import { Link } from "react-router-dom"
import { Input } from "../common/input"
import { Controller, SubmitHandler, useForm } from "react-hook-form"
import { ForgotPasswordInterface } from "../../types"
import { yupResolver } from "@hookform/resolvers/yup"
import { forgotPasswordSchema } from "../../schema"
import { ErrorComponent } from "../common/error"
import { Button } from "@headlessui/react"

export const ForgotPasswordForm = () => {
    const {
        handleSubmit,
        formState: { errors },
        control
    } = useForm<ForgotPasswordInterface>({
        resolver: yupResolver(forgotPasswordSchema)
    })
    const handleForgotSubmit: SubmitHandler<ForgotPasswordInterface> = async (data) => { console.log("data=>", data) }

    return (
        <form onSubmit={handleSubmit(handleForgotSubmit)}
            className="w-full sm:w-fit sm:min-w-[500px] xl:w-1/2 xl:p-0 p-10 flex flex-col bg-auth-form justify-center items-center gap-y-[42px] rounded-3xl">
            <img src="/svgs/logo/logo.svg" alt="logo" className="auth-logo-size" />
            <div className="flex flex-col xl:-mr-24 w-full md:w-[400px]">
                <div className="flex flex-col gap-y-5">
                    <span className="font-medium text-lg md:text-2xl xl:text-3xl text-primary-text-color">فراموشی رمز عبور</span>
                    <div className="flex flex-row gap-x-0.5 items-center">
                        <p className="text-secondary-text-color font-normal text-xs md:text-sm">لطفا شماره موبایل خود را وارد کنید</p>
                    </div>
                </div>
                <div className="mt-9 mb-[42px]">
                    <Controller control={control} name="phoneNumber" render={({ field }) => (
                        <div>
                            <Input type="number" placeholder="شماره موبایل" field={field} />
                            <ErrorComponent show={errors.phoneNumber} message={errors?.phoneNumber?.message} />
                        </div>
                    )} />
                </div>
                <div className="flex flex-col gap-y-[27px] items-center">
                    <Button type="submit">دریافت کد تایید</Button>
                    <Link to="/auth/login">
                        <p className="font-medium text-base text-primary-color">بازگشت</p>
                    </Link>
                </div>
            </div>
        </form>
    )
}