import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:tangheem/classes/colors.dart';
import 'package:tangheem/classes/utils.dart';
import 'package:tangheem/widgets/common_textfield_widget.dart';

class ChangePasswordDialog extends StatefulWidget {
  final Function(String, String) onPassword;

  ChangePasswordDialog({Key key, this.onPassword}) : super(key: key);

  @override
  _ChangePasswordDialogState createState() {
    return _ChangePasswordDialogState();
  }
}

class _ChangePasswordDialogState extends State<ChangePasswordDialog> {
  final TextEditingController _currentPasswordController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();
  final TextEditingController _confirmPasswordController = TextEditingController();

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

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

  @override
  Widget build(BuildContext context) {
    return Dialog(
      insetPadding: EdgeInsets.symmetric(horizontal: 60.0, vertical: 24.0),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12),
      ),
      elevation: 0,
      backgroundColor: Colors.transparent,
      child: Directionality(
        textDirection: TextDirection.rtl,
        child: Container(
          width: double.infinity,
          decoration: BoxDecoration(
            color: ColorConsts.primaryBlue,
            borderRadius: BorderRadius.circular(16),
          ),
          padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                "تغيير كلمة المرور",
                textAlign: TextAlign.center,
                style: TextStyle(color: Colors.white, fontSize: 22),
              ),
              SizedBox(height: 16),
              CommonTextFieldWidget(hint: "كلمة المرور الحالية", controller: _currentPasswordController, prefixIcon: "assets/icons/password.svg"),
              SizedBox(height: 8),
              CommonTextFieldWidget(hint: "كلمة المرور الجديدة", controller: _passwordController, prefixIcon: "assets/icons/password.svg"),
              SizedBox(height: 8),
              CommonTextFieldWidget(hint: "تأكيد كلمة المرور الجديدة", controller: _confirmPasswordController, prefixIcon: "assets/icons/password.svg"),
              SizedBox(height: 16),
              SizedBox(
                width: double.infinity,
                height: 40,
                child: TextButton(
                  onPressed: () {
                    if (_currentPasswordController.text.length < 1) {
                      Utils.showToast("يرجى إاخال كلمة المرور");
                      return;
                    }
                    if (_passwordController.text.length < 1) {
                      Utils.showToast("يرجى إاخال كلمة المرور");
                      return;
                    }
                    if (_confirmPasswordController.text.length < 1) {
                      Utils.showToast("يرجى تأكيد كلمة المرور");
                      return;
                    }
                    if (_passwordController.text != _confirmPasswordController.text) {
                      Utils.showToast("خطأ في تطابق كلمات المرور");
                      return;
                    }
                    widget.onPassword(_currentPasswordController.text, _passwordController.text);
                  },
                  style: TextButton.styleFrom(
                    primary: Colors.white,
                    padding: EdgeInsets.all(2),
                    backgroundColor: ColorConsts.secondaryPink,
                    textStyle: TextStyle(fontSize: 14, fontFamily: "DroidKufi"),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(6.0),
                    ),
                  ),
                  child: Text("إعادة تعيين كلمة المرور"),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
