/*
 * @Author: ChenYaJin
 * @Date: 2023-08-04 17:05:07
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-08-08 15:30:37
 * @Description: 
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../../src/view_models/work_statistic_store.dart';
import '../../../src/assets.gen.dart';

import './components/tabbar_date.dart';
import './components/abnormal_rank.dart';
import './components/total_statistic.dart';
import './components/tabbar.dart';
import './components/calendar.dart';
import './components/date_abnormal_list.dart';

class WorkStatisticPage extends StatelessWidget {
  const WorkStatisticPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return _PageView();
  }
}

class _PageView extends StatelessWidget {
  const _PageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
        appBar: WAppBar(
          brightness: Brightness.light,
          iconTheme: IconThemeData(
            color: colorScheme.mainTitle,
            size: 19.pt,
          ),
          backgroundColor: Colors.white,
          title: WisText('作业管理',
              size: 19.pt,
              weight: FontWeight.w600,
              color: colorScheme.mainTitle),
        ),
        body: _BuildBody());
  }
}

class _BuildBody extends StatefulWidget {
  _BuildBody({Key? key}) : super(key: key);

  @override
  __BuildBodyState createState() => __BuildBodyState();
}

class __BuildBodyState extends State<_BuildBody>
    with SingleTickerProviderStateMixin {
  final WorkStatisticStore workStore = Get.isRegistered<WorkStatisticStore>()
      ? Get.find<WorkStatisticStore>()
      : Get.put(WorkStatisticStore());

  @override
  void dispose() {
    Get.delete<WorkStatisticStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final WorkStatisticStore store = Get.find<WorkStatisticStore>();
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    return Column(
      children: [
        Wisdom(
          child: Obx(
            () => Wisdom(
              height: 44.pt,
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
              child: Wisdom.row(
                  color: Colors.white,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    CustomScrollView(
                      scrollDirection: Axis.horizontal,
                      slivers: [
                        SliverToBoxAdapter(
                          child: Wisdom.row(
                            children: [
                              for (var item in store.taskItemList.reversed)
                                Wisdom(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  color: Color(0xFFF6F7FC),
                                  padding: EdgeInsets.symmetric(
                                    horizontal: 6.pt,
                                    vertical: 5.pt,
                                  ),
                                  margin: EdgeInsets.only(right: 12.pt),
                                  onTap: () => store.onSelectInventor(item.id!),
                                  child: Wisdom.rich(
                                    overflow: TextOverflow.ellipsis,
                                    children: [
                                      TextSpan(
                                        text: item.name,
                                        style: TextStyle(
                                          fontSize: 14.pt,
                                          fontWeight: FontWeight.w400,
                                          color:
                                              store.statusCode.value == item.id
                                                  ? colorScheme.primary
                                                  : Color(0xFF616178),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ],
                    ).asExpanded(),
                    Wisdom.row(
                      color: Colors.white,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      width: 65.pt,
                      onTap: () => store.toFilterPage(),
                      alignment: Alignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Text('筛选',
                            style: TextStyle(
                              fontSize: 13.pt,
                              color: store.isFilterStatus
                                  ? colorScheme.primary
                                  : colorScheme.mainTitle,
                            )),
                        Image(
                          image: store.isFilterStatus
                              ? AssetList.$filter_blue_png_image
                              : AssetList.$filter_png_image,
                          height: 20.pt,
                        ),
                      ],
                    ),
                  ]),
            ),
          ),
        ),
        TabbarDateComponent(),
        Wisdom(
          child: Obx(
            () => Wisdom.column(
              children: [
                if (store.isDateType.isTrue == true) ...[
                  TableCalendarComponent(),
                  DateAbnormalListComponent().asExpanded(),
                ] else ...[
                  BuildTotalStatistic(),
                  TabbarComponent(),
                  AbnormalRankComponent().asExpanded(),
                ]
              ],
            ),
          ),
        ).asExpanded(),
      ],
    );
  }
}
