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


export const ResetPasswordForm = () => {
    const {
        handleSubmit,
        formState: { errors },
        control
    } = useForm<ResetPasswordInterface>({
        resolver: yupResolver(resetPasswordSchema)
    })
    const handleResetPassword: SubmitHandler<ResetPasswordInterface> = async (data) => {
        console.log("data=>", data)
    }
    return (
        <form onSubmit={handleSubmit(handleResetPassword)}
            className="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">
                <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-col md:flex-row gap-0.5 items-center">
                        <p className="text-secondary-text-color font-normal text-xs md:text-sm">کد تایید ارسال شده به شماره 09376225448 را وارد کنید.</p>
                        <Link to="/auth/forgot-password">
                            <p className="text-primary-color font-bold text-xs md:text-sm cursor-pointer">ویرایش</p>
                        </Link>
                    </div>
                </div>
                <div className="flex flex-col gap-y-[25px] mt-9 mb-[42px]">
                    <Controller control={control} name="password" render={({ field }) => (<div>
                        <Input type="password" placeholder="رمز عبور" field={field} />
                        <ErrorComponent show={errors.password} message={errors.password?.message} />
                    </div>)} />
                    <Controller control={control} name="repeatPassword" render={({ field }) => (<div>
                        <Input type="password" placeholder="تکرار رمز عبور" field={field} />
                        <ErrorComponent show={errors.repeatPassword} message={errors.repeatPassword?.message} />
                    </div>)} />
                </div>
                <Button type="submit">ذخیره</Button>
            </div>
        </form>
    )
}