import 'package:cims_apps/application/component/button/button_view.dart';
import 'package:cims_apps/application/component/select_form/select_form_view.dart';
import 'package:cims_apps/application/component/text_caption/text_caption.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/submission_parent.dart';
import 'package:cims_apps/features/auth/registration/viewmodel/submission_data_viewmodel.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SubmitPersonalData extends StatelessWidget {
  const SubmitPersonalData({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (context) => SubmissionDataViewModel(),
        builder: (context, child) {
          return Consumer<SubmissionDataViewModel>(
              builder: (context, provider, child) {
            return SizedBox(
              height: SizeConfig.height * .78,
              child: Form(
                key: provider.formKeyPersonalData,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    const TextCaption(title: 'Your personal details'),
                    SelectFormView(
                      name: 'Occupation',
                      hintText: 'Select occupation ',
                      ctrl: provider.ctrlOccupation,
                      listItem: provider.listOccupation,
                      onSelect: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Field must be filled';
                        }
                        return null;
                      },
                    ),
                    SelectFormView(
                      name: 'Income Level (IDR)',
                      hintText: 'Select Income ',
                      ctrl: provider.ctrlIncome,
                      listItem: provider.listIncome,
                      onSelect: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Field must be filled';
                        }
                        return null;
                      },
                    ),
                    SelectFormView(
                      name: 'Marital Status',
                      hintText: 'Select Marital Status ',
                      ctrl: provider.ctrlMarital,
                      listItem: provider.listMarital,
                      onSelect: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Field must be filled';
                        }
                        return null;
                      },
                    ),
                    SelectFormView(
                      name: 'Source of Fund',
                      hintText: 'Select Source of Fund ',
                      ctrl: provider.ctrlSourceFund,
                      listItem: provider.listSourceFund,
                      onSelect: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Field must be filled';
                        }
                        return null;
                      },
                    ),
                    // SizedBox(height: SizeConfig.height * .18),
                    ButtonView(
                      marginVertical: 0,
                      name: 'Next',
                      onPressed: () async {
                        if (provider.formKeyPersonalData.currentState!
                            .validate()) {
                          await provider.next(context).then((value) {
                            if (value) {
                              routePush(context,
                                  page: const SubmissionParent());
                            }
                          });
                        }
                      },
                    )
                  ],
                ),
              ),
            );
          });
        });
  }
}
