/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2021-07-22 16:20:42
 * @LastEditTime: 2022-12-07 15:09:54
 * @Description  : 任务管理-任务大厅
 */

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:task_package/src/assets.gen.dart';
import 'package:task_package/src/components/dropdown_filter.dart';
import 'package:task_package/src/components/task_item.dart';
import 'package:task_package/src/view_models/hall_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'index.g.dart';
part 'components/search.dart';

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

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

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

class HallPageView extends StatelessWidget {
  const HallPageView({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: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          // 触摸收起键盘
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: _BuildBody(),
      ),
    );
  }
}

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

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

class __BuildBodyState extends State<_BuildBody>
    with SingleTickerProviderStateMixin {
  HallPageStore get store => Provider.of(context, listen: false);

  @override
  void initState() {
    super.initState();
    store.onGetTaskListItem();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        /// 搜索框
        _BuildSearchInput(
          title: store.taskTitle,
          onInput: (v) => store.onSearchTaskTitles(v),
          onCancel: () => store.onSearchTaskTitles(''),
        ),
        Stack(
          fit: StackFit.expand,
          children: [
            Observer(builder: (_) {
              return WisScrollView(
                controller: store.viewController0,
                onInit: () => store.onInitList(),
                onLoad: () => store.onGetList(),
                onRefresh: () => store.onInitList(),
                key: store.hallScrViewKey,
                bottomSpace: 59.pt,
                slivers: [
                  SliverToBoxAdapter(
                    child: Wisdom(
                      height: 54.pt,
                    ),
                  ),
                  WisSliverList.childBuilder(
                    padding:
                        EdgeInsets.symmetric(horizontal: 15.pt, vertical: 7.pt),
                    childCount: store.taskList.length,
                    interval: 10.pt,
                    builder: (_, i) {
                      return Observer(builder: (_) {
                        return TaskItem(
                          onClick: (item) => store.toTaskDetail(item),
                          item: store.taskList[i],
                          isMine: true,
                        );
                      });
                    },
                  ),
                ],
              );
            }),
            Observer(builder: (_) {
              return DropdownFilter(
                // key: store.dropdownKey1,
                store: store,
                onChooseListItem: (data, index) => store.onChooseListItem(data),
                checkList: store.checkListItem,
                contents: store.taskItemList,
                filters: [
                  FilterButton(
                    isDrop: true,
                    title: '任务类型',
                    type: 'Column',
                    hasIcon: true,
                    icon: Image(
                      image: AssetList.$hxl_png_image,
                      height: 4.pt,
                    ),
                    dropdownIcon: Image(
                      image: AssetList.$lss_png_image,
                      height: 4.pt,
                    ),
                  ),
                ],
              );
            }),
          ],
        ).asExpanded(),
      ],
    );
  }
}
