import { r as registerInstance, c as createEvent, h, g as getElement, H as Host } from './index-08b73e9e.js';
import { m as malformedContent, E as Error } from './unknown-97022c22.js';
import './App-364e27cc.js';
import './Token-ba2c5d5c.js';
import { N as Notice } from './Notice-668f9bc7.js';
import { H as Handler } from './Handler-bd5ad0e8.js';
import { d as dist } from './index-a0a71287.js';
import { a as Connection } from './Item-f4cbd6f4.js';
import { O as Order, c as Customer, K as Key, R as Remover } from './index-3299c1c0.js';
import './Credentials-b84c0c5f.js';
import './index-26d778c4.js';
import './_commonjsHelpers-9943807e.js';
import './index-1f953d81.js';
import './TextDecoder-357ac2ce.js';

const sv$3 = {
  "Contact information": "Kontaktinformation",
  "Failed to update contact information.": "Kunde inte uppdatera kontaktinformation.",
  "Updated contact information.": "Kontaktinformation uppdaterad.",
  "Updating contact information...": "Uppdaterar kontaktinformation...",
};

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

const styleCss$6 = ".sc-customer-address-h{display:block;max-width:90em;margin:auto;border:1px solid rgb(var(--smoothly-medium-color));border-top:none}[component].sc-customer-address-h{width:calc(60em - 2px)}[hidden].sc-customer-address-h{display:none}.sc-customer-address-h>h2.sc-customer-address{padding:1em 2.5em;margin-bottom:1em}.sc-customer-address-h>ig-customer-contact.sc-customer-address{padding-left:4em}[component=\"app\"].sc-customer-address-h h2.sc-customer-address{display:none}";

const CustomerAddress = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$3(this.element);
  }
  async updateContact(event) {
    this.notice.emit(Notice.execute(this.t("Updating contact information..."), async () => {
      let result;
      this.customer.contact = event.detail;
      const response = this.customer.contact
        ? Handler.client.customer.setContact(this.customer.contact, "me")
        : malformedContent("contact", "model.Contact", "Contact information missing");
      if (!Error.is(response))
        result = [true, this.t("Updated contact information.")];
      else
        result = [false, this.t("Failed to update contact information.")];
      return result;
    }));
  }
  render() {
    return [
      h("h2", { color: "light" }, this.t("Contact information")),
      h("ig-customer-contact", { customer: this.customer }),
    ];
  }
  get element() { return getElement(this); }
};
CustomerAddress.style = styleCss$6;

const sv$2 = {
  "Equalizing balance...": "Justerar saldo...",
  "Balance was successfully equalized.": "Saldot har justerats.",
  "Failed to equalize balance.": "Kunde inte justera saldo.",
  "Topping up balance...": "Fyller på saldo...",
  "Balance was successfully topped up.": "Saldot har fyllts på.",
  "Failed to top up balance.": "Kunde inte fylla på saldo.",
};

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

const styleCss$5 = ".sc-customer-balance-h{display:block;width:90em;margin:auto;padding-top:2em}[hidden].sc-customer-balance-h{display:none}.sc-customer-balance-h>ig-balance-add.sc-customer-balance{padding-bottom:1em;float:left;padding-right:5em}.sc-customer-balance-h>ig-customer-balance.sc-customer-balance{padding-bottom:1em}[component].sc-customer-balance-h{padding-top:0;width:50em}[component=\"app\"].sc-customer-balance-h{width:60em}[component].sc-customer-balance-h>ig-customer-balance.sc-customer-balance{padding:0.5em}[component].sc-customer-balance-h>ig-balance-add.sc-customer-balance{padding-top:0.5em;padding-left:0.5em}[component].sc-customer-balance-h th.sc-customer-balance{position:relative}";

const CustomerBalance = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$2(this.element);
  }
  equalize() {
    this.notice.emit(Notice.execute(this.t("Equalizing balance..."), async () => {
      let result;
      const response = await Handler.client.customer.equalizeBalance("me");
      if (Error.is(response) || response.errors > 0)
        result = [false, this.t("Failed to equalize balance.")];
      else {
        await this.getCustomer();
        result = [true, this.t("Balance was successfully equalized.")];
      }
      return result;
    }));
  }
  onAddFunds(event) {
    this.notice.emit(Notice.execute(this.t("Topping up balance..."), async () => {
      let result;
      const response = await Handler.client.order.create(event.detail);
      if (!Error.is(response) && Order.is(response)) {
        this.orders = this.orders ? [response, ...this.orders] : [response];
        await this.getCustomer();
        result = [true, this.t("Balance was successfully topped up.")];
      }
      else
        result = [false, this.t("Failed to top up balance.")];
      return result;
    }));
  }
  async getCustomer() {
    const customer = await Handler.client.customer.get("me");
    if (Customer.is(customer))
      this.customer = customer;
  }
  render() {
    const orders = this.orders
      ? this.orders.filter(o => o.payment.type == "customer" || o.payment.type == "card" ? o.payment.charge == "balance" : false)
      : undefined;
    return [
      h("ig-balance-add", { customer: this.customer }),
      h("ig-customer-balance", { customer: this.customer }),
      h("ig-orders", { display: true, orders: orders }),
    ];
  }
  get element() { return getElement(this); }
};
CustomerBalance.style = styleCss$5;

const sv$1 = {
  "Sending email...": "Skickar e-post...",
  "Email was sent.": "E-post skickades",
  "Failed to send email.": "Misslyckades att skicka e-post.",
  "Your authorization is invalid or expired. Please check your email for a new link or press the button to send a new email.": "Din inloggning är ogiltig eller har upphört. Kontrollera din e-post efter en ny länk eller tryck på knappen för att skicka ett nytt e-postmeddelande.",
  "Your authorization is invalid or expired. Try refreshing the page or log out and then log in again. If that doesn't work, contact customer support.": "Din inloggning är ogiltig eller har upphört. Ladda om sidan eller logga ut och sedan logga in igen. Om det inte fungerar, kontakta kundtjänst.",
  "Send email": "Skicka e-post",
};

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

const styleCss$4 = ".sc-customer-error-h{display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-wrap:wrap;flex-wrap:wrap;text-align:center;-ms-flex-direction:column;flex-direction:column}smoothly-display.sc-customer-error{font-size:larger;width:30%;padding:2em;margin:2em;background-color:rgb(var(--smoothly-secondary-color));color:rgb(var(--smoothly-secondary-contrast));-ms-flex-item-align:center;align-self:center}smoothly-submit.sc-customer-error{max-width:8em;text-align:center;padding:.7em;cursor:pointer;-ms-flex-item-align:center;align-self:center}";

const CustomerError = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  async sendLink() {
    var _a, _b, _c, _d;
    Connection.url = (_b = (_a = this.unpackedKey) === null || _a === void 0 ? void 0 : _a.iss) !== null && _b !== void 0 ? _b : "";
    Connection.key = (_d = (_c = this.unpackedKey) === null || _c === void 0 ? void 0 : _c.token) !== null && _d !== void 0 ? _d : "";
    this.notice.emit(Notice.execute(this.t("Sending email..."), async () => {
      var _a, _b;
      let result;
      const response = await Handler.client.customer.createLink((_b = (_a = this.unpackedKey) === null || _a === void 0 ? void 0 : _a.customer) !== null && _b !== void 0 ? _b : "");
      if (response && !Error.is(response))
        result = [true, this.t("Email was sent.")];
      else
        result = [false, this.t("Failed to send email.")];
      return result;
    }));
  }
  render() {
    return [
      h("smoothly-display", null, this.t(this.component
        ? "Your authorization is invalid or expired. Try refreshing the page or log out and then log in again. If that doesn't work, contact customer support."
        : "Your authorization is invalid or expired. Please check your email for a new link or press the button to send a new email.")),
      !this.component && (h("smoothly-submit", { color: "success", fill: "solid", onSubmit: () => this.sendLink() }, this.t("Send email"))),
    ];
  }
  get element() { return getElement(this); }
};
CustomerError.style = styleCss$4;

const styleCss$3 = ".sc-customer-login-h{display:block}[hidden].sc-customer-login-h{display:none}.sc-customer-login-h>smoothly-dialog.sc-customer-login{top:60px;z-index:2}smoothly-display.sc-customer-login{border:1px solid rgb(var(--smoothly-medium-color));padding:.6em .2em .6em .2em;vertical-align:middle;cursor:pointer}";

const CustomerLogin = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.selected = createEvent(this, "selected", 7);
    this.apiKeys = [];
    this.open = true;
    this.expired = false;
  }
  componentWillLoad() {
    Handler.client.me.customerKeys.forEach(async (key) => {
      const apikey = await Key.getVerifier()
        .add(Remover.create(["exp"]))
        .verify(key, "customer");
      if (apikey)
        this.apiKeys = [...this.apiKeys, apikey];
    });
  }
  async login(index) {
    this.selected.emit([Handler.client.me.customerKeys[index], this.apiKeys[index]]);
    this.open = false;
  }
  render() {
    return [
      this.apiKeys.length > 0 ? (h("smoothly-dialog", { open: this.open, header: "Intergiro Customer" }, this.apiKeys.map((key, index) => (h("smoothly-display", { onClick: () => this.login(index) }, key.name + " " + key.customer))))) : (""),
    ];
  }
};
CustomerLogin.style = styleCss$3;

const styleCss$2 = ".sc-customer-methods-h{display:block;max-width:90em;width:100%;margin:auto;border-radius:5em;font-family:var(--smoothly-font-family)}.sc-customer-methods-h>ig-payment-methods.sc-customer-methods{display:inline-block;height:100%;width:100%}[component].sc-customer-methods-h>customer-warning.sc-customer-methods{margin:0px}[component].sc-customer-methods-h{width:auto;height:auto;padding:1em}";

const CustomerMethods = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.update = createEvent(this, "update", 7);
    this.add = createEvent(this, "add", 7);
  }
  componentWillLoad() {
    var _a;
    this.apiKey = (_a = Connection.key) !== null && _a !== void 0 ? _a : "";
    Connection.keyChanged.push(key => (this.apiKey = key !== null && key !== void 0 ? key : ""));
  }
  onUpdate(e) {
    this.update.emit(e.detail);
  }
  getCustomCssVariables() {
    var _a, _b, _c, _d, _e;
    const result = {};
    if (this.cosmetic && (typeof this.cosmetic == "object" || ((_a = this.cosmetic) === null || _a === void 0 ? void 0 : _a.length) > 0)) {
      const cosmetic = typeof this.cosmetic == "string" && this.cosmetic.length > 0 ? JSON.parse(this.cosmetic) : this.cosmetic;
      Object.entries({
        "--smoothly-font-family": (_b = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.fontFamily) !== null && _b !== void 0 ? _b : cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.font_family,
        "--smoothly-primary-color": (_c = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.header) === null || _c === void 0 ? void 0 : _c.background,
        "--smoothly-success-color": (_d = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.success) === null || _d === void 0 ? void 0 : _d.background,
        "--smoothly-success-contrast": (_e = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.success) === null || _e === void 0 ? void 0 : _e.color,
      }).forEach(([key, value]) => {
        value && (result[key] = value);
      });
    }
    return result;
  }
  render() {
    return (h(Host, { style: this.getCustomCssVariables() }, (this.customer.status == "suspended" || this.customer.status == "pending") && (h("customer-warning", { color: "warning" })), h("ig-payment-methods", { methods: this.methods, addable: true, deletable: true, mode: "card", "api-key": this.apiKey, customer: this.customer, onDelete: (e) => this.onUpdate(e), onUpdate: (e) => this.onUpdate(e) })));
  }
};
CustomerMethods.style = styleCss$2;

const styleCss$1 = ".sc-customer-orders-h>payfunc-orders.sc-customer-orders{font-family:var(--smoothly-font-family)}";

const CustomerOrders = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  getCustomCssVariables() {
    var _a, _b, _c, _d, _e, _f;
    const result = {};
    if (this.cosmetic && (typeof this.cosmetic == "object" || ((_a = this.cosmetic) === null || _a === void 0 ? void 0 : _a.length) > 0)) {
      const cosmetic = typeof this.cosmetic == "string" && this.cosmetic.length > 0 ? JSON.parse(this.cosmetic) : this.cosmetic;
      Object.entries({
        "--smoothly-font-family": (_b = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.fontFamily) !== null && _b !== void 0 ? _b : cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.font_family,
        "--smoothly-light-color": (_c = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.header) === null || _c === void 0 ? void 0 : _c.background,
        "--smoothly-light-contrast": (_d = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.header) === null || _d === void 0 ? void 0 : _d.color,
        "--smoothly-dark-shade": (_e = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.body) === null || _e === void 0 ? void 0 : _e.background,
        "--smoothly-default-shade": (_f = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.body) === null || _f === void 0 ? void 0 : _f.background,
      }).forEach(([key, value]) => {
        value && (result[key] = value);
      });
    }
    return result;
  }
  render() {
    return (h("ig-orders", { display: true, orders: this.orders, receipt: this.receipt, embedded: this.component, style: this.getCustomCssVariables() }));
  }
};
CustomerOrders.style = styleCss$1;

const sv = {
  "No subscriptions exists.": "Inga prenumerationer existerar.",
};

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

const styleCss = ".sc-customer-subscriptions-h{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:start;justify-content:flex-start}[component=\"subscription\"].sc-customer-subscriptions-h{max-width:48em}[component=\"subscription\"].sc-customer-subscriptions-h>*.sc-customer-subscriptions{margin:0.5em 0 0.5em 0}[component=\"subscription\"].sc-customer-subscriptions-h>*.sc-customer-subscriptions:first-child{margin-top:0}[component=\"subscription\"].sc-customer-subscriptions-h>*.sc-customer-subscriptions:last-child{margin-bottom:0}smoothly-display.sc-customer-subscriptions{-ms-flex-wrap:wrap;flex-wrap:wrap;text-align:center;font-size:larger;width:30%;padding:2em;margin:2em;background-color:rgb(var(--smoothly-secondary-color));-ms-flex-item-align:center;align-self:center}";

const CustomerSubscriptions = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  render() {
    return this.customer.subscription && this.customer.subscription.length > 0 ? (this.customer.subscription.map(s => (h("customer-subscriptions-panel", { cosmetic: this.cosmetic, subscription: s })))) : (h("smoothly-display", null, this.t("No subscriptions exists.")));
  }
  get element() { return getElement(this); }
};
CustomerSubscriptions.style = styleCss;

export { CustomerAddress as customer_address, CustomerBalance as customer_balance, CustomerError as customer_error, CustomerLogin as customer_login, CustomerMethods as customer_methods, CustomerOrders as customer_orders, CustomerSubscriptions as customer_subscriptions };
