import 'package:fis_common/index.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/values/font_sizes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flyinsono/architecture/define.dart';

///手机端图标按钮
class MobileModuleCard extends FStatelessWidget implements FPage {
  MobileModuleCard({
    required this.label,
    required this.iconData,
    required this.onPressed,
    this.pageName = 'MobileModuleCard',
    this.moduleWidth = 76,
    this.moduleheight = 70,
    this.hasVerticalSpace = true,
    this.iconSize = 30,
  });
  @override
  final String pageName;

  ///图标数据
  final IconData iconData;

  ///文字显示
  final String label;

  ///点击回调
  final VoidCallback onPressed;

  ///宽度
  final double moduleWidth;

  ///高度
  final double moduleheight;

  ///图标和文字是否具有垂直距离
  final bool hasVerticalSpace;

  ///图标大小
  final double iconSize;

  @override
  FWidget build(BuildContext context) {
    return FContainer(
      width: moduleWidth,
      height: moduleheight,
      child: FOutlinedButton(
        name: label,
        businessParent: this,
        onPressed: onPressed,
        child: FColumn(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            FIcon(iconData, size: iconSize),
            hasVerticalSpace ? FSizedBox(height: 6) : FContainer(),
            FExpanded(
              child: FText(
                label,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: FFontSizes.BODY,
                  color: Colors.black,
                ),
              ),
            ),
          ],
        ),
        style: ButtonStyle(
          padding: MaterialStateProperty.all(EdgeInsets.zero),
          side: MaterialStateProperty.all(BorderSide.none),
        ),
      ),
    );
  }
}

class MobileCustomIconModuleCard extends FStatelessWidget implements FPage {
  MobileCustomIconModuleCard({
    required this.label,
    required this.onPressed,
    required this.iconUrl,
    this.pageName = 'MobileModuleCard',
    this.moduleWidth = 76,
    this.moduleheight = 70,
    this.iconSize = 30,
  });
  @override
  final String pageName;

  ///文字显示
  final String label;

  ///从网络加载Icon的地址
  final String iconUrl;

  ///点击回调
  final VoidCallback onPressed;

  ///宽度
  final double moduleWidth;

  ///高度
  final double moduleheight;

  ///图标大小
  final double iconSize;

  @override
  FWidget build(BuildContext context) {
    FWidget thirdpartyIcon = FContainer();
    if (iconUrl.isNotNullOrEmpty) {
      if (iconUrl.endsWith('.jpg')) {
        thirdpartyIcon = QuickFWidget(
          ColorFiltered(
            colorFilter: ColorFilter.mode(Colors.blue, BlendMode.srcIn),
            child: Image.network(
              iconUrl,
              height: iconSize,
              width: iconSize,
            ),
          ),
        );
      } else if (iconUrl.endsWith('.svg')) {
        thirdpartyIcon = QuickFWidget(
          SvgPicture.network(
            iconUrl,
            color: Colors.blue, // 设置颜色
            width: iconSize,
            height: iconSize,
          ),
        );
      } else {
        thirdpartyIcon = FImage.network(
          iconUrl,
          height: iconSize,
        );
      }
    }
    return FContainer(
      width: moduleWidth,
      height: moduleheight,
      child: FOutlinedButton(
        name: label,
        businessParent: this,
        onPressed: onPressed,
        child: FColumn(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            thirdpartyIcon,
            FSizedBox(height: 6),
            FExpanded(
              child: FText(
                label,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: FFontSizes.BODY,
                  color: Colors.black,
                ),
              ),
            ),
          ],
        ),
        style: ButtonStyle(
          padding: MaterialStateProperty.all(EdgeInsets.zero),
          side: MaterialStateProperty.all(BorderSide.none),
        ),
      ),
    );
  }
}
