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

class DesktopModuleCard extends FStatelessWidget {
  DesktopModuleCard({
    required this.label,
    required this.iconData,
    required this.onPressed,
    required this.businessParent,
    this.iconSize,
    this.width,
    this.subtitle,
    this.iconUrl,
  });

  ///父级节点
  final FPage businessParent;
  final String? subtitle;
  final double? width;
  final IconData iconData;
  final double? iconSize;
  final String label;
  final String? iconUrl;
  final VoidCallback onPressed;

  @override
  FWidget build(BuildContext context) {
    final fnIsActive = (Set<MaterialState> states) {
      return states.contains(MaterialState.hovered) ||
          states.contains(MaterialState.pressed);
    };
    var moduleHeight = kIsMobile ? 90.0 : 104.0;
    var moduleWidth = kIsMobile ? 160.0 : width ?? 180.0;
    FWidget thirdpartyIcon = FContainer();
    if (iconUrl.isNotNullOrEmpty) {
      if (iconUrl!.endsWith('.jpg')) {
        thirdpartyIcon = QuickFWidget(
          ColorFiltered(
            colorFilter: ColorFilter.mode(
                Color.fromRGBO(60, 60, 60, 1), BlendMode.srcIn),
            child: Image.network(
              iconUrl!,
              height: 42,
              width: 42,
            ),
          ),
        );
      } else if (iconUrl!.endsWith('.svg')) {
        thirdpartyIcon = QuickFWidget(
          SvgPicture.network(
            iconUrl!,
            color: Color.fromRGBO(60, 60, 60, 1), // 设置颜色
            width: 42,
            height: 42,
          ),
        );
      } else {
        thirdpartyIcon = FImage.network(
          iconUrl!,
          height: 42,
        );
      }
    }
    return FOutlinedButton(
      name: label,
      businessParent: businessParent,
      onPressed: onPressed,
      child: FContainer(
        height: moduleHeight,
        width: moduleWidth,
        child: FRow(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            iconUrl.isNullOrEmpty
                ? FIcon(iconData, size: iconSize ?? 42)
                : thirdpartyIcon,
            FSizedBox(width: kIsMobile ? 10 : 16),
            FColumn(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                FText(label, style: TextStyle(fontSize: kIsMobile ? 18 : 22)),
              ],
            ),
          ],
        ),
      ),
      style: ButtonStyle(
        backgroundColor: MaterialStateProperty.all(
          const Color.fromRGBO(242, 242, 242, 1),
        ),
        // fixedSize: MaterialStateProperty.all(
        //     kIsMobile ? const Size(160, 90) : Size(width ?? 180, 104)),
        shape: MaterialStateProperty.all(
          RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
        ),
        foregroundColor: MaterialStateProperty.resolveWith(
          (states) => fnIsActive(states)
              ? Colors.black87
              : const Color.fromRGBO(60, 60, 60, 1),
        ),
        side: MaterialStateProperty.resolveWith(
          (states) => fnIsActive(states)
              ? BorderSide(color: Theme.of(context).primaryColor, width: 2)
              : BorderSide.none,
        ),
        elevation: MaterialStateProperty.resolveWith(
          (states) => fnIsActive(states) ? 6 : null,
        ),
      ),
    );
  }
}
