part of '../index.dart';

class TabCard extends StatefulWidget {
  const TabCard({
    Key? key,
    this.selectIndex,
    this.onSelectCard,
    required this.child,
    this.isIconed = false,
    this.icons,
    required this.tabs,
    this.unSelectedTabs,
    this.height,
  }) : super(key: key);
  final int? selectIndex;
  final List<Widget> child;
  final Function(int index)? onSelectCard;
  final bool? isIconed;
  final List? icons;
  final List tabs;
  final List? unSelectedTabs;
  final double? height;

  @override
  State<TabCard> createState() => _TabCardState();
}

class _TabCardState extends State<TabCard> {
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Container(
          height: widget.height ?? 226.pt,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [const Color(0xffE4EEFF), Color(0xffffffff)],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            ),
            borderRadius: BorderRadius.circular(12.pt),
          ),
          margin: EdgeInsets.only(
            left: 15.pt,
            right: 15.pt,
            top: 15.pt,
          ),
          child: TabContainer(
            isStringTabs: !widget.isIconed!,
            onSelect: (index) => {widget.onSelectCard!(index)},
            color: Colors.white,
            borderColor: Color(0x4A0074FF),
            selectedTextStyle: TextStyle(
              color: colorScheme.mainTitle,
              fontSize: 18.pt,
              fontWeight: FontWeight.bold,
            ),
            enabled: true,
            unselectedTextStyle: TextStyle(
              color: colorScheme.minor,
              fontSize: 16.pt,
            ),
            radius: 12.pt,
            tabEdge: TabEdge.top,
            tabCurve: Curves.easeIn,
            transitionBuilder: (child, animation) {
              animation =
                  CurvedAnimation(curve: Curves.easeIn, parent: animation);
              return SlideTransition(
                position: Tween(
                  begin: const Offset(0.2, 0.0),
                  end: const Offset(0.0, 0.0),
                ).animate(animation),
                child: FadeTransition(
                  opacity: animation,
                  child: child,
                ),
              );
            },
            children: widget.child,
            tabs: widget.tabs,
            unSelectedTabs: widget.unSelectedTabs,
          ),
        )
      ],
    );
  }
}

class TabRowItem extends StatelessWidget {
  const TabRowItem({
    Key? key,
    required this.num,
    required this.text,
    this.onTap,
  }) : super(key: key);
  final Widget num;
  final Widget text;
  final Function()? onTap;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Wisdom.column(
          onTap: () => onTap!(),
          padding: EdgeInsets.all(15.pt),
          children: [
            text,
            num,
          ]),
    );
  }
}

class TabCardBody extends StatefulWidget {
  const TabCardBody({
    Key? key,
    required this.list,
    required this.toRoutes,
  }) : super(key: key);

  final List list;
  final Function() toRoutes;

  @override
  State<TabCardBody> createState() => _TabCardBodyState();
}

class _TabCardBodyState extends State<TabCardBody> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;

    return Wisdom.column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Wisdom.row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            for (int i = 0; i < widget.list.length; i++) widget.list[i],
          ],
        ),
        Wisdom.row(
          onTap: () => widget.toRoutes(),
          mainAxisAlignment: MainAxisAlignment.center,
          borderRadius: BorderRadius.circular(8.pt),
          children: [
            DottedBorder(
              color: colorScheme.divider,
              strokeWidth: 1,
              dashPattern: [5, 4],
              borderType: BorderType.RRect,
              radius: Radius.circular(8.pt),
              child: Wisdom.row(
                width: 315.pt,
                height: 53.pt,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Image(
                    image: AssetList.$plus_png_image,
                    height: 20.pt,
                    width: 20.pt,
                  ),
                ],
              ),
            ),
          ],
        )
      ],
    );
  }
}
