'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { Card, CardHeader, CardTitle, CardContent } from '../../fd-component-toolbox/card/Card.js';
import { useSearchParams, useRouter } from '../../meta/client/framework/hooks.js';
import { FormItem, FormControl, FormMessage, Form, FormField } from '../../fd-component-toolbox/form/Form.js';
import { Label } from '../../fd-component-toolbox/label/Label.js';
import { Input } from '../../fd-component-toolbox/input/Input.js';
import { Button } from '../../fd-component-toolbox/button/Button.js';
import { getResetPasswordPasswordInputId, getResetPasswordResetButtonId, onResetPassword, getResetPasswordRepeatPasswordInputId } from './ResetPasswordForm.funcs.js';
import { wellKnownUserProps } from '../../../fd-toolbox/constants/common-user-fields.js';
import { Icon, iconNames } from '../../fd-component-toolbox/icon/Icon.js';
import { getRelativeLoginUrl } from '../../../fd-toolbox/routing/login-routers.js';
import { resetPasswordQueryParams } from '../../../base-repo/constants/internal-query-constants.js';
import { resetButtonText } from './reset-password-form-constants.js';
import { userDisplayProps } from '../user-dto.js';
import { formMethods } from '../../../base-repo/constants/tools-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function ResetPasswordForm() {
  const $ = c(3);
  const params = useSearchParams();
  const email = params.get(wellKnownUserProps.email) ?? void 0;
  const token = params.get(resetPasswordQueryParams.code) ?? void 0;
  const [hidePassword, setHidePassword] = useState(true);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      mode: formMethods.onChange
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const form = useForm(t0);
  const router = useRouter();
  let t1;
  if ($[1] !== hidePassword) {
    t1 = t2 => {
      const {
        field
      } = t2;
      return jsx(FormItem, {
        children: jsxs("div", {
          className: "w-full p-1",
          children: [jsx(Label, {
            children: userDisplayProps.password
          }), jsx(FormControl, {
            children: jsx(Input, {
              ...field,
              inputId: getResetPasswordPasswordInputId(),
              placeholder: userDisplayProps.password,
              type: hidePassword ? "password" : "text",
              showClearIcon: true,
              children: jsx(Button, {
                variant: "icon",
                size: "icon",
                type: "button",
                tabIndex: -1,
                className: "w-6",
                onClick: () => setHidePassword(_temp),
                children: jsx(Icon, {
                  name: hidePassword ? iconNames.visibility : iconNames.visibilityOff
                })
              })
            })
          }), jsx(FormMessage, {})]
        })
      });
    };
    $[1] = hidePassword;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  return jsx("div", {
    className: "relative h-screen w-full overflow-hidden",
    children: jsx("div", {
      className: "absolute inset-0 flex items-center justify-center",
      children: jsxs(Card, {
        className: "mx-auto grid w-80 gap-6 rounded-lg p-6 shadow-lg",
        children: [jsx(CardHeader, {
          className: "grid gap-2 p-0 text-center",
          children: jsx(CardTitle, {
            className: "text-3xl font-bold",
            children: "Reset Password"
          })
        }), jsx(CardContent, {
          className: "p-0",
          children: jsx(Form, {
            ...form,
            children: jsxs("form", {
              onSubmit: form.handleSubmit(async data => {
                onResetPassword(data, () => router.push(getRelativeLoginUrl()), email, token);
              }),
              children: [jsx(FormField, {
                control: form.control,
                name: wellKnownUserProps.password,
                render: t1
              }), jsx(FormField, {
                control: form.control,
                name: wellKnownUserProps.confirmPassword,
                render: _temp2
              }), jsx(Button, {
                className: "mt-4 mr-4 block w-full",
                id: getResetPasswordResetButtonId(),
                disabled: !form.formState.isValid,
                type: "submit",
                children: resetButtonText
              })]
            })
          })
        })]
      })
    })
  });
}
function _temp2(t0) {
  const {
    field: field_0
  } = t0;
  return jsx(FormItem, {
    children: jsxs("div", {
      className: "w-full p-1",
      children: [jsx(Label, {
        children: userDisplayProps.repeatPassword
      }), jsx(FormControl, {
        children: jsx(Input, {
          ...field_0,
          inputId: getResetPasswordRepeatPasswordInputId(),
          placeholder: userDisplayProps.repeatPassword,
          type: "password",
          showClearIcon: true
        })
      }), jsx(FormMessage, {})]
    })
  });
}
function _temp(prev) {
  return !prev;
}
__name(ResetPasswordForm, "ResetPasswordForm");

export { ResetPasswordForm as default };
