'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { use, useState, useEffect } from 'react';
import { Input } from '../../../fd-component-toolbox/input/Input.js';
import { Button } from '../../../fd-component-toolbox/button/Button.js';
import { useForm } from 'react-hook-form';
import { onRegisterSubmit } from './RegisterForm.funcs.js';
import { Label } from '../../../fd-component-toolbox/label/Label.js';
import { useRouter } from '../../../meta/client/framework/hooks.js';
import { FormItem, FormControl, FormMessage, Form, FormField } from '../../../fd-component-toolbox/form/Form.js';
import '../../../fd-component-toolbox/client/framework/index.js';
import { Card, CardHeader, CardTitle, CardContent } from '../../../fd-component-toolbox/card/Card.js';
import { wellKnownUserProps } from '../../../../fd-toolbox/constants/common-user-fields.js';
import { Icon, iconNames } from '../../../fd-component-toolbox/icon/Icon.js';
import { useSetTitle } from '../../../meta/page/use-set-title.js';
import { routes } from '../../../../fd-toolbox/routing/routes.js';
import { Link } from '../../../fd-component-toolbox/link/Link.js';
import { notifyError } from '../../../../fd-toolbox/notifications.js';
import { userFriendlyWorkspaceInviteMessages } from '../../constants/user-friendly-workspace-invite-messages.js';
import { useTheme } from '../../providers/ThemeProvider/ThemeProvider.js';
import { themes } from '../../menu/themes.js';
import { auths } from '../../../../fd-toolbox-core/server/constants/auth-constants.js';
import { userDisplayProps } from '../../user-dto.js';
import { formMethods } from '../../../../base-repo/constants/tools-constants.js';
import FrameworkImage from 'next/image.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const pageTitle = "Sign Up";
function RegisterForm(t0) {
  const $ = c(18);
  const {
    userInviteValidationResultPromise,
    userWorkspaceInviteId
  } = t0;
  const userInviteValidationResult = use(userInviteValidationResultPromise);
  const [hidePassword, setHidePassword] = useState(true);
  const [errorMessage, setErrorMessage] = useState(void 0);
  useSetTitle(pageTitle);
  let t1;
  let t2;
  if ($[0] !== userInviteValidationResult) {
    t1 = () => {
      if (userInviteValidationResult && !userInviteValidationResult.isValid) {
        if (userInviteValidationResult.userFriendlyErrorMessage) {
          notifyError(userInviteValidationResult.userFriendlyErrorMessage);
        } else {
          notifyError(userFriendlyWorkspaceInviteMessages.notValidInviteCode);
        }
      }
    };
    t2 = [userInviteValidationResult];
    $[0] = userInviteValidationResult;
    $[1] = t1;
    $[2] = t2;
  } else {
    t1 = $[1];
    t2 = $[2];
  }
  useEffect(t1, t2);
  const {
    appliedTheme
  } = useTheme();
  const imgSrc = appliedTheme === themes.light ? themes.lightLoginImage : themes.darkLoginImage;
  let t3;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = {
      defaultValues: {
        email: auths.defaultEmail,
        password: auths.defaultPwd
      },
      mode: formMethods.onChange
    };
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const form = useForm(t3);
  const router = useRouter();
  let t4;
  if ($[4] !== errorMessage || $[5] !== form || $[6] !== hidePassword || $[7] !== imgSrc || $[8] !== router || $[9] !== userWorkspaceInviteId) {
    let t5;
    if ($[11] !== router || $[12] !== userWorkspaceInviteId) {
      t5 = async data => {
        onRegisterSubmit(data, router, setErrorMessage, userWorkspaceInviteId);
      };
      $[11] = router;
      $[12] = userWorkspaceInviteId;
      $[13] = t5;
    } else {
      t5 = $[13];
    }
    let t6;
    if ($[14] !== hidePassword) {
      t6 = t7 => {
        const {
          field
        } = t7;
        return jsx(FormItem, {
          children: jsxs("div", {
            className: "w-full py-1",
            children: [jsx(Label, {
              children: userDisplayProps.email
            }), jsx(FormControl, {
              children: jsx(Input, {
                ...field,
                inputId: "registerInput",
                placeholder: userDisplayProps.email,
                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, {})]
          })
        });
      };
      $[14] = hidePassword;
      $[15] = t6;
    } else {
      t6 = $[15];
    }
    let t7;
    if ($[16] !== hidePassword) {
      t7 = t8 => {
        const {
          field: field_0
        } = t8;
        return jsx(FormItem, {
          children: jsxs("div", {
            className: "w-full py-1",
            children: [jsxs(Label, {
              children: [" ", userDisplayProps.password]
            }), jsxs("div", {
              className: "",
              children: [jsx(FormControl, {
                children: jsx(Input, {
                  ...field_0,
                  inputId: "registerPasswordInput",
                  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(_temp2),
                    children: jsx(Icon, {
                      name: hidePassword ? iconNames.visibility : iconNames.visibilityOff
                    })
                  })
                })
              }), jsx(FormMessage, {})]
            })]
          })
        });
      };
      $[16] = hidePassword;
      $[17] = t7;
    } else {
      t7 = $[17];
    }
    t4 = jsxs("div", {
      className: "relative h-screen w-full overflow-hidden",
      children: [jsx(FrameworkImage, {
        src: imgSrc,
        alt: "Forest",
        fill: true,
        className: "object-cover",
        priority: true
      }), 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: "Sign Up"
            })
          }), jsx(CardContent, {
            className: "p-0",
            children: jsx(Form, {
              ...form,
              children: jsxs("form", {
                onSubmit: form.handleSubmit(t5),
                children: [jsx(FormField, {
                  control: form.control,
                  name: wellKnownUserProps.email,
                  render: t6
                }), jsx(FormField, {
                  control: form.control,
                  name: wellKnownUserProps.password,
                  render: t7
                }), jsxs("div", {
                  className: "flex w-full justify-center gap-1 px-1 pt-2",
                  children: [jsx("p", {
                    className: "text-sm",
                    children: "Already have an account?"
                  }), jsx(Link, {
                    className: "text-muted-foreground inline-block text-sm",
                    href: routes.login,
                    children: "Sign In"
                  })]
                }), jsx(Button, {
                  className: "mt-4 mr-4 block w-full",
                  id: "registerButton",
                  disabled: !form.formState.isValid,
                  type: "submit",
                  children: "Sign Up"
                }), errorMessage && jsx("div", {
                  className: "mt-4",
                  children: jsx("p", {
                    className: "text-destructive",
                    children: errorMessage
                  })
                })]
              })
            })
          })]
        })
      })]
    });
    $[4] = errorMessage;
    $[5] = form;
    $[6] = hidePassword;
    $[7] = imgSrc;
    $[8] = router;
    $[9] = userWorkspaceInviteId;
    $[10] = t4;
  } else {
    t4 = $[10];
  }
  return t4;
}
function _temp2(prev_0) {
  return !prev_0;
}
function _temp(prev) {
  return !prev;
}
__name(RegisterForm, "RegisterForm");

export { RegisterForm as default };
