// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import 'package:general_package/constants/constants.dart';
import 'package:general_package/responsive/responsive.dart';
import 'package:general_package/themes/themes.dart';

class DynamicFormTab extends StatefulWidget {
  DynamicFormTab(
      {super.key,
      required this.title,
      this.padding,
      this.inputs,
      this.tabsMenu});
  String title;
  EdgeInsetsGeometry? padding;
  List<List<Widget>>? inputs;
  List<String>? tabsMenu;
  @override
  State<DynamicFormTab> createState() => _DynamicFormTabState();
}

class _DynamicFormTabState extends State<DynamicFormTab>
    with SingleTickerProviderStateMixin {
  late TabController controller;

  @override
  void initState() {
    super.initState();
    controller = TabController(length: widget.tabsMenu!.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: widget.padding,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text(widget.title, style: Theme.of(context).textTheme.headline3),
          GeneralConstants.instance.sizedBoxHeight10,
          Container(
            padding: GeneralConstants.instance.paddingSymmetric10,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(90),
              color: AppTheme.secondaryColor.withOpacity(0.4),
            ),
            child: TabBar(
              unselectedLabelColor: AppTheme.grayColor,
              labelColor: AppTheme.whiteColor,
              indicatorSize: TabBarIndicatorSize.tab,
              indicator: BoxDecoration(
                gradient: LinearGradient(colors: [
                  AppTheme.primaryColor,
                  AppTheme.primaryDarkColor,
                ]),
                borderRadius: BorderRadius.circular(50),
              ),
              tabs: widget.tabsMenu!
                  .map(
                    (tabMenu) => Container(
                      constraints: const BoxConstraints(
                        minHeight: 30,
                      ),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(90),
                      ),
                      child: Align(
                        alignment: Alignment.center,
                        child: Text(tabMenu),
                      ),
                    ),
                  )
                  .toList(),
              controller: controller,
            ),
          ),
          // SingleChildScrollView(
          //   child: SizedBox(
          //     height: ScreenTypeData.fullHeight(context) * .20,
          //     child: TabBarView(
          //         controller: controller,
          //         // children: widget.inputs!
          //         //     .map((input) => Column(
          //         //           children: input.toList(),
          //         //         ))
          //         //     .toList()
          //             ),
          //   ),
          // )
          SizedBox(
            height: ScreenTypeData.fullHeight(context)*.20,
            child: TabBarView(
                controller: controller,
                children: widget.inputs!.map((input) {
                  return SingleChildScrollView(
                    child: Column(
                      children: input.toList(),
                    ),
                  );
                }).toList()),
          ),
        ],
      ),
    );
  }
}
