'use strict';

const index = require('./index-8277cbb3.js');
const global = require('./global-b7b1b8fe.js');
const JSS = require('./JSS-8503a151.js');
const sqmTextSpanView = require('./sqm-text-span-view-b9e10f5d.js');

function PortalProfileView(props) {
  var _a, _b, _c, _d, _e;
  const { states, callbacks } = props;
  const { text, formState } = states;
  const { errors, error } = formState;
  const style = {
    Container: {
      display: "flex",
      flexDirection: "column",
      gap: "var(--sl-spacing-xxx-large)",
      padding: "var(--sl-spacing-xxx-large)",
    },
    FormStyle: {
      width: "100%",
      minWidth: "700px",
      "& >*:not(:last-child)": {
        "margin-bottom": "32px",
      },
      "@media screen and (max-width: 1100px)": {
        minWidth: "100%",
      },
    },
    Error: {
      "&::part(erroralert-base)": {
        "margin-bottom": "32px",
      },
    },
    Success: {
      "&::part(successalert-base)": {
        "margin-bottom": "32px",
      },
    },
    NameInputStyle: {
      width: "50%",
      "@media screen and (max-width: 860px)": {
        width: "100%",
        "margin-right": "0",
      },
    },
    NameInputContainer: {
      display: "flex",
      gap: "32px",
      width: "100%",
      "@media screen and (max-width: 860px)": {
        flexDirection: "column",
      },
    },
  };
  const sheet = JSS.createStyleSheet(style);
  const styleString = sheet.toString();
  const country = ((_a = states.user) === null || _a === void 0 ? void 0 : _a.countryCode) ? global.intl.formatDisplayName((_b = states.user) === null || _b === void 0 ? void 0 : _b.countryCode, {
    type: "region",
  })
    : "";
  return (index.h("div", { class: sheet.classes.Container, part: "sqm-base" },
    index.h("style", { type: "text/css" }, styleString),
    index.h(sqmTextSpanView.TextSpanView, Object.assign({}, { type: "h1" }), text.editProfileHeader),
    index.h(sqmTextSpanView.TextSpanView, Object.assign({}, { type: "h2" }), text.editProfileSubHeader),
    index.h("form", { class: sheet.classes.FormStyle, onSubmit: callbacks.onSubmit },
      states.success && (index.h("sqm-form-message", { class: sheet.classes.Success, exportparts: "success-icon" },
        index.h("div", { part: "successalert-text" }, text.submissionSuccessText))),
      error && (index.h("sqm-form-message", { class: sheet.classes.Error, type: "error", exportparts: "erroralert-icon" },
        index.h("div", { part: "erroralert-text" }, error))),
      index.h("div", { class: sheet.classes.NameInputContainer },
        index.h("sl-input", Object.assign({ class: sheet.classes.NameInputStyle, exportparts: "label: input-label, base: input-base", value: (_c = states.user) === null || _c === void 0 ? void 0 : _c.firstName, onInput: callbacks.onChange, label: text.firstnametext, disabled: states.loading }, ((errors === null || errors === void 0 ? void 0 : errors.firstName) && (errors === null || errors === void 0 ? void 0 : errors.firstName.status) !== "valid"
          ? { class: "ErrorStyles", helpText: text.fieldEmptyText }
          : []), { id: "firstName", name: "firstName", error: (errors === null || errors === void 0 ? void 0 : errors.firstName) && (errors === null || errors === void 0 ? void 0 : errors.firstName.status) !== "valid"
            ? errors === null || errors === void 0 ? void 0 : errors.firstName.message : undefined })),
        index.h("sl-input", Object.assign({ class: sheet.classes.NameInputStyle, exportparts: "label: input-label, base: input-base", value: (_d = states.user) === null || _d === void 0 ? void 0 : _d.lastName, onInput: callbacks.onChange, label: text.lastnametext, disabled: states.loading, id: "lastName", name: "lastName" }, ((errors === null || errors === void 0 ? void 0 : errors.lastName) && (errors === null || errors === void 0 ? void 0 : errors.lastName.status) !== "valid"
          ? { class: "ErrorStyles", helpText: text.fieldEmptyText }
          : []), { error: (errors === null || errors === void 0 ? void 0 : errors.lastName) && (errors === null || errors === void 0 ? void 0 : errors.lastName.status) !== "valid"
            ? errors === null || errors === void 0 ? void 0 : errors.lastName.message : undefined }))),
      index.h("sl-input", { label: text.emailtext, value: (_e = states.user) === null || _e === void 0 ? void 0 : _e.email, exportparts: "label: input-label, base: input-base", disabled: true }),
      states.showCountry && (index.h("sl-input", { label: text.countrytext, value: country, exportparts: "label: input-label, base: input-base", disabled: true })),
      index.h("sl-button", { type: "primary", exportparts: "base: primarybutton-base", loading: states.loading, disabled: states.submitDisabled, onClick: (e) => {
          callbacks.onSubmit(e);
        }, submit: true }, text.submitChangeButtonText))));
}

exports.PortalProfileView = PortalProfileView;
