/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-03-04 16:06:21
 * @LastEditTime : 2023-07-26 10:39:42
 * @FilePath     : /wisdom-huiguanjia-app/oa_package/lib/src/pages/index/view.dart
 * @Description  : Do not edit
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:oa_package/src/assets.gen.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:oa_package/src/view_models/index_store.dart';
part 'components/grid.dart';
part 'components/stat.dart';

class IndexPageView extends StatelessWidget {
  const IndexPageView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<IndexStore>(context, listen: true);
    final appGlobalStore = GetIt.I.get<AppGlobalStore>();
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        title: WisText(
          '审批',
          size: 19.pt,
          weight: FontWeight.bold,
          color: colorScheme.mainTitle,
        ),
      ),
      body: WisScrollView(
        onInit: () => store.getData(),
        onRefresh: () => store.getData(),
        slivers: [
          // 顶部任务状态
          _StatComponent(),
          if (appGlobalStore.isPageSet == true) ...[
            SliverToBoxAdapter(
              child: Observer(builder: (_) {
                return Column(children: [
                  // 个性化审批菜单
                  if (store.pageMenuList != [] &&
                      store.pageMenuList.length > 0) ...[
                    /// 九宫格样式
                    if (store.pageDetail.displayMode == 'gridLayout') ...[
                      for (var item in store.pageMenuList)
                        WisDynamicMenuGrid(
                          title: item?.name ?? '--',
                          list: item.menus,
                          type: item.type,
                          toRoutes: (item, type) =>
                              store.toSettingProcess(item),
                        ),
                    ] else ...[
                      /// 列表样式
                      for (var item in store.pageMenuList)
                        WisDynamicMenuList(
                          title: item?.name ?? '--',
                          list: item.menus,
                          type: item.type,
                          toRoutes: (item, type) =>
                              store.toSettingProcess(item),
                        ),
                    ],
                  ] else ...[
                    WEmptyWidget(
                      text: WisText('空空如也~'),
                    ),
                  ],
                ]);
              }),
            ),
          ] else ...[
            // 审批菜单
            _GridComponent(list: store.oaMenuList),
          ],
          SizedBox(height: 30.pt).asSliver(),
        ],
      ),
    );
  }
}
