import { h } from './index-38ad4957.js';
import { c as createStyleSheet } from './JSS-67b5cff8.js';
import { A as AuthWrapper, g as gap, a as AuthColumn, b as AuthButtonsContainer, E as ErrorStyles } from './mixins-f750863a.js';

const style = {
  Wrapper: {
    ...AuthWrapper,
    ...gap({ direction: "column", size: "var(--sl-spacing-small)" }),
  },
  Column: AuthColumn,
  ForgotButtonContainer: {
    display: "inline",
    cursor: "pointer",
    "font-size": "13px",
    "font-weight": "600",
    color: "#AAAAAA",
    margin: "0",
  },
  ButtonsContainer: AuthButtonsContainer,
  ErrorStyle: ErrorStyles,
};
const vanillaStyle = `
:host {
  display: block;
}
:host([hidden]): {
  display: none;
}
a svg {
  margin: 0 auto;
  display: block;
}
`;
const sheet = createStyleSheet(style);
const styleString = sheet.toString();
function EmailRegistrationView(props) {
  var _a, _b, _c, _d;
  const { states, callbacks, content } = props;
  const getErrorMessage = (error, fraudErrorMessage, fraudErrorMessageTitle) => {
    return error === "FRAUD" ? (h("sqm-form-message", { type: "error", exportparts: "erroralert-icon" },
      h("b", null, fraudErrorMessageTitle),
      h("div", { part: "erroralert-text" }, fraudErrorMessage))) : (h("sqm-form-message", { type: "error", exportparts: "erroralert-icon" },
      h("div", { part: "erroralert-text" }, error)));
  };
  const emailValidationRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return (h("div", { part: "sqm-base", class: sheet.classes.Wrapper, style: {
      border: `${content.hideBorder
        ? "none"
        : "var(--sqm-border-thickness, 1px) solid var(--sqm-border-color)"}`,
      backgroundColor: content.backgroundColor,
      "padding-top": `var(--sl-spacing-${content.paddingTop})`,
      "padding-right": `var(--sl-spacing-${content.paddingRight})`,
      "padding-bottom": `var(--sl-spacing-${content.paddingBottom})`,
      "padding-left": `var(--sl-spacing-${content.paddingLeft})`,
    } },
    h("style", { type: "text/css" },
      vanillaStyle,
      styleString),
    content.topSlot,
    h("sl-form", { class: sheet.classes.Column, "onSl-submit": callbacks.submit },
      props.states.error &&
        getErrorMessage(props.states.error, props.content.fraudErrorMessage, props.content.fraudErrorMessageTitle),
      content.includeName && (h("sl-input", { exportparts: "label: input-label, base: input-base", type: "name", name: "/firstName", label: content.firstNameLabel || "First Name", disabled: states.loading })),
      content.includeName && (h("sl-input", { exportparts: "label: input-label, base: input-base", type: "name", name: "/lastName", label: content.lastNameLabel || "Last Name", disabled: states.loading })),
      h("sl-input", Object.assign({ exportparts: "label: input-label, base: input-base", type: "email", name: "/email", label: content.emailLabel || "Email", disabled: states.loading, required: true, validationError: ({ value }) => {
          if (!value) {
            return content.requiredFieldErrorMessage;
          }
          if (!value.match(emailValidationRegex)) {
            return content.invalidEmailErrorMessage;
          }
        } }, (((_b = (_a = states.registrationFormState) === null || _a === void 0 ? void 0 : _a.validationErrors) === null || _b === void 0 ? void 0 : _b.email) ? {
        class: sheet.classes.ErrorStyle,
        helpText: ((_d = (_c = states.registrationFormState) === null || _c === void 0 ? void 0 : _c.validationErrors) === null || _d === void 0 ? void 0 : _d.email) ||
          content.requiredFieldErrorMessage,
      }
        : []))),
      h("div", { class: sheet.classes.ButtonsContainer, style: {
          paddingTop: `${content.includeName ? "var(--sl-spacing-medium)" : "0"}`,
        } },
        h("sl-button", { submit: true, loading: states.loading, exportparts: "base: primarybutton-base", type: "primary" }, content.registerLabel || "Registration"))),
    content.bottomSlot));
}

export { EmailRegistrationView as E };
