import { useResetPasswordMutation } from "../../gql"
import { useFormHandler, TextInput } from "../../form"

const initialValues = {
  token: '',
  password: '',
  passwordAgain: ''
}

const ResetPassword = () => {

  const [resetPassword, { loading, error }] = useResetPasswordMutation()
  const { inputProps, values: { token, password } } = useFormHandler(initialValues)

  return (
    <form onSubmit={async (event: React.FormEvent) => {
      event.preventDefault()
      resetPassword({ variables: { token, password } })
    }}>
      <TextInput label='Password' {...inputProps('password')} />
      <TextInput label='Repeat password' {...inputProps('passwordAgain')} />
      <button type='submit' disabled={loading}>Reset Password</button>
    </form>
  )
}

export default ResetPassword
