import {
  AuthLayout
} from "./chunk-QEFPTNPC.js";
import {
  AvatarBox
} from "./chunk-CP5IL4P6.js";
import "./chunk-FMFVTERD.js";
import {
  i18n
} from "./chunk-ZZ4JC4WE.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import "./chunk-U2EI2ZLM.js";
import {
  require_dist
} from "./chunk-52KJSIHS.js";
import "./chunk-QHQWEERJ.js";
import "./chunk-Y7QKP6QU.js";
import {
  useFeatureFlags
} from "./chunk-RLRWDHME.js";
import {
  useSignUpWithEmailPass
} from "./chunk-K5324KIX.js";
import "./chunk-FV76G2D7.js";
import "./chunk-GHDLST2P.js";
import "./chunk-YVYYOBAE.js";
import "./chunk-L2NJPDUD.js";
import "./chunk-P7UBW2EI.js";
import "./chunk-MR6REQKT.js";
import "./chunk-EPSDO2MJ.js";
import "./chunk-BHEU34FL.js";
import "./chunk-W34KDYZA.js";
import "./chunk-II3CLUXA.js";
import "./chunk-XKEYHWBS.js";
import "./chunk-J2XUEO2E.js";
import "./chunk-656G74I2.js";
import "./chunk-VWPNMEOE.js";
import "./chunk-O72AIZUN.js";
import "./chunk-VUWAOX7H.js";
import "./chunk-5DKUSZQ7.js";
import "./chunk-DIAWPVYS.js";
import "./chunk-4U2BLH45.js";
import "./chunk-YAUGB4LD.js";
import "./chunk-A5DJIOHN.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-DTGEFKK4.js";
import {
  __toESM
} from "./chunk-NBMM2TZK.js";

// src/pages/register/register.tsx
var import_types = __toESM(require_dist(), 1);
import { Children, useState } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { Spinner } from "@medusajs/icons";
import { Button, Heading, Hint, Input, Text } from "@medusajs/ui";
import { useForm } from "react-hook-form";
import { Trans, useTranslation } from "react-i18next";
import { Link, Navigate, useNavigate } from "react-router-dom";
import config from "virtual:mercur/config";

// src/pages/register/register-schema.ts
import * as z from "zod";
var RegisterSchema = z.object({
  first_name: z.string().min(1, i18n.t("register.validation.firstNameRequired")),
  last_name: z.string().min(1, i18n.t("register.validation.lastNameRequired")),
  email: z.string().email(i18n.t("register.validation.emailInvalid")),
  password: z.string().min(8, i18n.t("register.validation.passwordMinLength")).refine((val) => val.trim().length >= 8, {
    message: i18n.t("register.validation.passwordMinLength")
  }).refine((val) => /[a-z]/.test(val) && /[A-Z]/.test(val) && /[\d\W]/.test(val), {
    message: i18n.t("register.validation.passwordComplexity")
  })
});

// src/pages/register/register.tsx
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var REGISTER_DRAFT_KEY = "mercur_register_draft";
var RegisterLogo = () => {
  return /* @__PURE__ */ jsx(AvatarBox, {});
};
var RegisterHeader = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-col", children: [
    /* @__PURE__ */ jsx(Heading, { children: t("register.title", { name: config.name ?? "Mercur" }) }),
    /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: t("register.hint", { name: config.name ?? "Mercur" }) })
  ] });
};
var RegisterForm = () => {
  const { t } = useTranslation();
  const navigate = useNavigate();
  const [serverError, setServerError] = useState(null);
  const form = useForm({
    resolver: zodResolver(RegisterSchema),
    mode: "onSubmit",
    reValidateMode: "onSubmit",
    defaultValues: {
      first_name: "",
      last_name: "",
      email: "",
      password: ""
    }
  });
  const { mutateAsync: signUp, isPending } = useSignUpWithEmailPass();
  const handleSubmit = form.handleSubmit(async ({ first_name, last_name, email, password }) => {
    setServerError(null);
    try {
      await signUp({ email, password });
      sessionStorage.setItem(
        REGISTER_DRAFT_KEY,
        JSON.stringify({ first_name, last_name, email })
      );
      navigate("/onboarding", { state: { email, first_name, last_name } });
    } catch (error) {
      setServerError(error?.message || t("register.error"));
    }
  });
  return /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex w-full flex-col gap-y-6", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "first_name",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("register.firstName") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { autoComplete: "given-name", ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "last_name",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("register.lastName") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { autoComplete: "family-name", ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "email",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("fields.email") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { autoComplete: "email", ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "password",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("fields.password") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
              Input,
              {
                type: "password",
                autoComplete: "new-password",
                ...field
              }
            ) }),
            /* @__PURE__ */ jsx(Form.Hint, { children: t("register.passwordHint") }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      serverError && /* @__PURE__ */ jsx(Hint, { className: "inline-flex", variant: "error", children: serverError })
    ] }),
    /* @__PURE__ */ jsx(Button, { className: "w-full", type: "submit", isLoading: isPending, children: t("actions.continue") })
  ] }) });
};
var RegisterFooter = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx("div", { className: "mt-auto", children: /* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted txt-small", children: /* @__PURE__ */ jsx(
    Trans,
    {
      t,
      i18nKey: "register.alreadySeller",
      components: [
        /* @__PURE__ */ jsx(
          Link,
          {
            to: "/login",
            className: "text-ui-fg-interactive transition-fg hover:text-ui-fg-interactive-hover focus-visible:text-ui-fg-interactive-hover font-medium outline-none"
          },
          "login-link"
        )
      ]
    }
  ) }) });
};
var Root = ({ children }) => {
  const { feature_flags, isLoading } = useFeatureFlags();
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "flex min-h-screen items-center justify-center", children: /* @__PURE__ */ jsx(Spinner, { className: "text-ui-fg-interactive animate-spin" }) });
  }
  if (!feature_flags?.[import_types.MercurFeatureFlags.SELLER_REGISTRATION]) {
    return /* @__PURE__ */ jsx(Navigate, { to: "/login", replace: true });
  }
  return /* @__PURE__ */ jsx(AuthLayout, { children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(RegisterLogo, {}),
    /* @__PURE__ */ jsxs("div", { className: "mt-6", children: [
      /* @__PURE__ */ jsx(RegisterHeader, {}),
      /* @__PURE__ */ jsx(RegisterForm, {})
    ] }),
    /* @__PURE__ */ jsx(RegisterFooter, {})
  ] }) });
};
var RegisterPage = Object.assign(Root, {
  Logo: RegisterLogo,
  Header: RegisterHeader,
  Form: RegisterForm,
  Footer: RegisterFooter
});
export {
  RegisterPage
};
