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/widget_responsive.dart';
import 'package:tour_travel_agr/resource/colors.dart';
import 'package:tour_travel_agr/resource/font.dart';
import 'package:tour_travel_agr/resource/size.dart';
import 'package:tour_travel_agr/resource/style.dart';

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

  @override
  State<ChangePasswordView> createState() => _ChangePasswordViewState();
}

class _ChangePasswordViewState extends State<ChangePasswordView> {
  final TextEditingController nowPasswordController = TextEditingController();

  final TextEditingController newPasswordController = TextEditingController();

  final TextEditingController confirmNewPasswordController =
      TextEditingController();

  bool buttonActive = false;
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @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: "Change Password",
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: AppMargin.m20,
                  ),
                  PasswordInput(
                    passwordController: nowPasswordController,
                    labelText: "Password Saat Ini",
                    borderSideActive: true,
                    labelColor: ColorManager.primary,
                    onChanged: (val) {
                      if (nowPasswordController.text.isNotEmpty &&
                          newPasswordController.text.isNotEmpty &&
                          confirmNewPasswordController.text.isNotEmpty) {
                        setState(() {
                          buttonActive = true;
                        });
                      } else {
                        buttonActive = false;
                      }
                    },
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      top: AppMargin.m20,
                    ),
                    child: Text(
                      "Ubah password anda",
                      style: getRegularStyle(
                        color: Colors.black,
                        fontSize: 15,
                        fontFamily: FontConstants.mulish,
                      ),
                    ),
                  ),
                  SizedBox(
                    height: AppMargin.m12,
                  ),
                  PasswordInput(
                    passwordController: newPasswordController,
                    labelText: "Password Baru",
                    borderSideActive: true,
                    labelColor: ColorManager.primary,
                    onChanged: (val) {
                      if (nowPasswordController.text.isNotEmpty &&
                          newPasswordController.text.isNotEmpty &&
                          confirmNewPasswordController.text.isNotEmpty) {
                        setState(() {
                          buttonActive = true;
                        });
                      } else {
                        buttonActive = false;
                      }
                    },
                  ),
                  PasswordInput(
                    marginTop: AppMargin.m12,
                    passwordController: confirmNewPasswordController,
                    labelText: "Konfirmasi Password Baru",
                    borderSideActive: true,
                    labelColor: ColorManager.primary,
                    onChanged: (val) {
                      if (nowPasswordController.text.isNotEmpty &&
                          newPasswordController.text.isNotEmpty &&
                          confirmNewPasswordController.text.isNotEmpty) {
                        setState(() {
                          buttonActive = true;
                        });
                      } else {
                        buttonActive = false;
                      }
                    },
                  ),
                  Container(
                    margin: const EdgeInsets.only(
                      top: 50,
                    ),
                    child: CustomButton(
                      text: "Update",
                      colorButton: (buttonActive) ? null : Colors.grey,
                      onTap: () {
                        if (buttonActive) {
                          // TODO: do something here
                        }
                      },
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
