import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './_commonjsHelpers-91fffb88.js';
import { a as Customer, N as Name } from './index-ec2a4942.js';
import { d as dist } from './index-fdd60c34.js';

const sv = {
  Name: "Namn",
  Type: "Typ",
  Number: "Nummer",
  "Identity number": "Personnummer",
  Email: "E-post",
  "Phone number": "Telefonnummer",
  Address: "Adress",
  "Failed to update customer information.": "Kunde inte uppdatera kundinformation.",
  "Updated customer information.": "Kundinformation uppdaterad.",
  "Updating customer information...": "Uppdaterar kundinformation...",
};

function create(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-payfunc-account-customer-h{display:flex;flex-wrap:wrap;justify-content:space-between}[hidden].sc-payfunc-account-customer-h{display:none}.sc-payfunc-account-customer-h>section.sc-payfunc-account-customer{width:50%;min-width:17em;display:flex;flex-direction:column}.sc-payfunc-account-customer-h>section.sc-payfunc-account-customer>label.sc-payfunc-account-customer{font-weight:bold}.sc-payfunc-account-customer-h>section.sc-payfunc-account-customer>payfunc-display-edit.sc-payfunc-account-customer{padding-top:.5em}.sc-payfunc-account-customer-h>section.sc-payfunc-account-customer>*.sc-payfunc-account-customer:not(label){min-height:5em;max-width:14em}.sc-payfunc-account-customer-h>section.sc-payfunc-account-customer>label.sc-payfunc-account-customer{padding-top:1em}";

const PayfuncAccountCustomer = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.updateCustomer = createEvent(this, "updateCustomer", 7);
    this.types = ["organization", "person"];
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async update(property, value) {
    var _a;
    if (!value || Object.keys(value).length == 0)
      (_a = this.account.customer) === null || _a === void 0 ? true : delete _a[property];
    else {
      const update = { [property]: value };
      if (Customer.is(update))
        this.account.customer = Object.assign(Object.assign({}, this.account.customer), update);
    }
    this.updateCustomer.emit(this.account.customer);
  }
  render() {
    var _a, _b;
    const customer = this.account.customer;
    return [
      h("section", null, h("label", null, this.t("Name")), h("payfunc-display-edit", { type: "text", name: this.t("Name"), value: (customer === null || customer === void 0 ? void 0 : customer.name) ? Name.get(customer.name) : undefined, onChanged: (e) => this.update("name", e.detail) })),
      h("section", null, h("label", null, this.t("Type")), h("payfunc-display-edit", { type: "text", name: this.t("Type"), value: customer === null || customer === void 0 ? void 0 : customer.type, select: this.types, onChanged: (e) => this.update("type", e.detail) })),
      h("section", null, h("label", null, this.t("Number")), h("smoothly-display", { type: "text", value: customer === null || customer === void 0 ? void 0 : customer.number })),
      h("section", null, h("label", null, this.t("Identity number")), h("payfunc-display-edit", { type: "identity-number", name: this.t("Identity number"), value: customer === null || customer === void 0 ? void 0 : customer.identityNumber, onChanged: (e) => this.update("identityNumber", e.detail) })),
      h("section", null, h("label", null, this.t("Email")), h("payfunc-email-addresses", { value: (_a = customer === null || customer === void 0 ? void 0 : customer.email) !== null && _a !== void 0 ? _a : "", onChanged: (e) => this.update("email", e.detail) })),
      h("section", null, h("label", null, this.t("Phone number")), h("payfunc-phone-numbers", { value: (_b = customer === null || customer === void 0 ? void 0 : customer.phone) !== null && _b !== void 0 ? _b : "", onChanged: (e) => this.update("phone", e.detail) })),
      h("section", null, h("label", null, this.t("Address")), h("payfunc-addresses", { value: customer === null || customer === void 0 ? void 0 : customer.address, onChanged: (e) => this.update("address", e.detail) })),
    ];
  }
  get element() { return getElement(this); }
};
PayfuncAccountCustomer.style = styleCss;

export { PayfuncAccountCustomer as payfunc_account_customer };
