/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-02-09 15:21:58
 * @LastEditTime : 2023-03-29 18:03:07
 * @Description  : Do not edit
 */
import 'package:app_package/app_package.dart';
import 'package:app_package/src/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class WisDynamicMenuList extends StatelessWidget {
  const WisDynamicMenuList({
    Key? key,
    this.title,
    this.list,
    this.type,
    this.toRoutes,
  }) : super(key: key);
  final String? title;
  final List? list;
  final String? type;
  final Function(dynamic item, dynamic type)? toRoutes;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return WisCard(
      margin: EdgeInsets.only(
        bottom: 10.pt,
        left: 15.pt,
        right: 15.pt,
      ),
      child: Wisdom.column(color: Colors.white, children: <Widget>[
        Wisdom.row(
            border: Border(
              bottom: BorderSide(
                color: Color(0xffE6E6E6),
              ),
            ),
            padding: EdgeInsets.only(top: 15.pt, left: 15.pt, bottom: 15.pt),
            children: [
              WisText(
                '$title',
                color: colorScheme.mainTitle,
                weight: FontWeight.w600,
                size: 15.pt,
              ),
            ]),
        if (list != null && list!.length > 0) ...[
          for (int i = 0; i < list!.length; i++)
            _BuildMenuItem(
              item: list![i],
              type: type,
              toRoutes: toRoutes,
              isLast: i == list!.length - 1 ? true : false,
            ),
        ]
      ]),
    );
  }
}

class _BuildMenuItem extends StatelessWidget {
  const _BuildMenuItem({
    Key? key,
    this.item,
    this.type,
    this.toRoutes,
    this.isLast,
  }) : super(key: key);
  final item;
  final String? type;
  final Function(dynamic item, dynamic type)? toRoutes;

  final bool? isLast;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.row(
      onTap: () => toRoutes!(item, type),
      padding: EdgeInsets.only(
        left: 15.pt,
      ),
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Row(
          children: [
            WImage.network(
              AppParseUtil.image(item.icon),
              height: 39.pt,
              width: 39.pt,
            ),
            Wisdom(width: 12.5.pt),
          ],
        ),
        Wisdom.row(
          padding: EdgeInsets.only(
            top: 22.pt,
            bottom: 22.pt,
          ),
          border: Border(
            bottom: BorderSide(
              color: isLast == true ? Colors.transparent : colorScheme.divider,
            ),
          ),
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            WisText(
              item?.name ?? '--',
              color: colorScheme.mainTitle,
              size: 16.pt,
              overflow: TextOverflow.ellipsis,
            ).asFlexible(flex: 1),
            Row(
              children: [
                Image(
                  image: AssetList.$tz_png_image,
                  width: 6.pt,
                  height: 12.pt,
                ),
                SizedBox(width: 15.pt),
              ],
            )
          ],
        ).asFlexible(flex: 1),
      ],
    );
  }
}
