/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2021-04-27 09:43:14
 * @LastEditTime: 2023-08-15 10:17:30
 * @FilePath     : /wisdom-huiguanjia-app/task_package/lib/src/pages/statistic/index.dart
 * @Description  : 任务统计-入口页
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../../src/assets.gen.dart';
import '../../../src/pages/statistic/components/all_stat.dart';
import '../../../src/pages/statistic/components/list_stat.dart';
import '../../../src/view_models/statistic_store.dart';
part 'components/mine.dart';
part 'components/people.dart';
part 'components/department.dart';
part 'index.g.dart';

///路由传递的参数
class StatisticPageArguments {
  final String? id;
  StatisticPageArguments({this.id});

  ///
  ///
  ///
  ///
  ///
  ///
  ///
//***以下为模板代码谨慎修改***
  factory StatisticPageArguments.fromJson(Map<String, dynamic> json) {
    return _$StatisticPageArgumentsFromJson(json);
  }
  factory StatisticPageArguments.fromRouteArguments(BuildContext context) {
    return _$StatisticPageArgumentsFromJson(
        (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>);
  }
  Map<String, dynamic> toJson() => _$StatisticPageArgumentsToJson(this);
}

///
///
///
///
///
//***以下为模板代码谨慎修改***
class StatisticPage extends StatelessWidget {
  const StatisticPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => StatisticStore(context)),
      ],
      child: _PageView(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<StatisticStore>(context, listen: false);
    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),

        /// 顶部按钮
        actions: <Widget>[
          Observer(builder: (_) {
            return Wisdom.row(
              children: <Widget>[
                if (store.tabIndex == 0 || store.isStatShow) ...[
                  Wisdom(
                    onTap: () => store.onSetFilterShow(),
                    margin: EdgeInsets.only(right: 25.pt),
                    child: Image(
                      image: AssetList.$sjsx_png_image,
                      height: 17.pt,
                      color: colorScheme.mainTitle,
                    ),
                  ),
                ],
              ],
            );
          })
        ],
      ),
      body: _BuildBody(),
      bottomSheet: _BuildBottomBar(),
    );
  }
}

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

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

class __BuildBodyState extends State<_BuildBody>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<StatisticStore>(context, listen: false);

    return WisTabPage(
      divider: false,
      onChange: (index) => {store.onSetTabIndex(index)},
      tabs: <Widget>[
        Text('我的任务'),
        Text('部门统计'),
        Text('人员统计'),
      ],
      views: <Widget>[
        _BuildTabViewMine(),
        _BuildTabViewDepart(),
        _BuildTabViewPeople(),
      ],
      indicator: RoundUnderlineTabIndicator(
        width: 10.pt,
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<StatisticStore>(context, listen: false);
    final colorScheme = WTheme.of(context).colorScheme;

    return Wisdom(
      child: Observer(builder: (_) {
        if (store.tabIndex == 1 || store.tabIndex == 2)
          return Wisdom.row(
            color: Colors.white,
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 18.pt),
            height: 80.pt,
            children: [
              Observer(builder: (_) {
                return Wisdom(
                  height: 44.pt,
                  color: colorScheme.primary,
                  borderRadius: BorderRadius.circular(25.pt),
                  onTap: () => store.toTaskStatistic(),
                  child: Center(
                    child: WisText(
                      store.tabIndex == 1
                          ? store.isStatShow
                              ? "返回部门选择"
                              : "查看部门统计"
                          : store.tabIndex == 2
                              ? store.isStatShow
                                  ? "返回人员选择"
                                  : "查看人员统计"
                              : '',
                      size: 16.pt,
                      color: Colors.white,
                      weight: FontWeight.w300,
                    ),
                  ),
                ).asExpanded();
              })
            ],
          );
        else
          return Container(
            height: 0,
            width: 0,
          );
      }),
    );
  }
}
