import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/clock/clock.dart';
import 'package:flyinsono/lab/components/memory_monitor.dart';
import 'package:flyinsono/lab/manager/page_manager.dart';
import 'package:flyinsono/lab/router/lab_route_names.dart';
import 'package:flyinsono/pages/schedule/schedule_notification/global_notification_layer.dart';
import 'package:get/get.dart';
import 'index.dart';
import 'widgets/widgets.dart';

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

  // 主视图
  Widget _buildView() {
    return Column(
      children: [
        MainPageHeader(),
        Expanded(
          child: GetBuilder<LabMainController>(
            id: LabMainController.tabViewId,
            builder: (controller) => IndexedStack(
              index: PageManager.ins.activeTabIndex,
              children: PageManager.ins.tabViews.entries
                  .map((entry) => entry.value)
                  .toList(),
            ),
          ),
        ),
        Container(
          height: 40,
          padding: EdgeInsets.symmetric(horizontal: 10).copyWith(left: 0),
          color: LabColors.mainPageHeaderColor,
          child: Row(
            children: [
              Container(
                height: 40,
                width: 150,
                // color: Colors.amber,
                // alignment: Alignment.centerLeft,
                child: TaskListButton(
                  onClick: () {
                    PageManager.ins.openNewTab(
                      LabRouteNames.TaskList,
                      '任务列表',
                      multiple: false,
                    );
                  },
                ),
              ),
              Container(
                width: 150,
              ),
              Obx(
                () => Container(
                  height: 40,
                  width: 300,
                  alignment: Alignment.centerLeft,
                  child: Text(
                    controller.state.bottomCustomText,
                    style: TextStyle(
                      color: LabColors.text300,
                    ),
                  ),
                ),
              ),
              // Expanded(
              //   child: RepaintBoundary(
              //     child: const MemoryMonitor(),
              //   ),
              // ),
              // const SizedBox(width: 10),
              // Container(
              //   width: 1,
              //   height: 20,
              //   color: LabColors.base500,
              // ),
              // const SizedBox(width: 10),
              Expanded(child: const SizedBox()),
              const CustomClock(
                textStyle:
                    TextStyle(color: LabColors.text300, wordSpacing: 1.2),
              ),
              const SizedBox(width: 10),
            ],
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabMainController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: LabColors.base300,
          body: SafeArea(
            child: FGlobalNotificationLayer(
              child: QuickFWidget(_buildView()),
            ),
          ),
        );
      },
    );
  }
}
