import 'package:flutter/material.dart';
import 'package:flyinsono/global.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/pages/lab_task/widgets/task_detail_list.dart';
import 'package:flyinsono/lab/pages/lab_task/widgets/task_header_panel.dart';
import 'package:get/get.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class LabTaskPage extends GetView<LabTaskController> {
  const LabTaskPage({Key? key}) : super(key: key);

  get tabHashCode => this.hashCode.toString();

  @override
  String? get tag => tabHashCode;

  // 主视图
  Widget _buildView() {
    return Row(
      children: [
        _buildLeftPart(),
        Expanded(
          child: _buildMainContent(),
        ),
        SizedBox(width: 10),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabTaskController>(
      init: LabTaskController(tabHashCode: this.hashCode),
      tag: tabHashCode, // 如果一个页面要想实现多开，必须加 tag
      id: LabTaskController.taskPageId,
      builder: (_) {
        return Scaffold(
          backgroundColor: LabColors.base300,
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }

  Widget _buildLeftPart() {
    return Container(
      width: 300,
      padding: EdgeInsets.all(10),
      child: Column(
        children: [
          Expanded(
            child: TaskList(
              tabHashCode: tabHashCode,
            ),
          )
        ],
      ),
    );
  }

  Widget _buildMainContent() {
    if (controller.noProcessingTask && controller.selectedClassifyIndex == 0) {
      return _buildNoTask();
    }
    return Container(
      height: double.infinity,
      padding: EdgeInsets.symmetric(vertical: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          TaskHeaderPanel(
            tabHashCode: tabHashCode,
          ),
          SizedBox(height: 10),
          Expanded(
            child: TaskDetailList(
              tabHashCode: tabHashCode,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildNoTask() {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            height: 200,
            child: ColorFiltered(
              colorFilter: ColorFilter.mode(LabColors.base400, BlendMode.srcIn),
              child: Image.asset(
                Global.isVStationSlave
                    ? "assets/images/logo_icon_0.png"
                    : "assets/images/logo_icon.png",
                filterQuality: FilterQuality.medium,
                isAntiAlias: true,
                fit: BoxFit.contain,
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            "暂无执行中的任务",
            style: TextStyle(
              color: LabColors.text600,
              fontSize: 16,
            ),
          ),
          SizedBox(
            height: 30,
          ),
        ],
      ),
    );
  }
}
