/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2022-11-02 14:56:59
 * @LastEditTime: 2024-04-29 10:54:56
 * @Description  : Do not edit
 */
part of '../index.dart';

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<WorkStore>(context);
    final colorScheme = WTheme.of(context).colorScheme;

    /// 更多功能弹层
    _showMoreMenu() async {
      return await showModalBottomSheet(
        context: WNavUtil.instance!.context!,
        backgroundColor: Colors.transparent,
        builder: (context) {
          return Wisdom.column(
            height: 350.pt,
            borderRadius: BorderRadius.circular(20.pt),
            margin: EdgeInsets.only(
              left: 15.pt,
              right: 15.pt,
              bottom: 34.pt,
            ),
            color: Colors.white,
            padding: EdgeInsets.all(15.pt),
            mainAxisSize: MainAxisSize.min,
            children: [
              Wisdom.row(
                margin: EdgeInsets.only(bottom: 5.pt),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  WisText(
                    '更多功能',
                    size: 19.pt,
                    weight: FontWeight.bold,
                  ),
                  Wisdom(
                    height: 44.pt,
                    onTap: () => WNavUtil.instance!.pop(),
                    child: Icon(
                      Icons.close,
                      color: colorScheme.grey,
                      size: 20.pt,
                    ),
                  ),
                ],
              ),
              SingleChildScrollView(
                child: Wisdom.wrap(
                  alignment: Alignment.centerLeft,
                  runAlignment: WrapAlignment.start,
                  runSpacing: 20.pt,
                  children: [
                    for (int i = 4; i < store.menuOrderList.length; i++)
                      Container(
                        width:
                            ((MediaQuery.of(context).size.width - 65.pt) / 4),
                        child: Wisdom.column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          onTap: () => {
                            WNavUtil.instance!.pop(),
                            store.toRoutes(store.menuOrderList[i], 'menu'),
                          },
                          padding: EdgeInsets.all(4.pt),
                          children: <Widget>[
                            Wisdom(
                              margin: EdgeInsets.only(bottom: 1.pt),
                              child: WImage.network(
                                store.menuOrderList[i].route == 'scan' ||
                                        store.menuOrderList[i].id ==
                                            'message_index' || store.menuOrderList[i].id ==
                                            'green'
                                    ? store.menuOrderList[i].icon ?? ''
                                    : AppParseUtil.image(
                                        '${store.menuOrderList[i].icon}'),
                                width: 44.pt,
                                height: 44.pt,
                              ),
                            ),
                            WisText(
                              '${store.menuOrderList[i].name}',
                              size: 13.pt,
                              color: colorScheme.mainTitle,
                              height: 1.8,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ),
                    Container(
                      width: ((MediaQuery.of(context).size.width - 65.pt) / 4),
                      child: Wisdom.column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        onTap: () => {
                          WNavUtil.instance!.pop(),
                          store.toOrder(),
                        },
                        children: <Widget>[
                          DottedBorder(
                            color: colorScheme.divider,
                            strokeWidth: 1,
                            dashPattern: [5, 4],
                            borderType: BorderType.RRect,
                            radius: Radius.circular(8.pt),
                            child: Wisdom(
                              margin: EdgeInsets.all(10.pt),
                              child: WImage.network(
                                // 'https://wy.huiguanjia.cn/9ad134a361f8d778/file/images/705752909742874624',
                                'https://wy.huiguanjia.cn/9ad134a361f8d778/file/images/814110197182173184',
                                width: 24.pt,
                                height: 24.pt,
                              ),
                            ),
                          ),
                          WisText(
                            '功能管理',
                            size: 13.pt,
                            color: colorScheme.mainTitle,
                            height: 1.8,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ).asExpanded(),
            ],
          );
        },
      );
    }

    return Wisdom.row(
      mainAxisAlignment: store.menuLength == 5
          ? MainAxisAlignment.spaceBetween
          : MainAxisAlignment.start,
      padding: EdgeInsets.symmetric(horizontal: 15.pt),
      children: [
        if (store.menuOrderList.length > 0) ...[
          for (int i = 0;
              i <
                  (store.menuOrderList.length > 4
                      ? 4
                      : store.menuOrderList.length);
              i++)
            Wisdom.column(
              crossAxisAlignment: CrossAxisAlignment.center,
              width: (MediaQuery.of(context).size.width - 30.pt) / 5,
              onTap: () => {
                store.toRoutes(store.menuOrderList[i], 'menu'),
              },
              padding: EdgeInsets.all(4.pt),
              children: <Widget>[
                Wisdom.stack(margin: EdgeInsets.only(bottom: 1.pt), children: [
                  WImage.network(
                    store.menuOrderList[i].route == 'scan' ||
                            store.menuOrderList[i].id == 'message_index' ||  store.menuOrderList[i].id == 'green'
                        ? store.menuOrderList[i].icon ?? ''
                        : AppParseUtil.image('${store.menuOrderList[i].icon}'),
                    width: 44.pt,
                    height: 44.pt,
                  ),
                ]),
                WisText(
                  '${store.menuOrderList[i].name}',
                  size: 13.pt,
                  color: colorScheme.mainTitle,
                  height: 1.8,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ],
            ).asFlexible(flex: 1),
            Wisdom.column(
              crossAxisAlignment: CrossAxisAlignment.center,
              width: (MediaQuery.of(context).size.width - 30.pt) / 5,
              onTap: () => _showMoreMenu(),
              padding: EdgeInsets.all(4.pt),
              children: <Widget>[
                Wisdom.stack(margin: EdgeInsets.only(bottom: 1.pt), children: [
                  Image(
                    image: AssetList.$icon_tghx_png_image,
                    height: 44.pt,
                    width: 44.pt,
                  ),
                ]),
                WisText(
                  '更多功能',
                  size: 13.pt,
                  color: colorScheme.mainTitle,
                  height: 1.8,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ],
            ).asFlexible(flex: 1),
        ]
      ],
    );
  }
}
