import 'package:cims_apps/application/component/button/button_view.dart';
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/route/route.dart';
import 'package:cims_apps/core/utils/size_config.dart';
import 'package:cims_apps/features/auth/registration/view/submission_data/initial_take_photo.dart';
import 'package:cims_apps/features/auth/registration/view/submission_data/submit_email.dart';
import 'package:cims_apps/features/auth/registration/view/submission_data/submit_personal_data.dart';
import 'package:cims_apps/features/auth/registration/viewmodel/submission_data_viewmodel.dart';
import 'package:cims_apps/features/bottom_navigation_view.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SubmissionParent extends StatefulWidget {
  static const routeName = '/SubmissionParent';
  const SubmissionParent({Key? key}) : super(key: key);

  @override
  State<SubmissionParent> createState() => _SubmissionParentState();
}

class _SubmissionParentState extends State<SubmissionParent> {
  Widget _stepItem({bool isCurrentStep = false, bool isDone = false}) {
    return Container(
      margin: const EdgeInsets.only(right: 4.0, left: 4.0),
      height: 6,
      width: SizeConfig.width * .08,
      decoration: BoxDecoration(
        color: isCurrentStep || isDone
            ? ColorPalette.primary
            : ColorPalette.greyBorderNeutrals,
        borderRadius: BorderRadius.circular(50),
      ),
    );
  }

  _content(int index) {
    switch (index) {
      case 1:
        return const SubmitPersonalData();
      case 2:
        return const SubmitEmail();
      case 3:
        return const InitialTakePhoto();
      case 4:
        return Container(
          child: Text("Step 4"),
        );
      case 5:
        return Container(
          child: Text("Step 5"),
        );
      case 6:
        return Container(
          child: Text("Step 6"),
        );
      case 7:
        return Container(
          child: Text("Step 7"),
        );
      case 8:
        return Container(
          child: Text("Step 8"),
        );
      case 9:
        return Container(
          child: Text("Step 9"),
        );
    }
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (context) => SubmissionDataViewModel(),
        builder: (context, child) {
          return WillPopScope(
            onWillPop: () async {
              await routePush(context,
                  page: const BottomNavigationView(),
                  routeType: RouteType.pushReplace);
              return false;
            },
            child: Scaffold(
              appBar: AppBar(
                title: const Text('Registration'),
              ),
              body: Stack(
                children: [
                  Consumer<SubmissionDataViewModel>(
                      builder: (context, provider, child) {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Padding(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 16.0, vertical: 16.0),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: List.generate(
                              provider.stepAmount,
                              (index) => _stepItem(
                                isCurrentStep:
                                    provider.currentStep == index + 1,
                              ),
                            ),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            padding:
                                const EdgeInsets.symmetric(horizontal: 16.0),
                            child: _content(provider.currentStep),
                          ),
                        ),
                        provider.currentStep == 3
                            ? const SizedBox()
                            : Align(
                                alignment: Alignment.bottomCenter,
                                child: ButtonView(
                                  name: 'Next',
                                  marginVertical: 16.0,
                                  onPressed: () {
                                    provider.nextSubmission(context);
                                  },
                                ),
                              )
                      ],
                    );
                  }),
                ],
              ),
            ),
          );
        });
  }
}
