/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2022-02-09 15:21:42
 * @LastEditTime: 2022-12-05 10:46:54
 * @Description  : Do not edit
 */

import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class DynamicMenuGrid extends StatelessWidget {
  const DynamicMenuGrid({
    Key? key,
    required this.title,
    required this.list,
    required this.type,
    required this.toRoutes,
    this.noticeMenusRoute,
  }) : super(key: key);
  final String title;
  final List list;
  final String type;
  final List? noticeMenusRoute;
  final Function(dynamic item, dynamic type) toRoutes;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return WisCard(
      isSliver: true,
      elevation: 0,
      margin: EdgeInsets.only(
        left: 15.pt,
        right: 15.pt,
        bottom: 10.pt,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Wisdom.row(
            border: Border(
              bottom: BorderSide(
                color: Color(0xffE6E6E6),
              ),
            ),
            padding: EdgeInsets.symmetric(vertical: 15.pt),
            children: <Widget>[
              // Wisdom(
              //   height: 20.pt,
              //   width: 3.pt,
              //   color: colorScheme.primary,
              //   margin: EdgeInsets.only(
              //     right: 12.pt,
              //   ),
              // ),
              SizedBox(width: 12.pt),
              WisText(
                '$title',
                color: colorScheme.mainTitle,
                weight: FontWeight.w600,
                size: 17.pt,
                overflow: TextOverflow.ellipsis,
              ).asFlexible(flex: 1),
            ],
          ),
          if (list.length == 0)
            Padding(
              padding: EdgeInsets.symmetric(vertical: 30.pt),
              child: Text(
                '暂无数据',
                textAlign: TextAlign.center,
                style: TextStyle(color: colorScheme.minor),
              ),
            )
          else
            Wrap(
              alignment: WrapAlignment.start,
              children: <Widget>[
                for (var item in list)
                  Container(
                    width: 85.pt,
                    margin: EdgeInsets.symmetric(vertical: 6.pt),
                    child: Wisdom.column(
                      onTap: () => toRoutes(item, type),
                      padding: EdgeInsets.all(4.pt),
                      children: <Widget>[
                        Wisdom(
                          width: 39.pt,
                          height: 39.pt,
                          alignment: Alignment.center,
                          child: Wisdom.stack(
                            children: <Widget>[
                              WImage.network(
                                AppParseUtil.image(item?.icon),
                                width: 39.pt,
                                height: 39.pt,
                              ),
                              if (noticeMenusRoute is List &&
                                  noticeMenusRoute!.length > 0 &&
                                  (noticeMenusRoute)!.contains(item?.route))
                                Positioned(
                                  top: -5.pt,
                                  right: -2.pt,
                                  child: Wisdom(
                                    width: 10.pt,
                                    height: 10.pt,
                                    padding: EdgeInsets.all(6),
                                    color: colorScheme.red,
                                    alignment: Alignment.topRight,
                                    borderRadius: BorderRadius.circular(15.pt),
                                  ),
                                ),
                            ],
                          ),
                        ),
                        WisText(
                          '${item?.name ?? '--'}',
                          size: 14.pt,
                          height: 1.8,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),
              ],
            ),
        ],
      ),
    );
  }
}
