// ignore_for_file: sized_box_for_whitespace

import 'package:flutter/material.dart';
import 'package:tour_travel_agr/helper/components_widget/custom_appbar.dart';
import 'package:tour_travel_agr/helper/components_widget/password_input.dart';
import 'package:tour_travel_agr/helper/components_widget/widget_button.dart';
import 'package:tour_travel_agr/helper/components_widget/widget_text_field.dart';
import 'package:tour_travel_agr/helper/widget_responsive.dart';
import 'package:tour_travel_agr/resource/colors.dart';
import 'package:tour_travel_agr/resource/routes.dart';
import 'package:tour_travel_agr/resource/size.dart';
import 'package:tour_travel_agr/resource/style.dart';

class RegisterView extends StatefulWidget {
  const RegisterView({super.key});

  @override
  State<RegisterView> createState() => _RegisterViewState();
}

class _RegisterViewState extends State<RegisterView> {
  final TextEditingController nameController = TextEditingController();

  final TextEditingController nikController = TextEditingController();

  final TextEditingController noHpController = TextEditingController();

  final TextEditingController passwordController = TextEditingController();

  final TextEditingController confirmPasswordController =
      TextEditingController();

  bool isChecked = false;
  bool buttonRregisterActive = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorManager.backgroundColor,
      body: ScreenResponsive(
        widget: bodyWidget(context),
        widthScreen: MediaQuery.of(context).size.width,
      ),
    );
  }

  Container bodyWidget(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        top: AppPadding.safeAreaTop(context),
        left: AppPadding.p20,
        right: AppPadding.p20,
        bottom: AppPadding.safeAreaBot(context),
      ),
      child: Column(
        children: [
          const CustomAppBar(
            text: "Register",
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  const SizedBox(
                    height: 12,
                  ),
                  InputTextField(
                    controller: nameController,
                    labelText: "Nama Lengkap",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "Nama anda",
                  ),
                  InputTextField(
                    controller: nikController,
                    labelText: "NIK",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "Nomor induk kependudukan",
                    marginTop: AppMargin.m12,
                  ),
                  InputTextField(
                    controller: noHpController,
                    labelText: "Nomor Handphone",
                    labelColor: ColorManager.primary,
                    borderSideActive: true,
                    hintText: "628...",
                    marginTop: AppMargin.m12,
                  ),
                  PasswordInput(
                    passwordController: passwordController,
                    labelColor: ColorManager.primary,
                    marginTop: 12,
                    borderSideActive: true,
                  ),
                  PasswordInput(
                    passwordController: confirmPasswordController,
                    labelColor: ColorManager.primary,
                    marginTop: 12,
                    borderSideActive: true,
                    labelText: "Konfirmasi password",
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      top: AppMargin.m25,
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          width: 20,
                          height: 20,
                          child: Checkbox(
                            checkColor: Colors.white,
                            activeColor: ColorManager.primary,
                            value: isChecked,
                            onChanged: (bool? value) {
                              setState(() {
                                buttonRregisterActive = value!;
                                isChecked = value;
                              });
                            },
                          ),
                        ),
                        Expanded(
                          child: Container(
                            margin: const EdgeInsets.only(
                              left: 4,
                            ),
                            child: Text(
                              "Dengan mendaftar layanan ini, anda menyetujui syarat & ketentuan yang berlaku",
                              style: getRegularStyle(
                                color: Colors.black,
                                fontSize: 12,
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      top: AppMargin.m25,
                      bottom: AppMargin.m20,
                    ),
                    child: CustomButton(
                      text: "Register",
                      colorButton: buttonRregisterActive
                          ? ColorManager.primary
                          : Colors.grey,
                      onTap: () {
                        if (buttonRregisterActive) {
                          // TODO:dosomething here
                          Navigator.pushNamed(
                              context, Routes.verificationRoute);
                        }
                      },
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
