import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/pages/lab_task/controller.dart';
import 'package:flyinsono/lab/style/lab_box_decoration.dart';
import 'package:get/get.dart';
import 'package:fis_jsonrpc/rpc.dart';

class TaskHeaderPanel extends GetView<LabTaskController> {
  const TaskHeaderPanel({Key? key, this.tabHashCode}) : super(key: key);
  final String? tabHashCode;
  @override
  String? get tag => tabHashCode;
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabTaskController>(
      id: LabTaskController.headerPanelId,
      tag: tabHashCode,
      builder: (context) {
        return Container(
          height: 160,
          padding: EdgeInsets.all(20),
          decoration: LabBoxDecoration.base,
          child: Row(
            children: [
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      controller.currentTaskInfo.title,
                      style: TextStyle(
                        fontSize: 20,
                        color: LabColors.text700,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "开始时间：${controller.currentTaskInfo.startTime}",
                      style: TextStyle(
                        fontSize: 14,
                        color: LabColors.text600,
                      ),
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    Text(
                      "已完成：${controller.currentTaskInfo.complateCount}/${controller.currentTaskInfo.totalCount}",
                      style: TextStyle(
                        fontSize: 14,
                        color: LabColors.text600,
                      ),
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    Text(
                      "已用时：${controller.currentTaskInfo.elapsedTime}",
                      style: TextStyle(
                        fontSize: 14,
                        color: LabColors.text600,
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: 10,
              ),
              if ((controller.currentSelectedTask?.status.index ?? 0) <
                  VTaskStatus.Completed.index)
                Container(
                  width: 160,
                  child: Column(
                    children: [
                      Container(
                        width: double.infinity,
                        height: 40,
                        child: ElevatedButton.icon(
                          icon: const Icon(Icons.cancel_outlined, size: 18),
                          style: ElevatedButton.styleFrom(
                            elevation: 0.0,
                            backgroundColor: LabColors.buttonColor,
                          ),
                          label: const Text("取消任务"),
                          onPressed: () {
                            controller.cancelCurrentTask();
                          },
                        ),
                      ),
                    ],
                  ),
                )
            ],
          ),
        );
      },
    );
  }
}
