import React, { useState, useEffect } from "react";
import { Link, useNavigate } from 'react-router-dom';
import titleShape from "../../../assets/images/shape/title-shape-two.svg";
import InputCom from "../../Helpers/Inputs/InputCom";
import AuthLayout from "../AuthLayout";

export default function ForgotPassword() {

  const navigate = useNavigate();
  const [validation, setValidation] = useState("")
  const [buttonDisabled, setButtonDisabled] = useState(true)

  // email
  const [email, setEmail] = useState("");
  const handleEmail = (e) => {
    setEmail(e.target.value);
  };


  function validationChecker(email) {
    const emailCheck = /^[^0-9][a-zA-Z0-9._%+-]+@[a-zA-Z]+(\.[a-zA-Z]+)+$/;
    if (email === "") {
      setValidation("email is required");

    } else if (!email.match(emailCheck)) {
      setValidation('Please input a valid email address');

    } else {
      setValidation("");
      setButtonDisabled(false)
    }
  }

  useEffect(() => {
    validationChecker(email)
  }, [email])

  return (
    <>
      <AuthLayout
        slogan="Welcome to myFit"
      >
        <div className="content-wrapper xl:bg-white dark:bg-dark-white   xl:px-[70px] w-full sm:w-auto   2xl:px-[100px] h-[818px] rounded-xl ">
          <div className="flex flex-col justify-center w-full h-full px-5">
            <div className="title-area flex flex-col justify-center items-center relative text-center mb-7">
              <h1 className="sm:text-5xl text-4xl font-bold sm:leading-[74px]   text-dark-gray dark:text-white">
                Forget Password
              </h1>
              <div className="shape sm:w-[377px] w-[270px] -mt-1 ml-0">
                <img src={titleShape} alt="shape" />
              </div>
            </div>
            <div className="input-area">
              <div className="input-item mb-5">
                <InputCom
                  placeholder="example@quomodosoft.com"
                  label="Email Address"
                  name="email"
                  type="email"
                  iconName="message"
                  inputHandler={handleEmail}
                  value={email}
                />
                {validation && <p className="my-5 font-bold  text-red-500">{validation}</p>}
              </div>

              <div className="signin-area mb-3.5">

                <button
                  className="w-full rounded-[50px] mb-5 h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center"
                  disabled={buttonDisabled}
                  onClick={() => navigate("/verify-you")}
                >
                  Send Code
                </button>

                <Link to="/"
                  className="my-40 font-bold flex justify-center text-red-500 items-center"
                >
                  Back to Home
                </Link>
              </div>
            </div>
          </div>
        </div>
      </AuthLayout>
    </>
  );
}
