'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-140bcbcd.js');
const unknown = require('./unknown-38d3748c.js');
require('./App-0b3e3f31.js');
require('./Token-8c5ba5d9.js');
const Notice = require('./Notice-e970b490.js');
const Handler = require('./Handler-51fdca63.js');
const index = require('./index-d3079b93.js');
const Item = require('./Item-00ce8c24.js');
const index$2 = require('./index-ac98852d.js');
require('./Credentials-8e4749ab.js');
require('./index-dc498c54.js');
require('./_commonjsHelpers-537d719a.js');
require('./index-09251373.js');
require('./TextDecoder-753156f3.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 index.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) {
    index$1.registerInstance(this, hostRef);
    this.notice = index$1.createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$3(this.element);
  }
  async updateContact(event) {
    this.notice.emit(Notice.Notice.execute(this.t("Updating contact information..."), async () => {
      let result;
      this.customer.contact = event.detail;
      const response = this.customer.contact
        ? Handler.Handler.client.customer.setContact(this.customer.contact, "me")
        : unknown.malformedContent("contact", "model.Contact", "Contact information missing");
      if (!unknown.Error.is(response))
        result = [true, this.t("Updated contact information.")];
      else
        result = [false, this.t("Failed to update contact information.")];
      return result;
    }));
  }
  render() {
    return [
      index$1.h("h2", { color: "light" }, this.t("Contact information")),
      index$1.h("ig-customer-contact", { customer: this.customer }),
    ];
  }
  get element() { return index$1.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 index.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) {
    index$1.registerInstance(this, hostRef);
    this.notice = index$1.createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$2(this.element);
  }
  equalize() {
    this.notice.emit(Notice.Notice.execute(this.t("Equalizing balance..."), async () => {
      let result;
      const response = await Handler.Handler.client.customer.equalizeBalance("me");
      if (unknown.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.Notice.execute(this.t("Topping up balance..."), async () => {
      let result;
      const response = await Handler.Handler.client.order.create(event.detail);
      if (!unknown.Error.is(response) && index$2.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.Handler.client.customer.get("me");
    if (index$2.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 [
      index$1.h("ig-balance-add", { customer: this.customer }),
      index$1.h("ig-customer-balance", { customer: this.customer }),
      index$1.h("ig-orders", { display: true, orders: orders }),
    ];
  }
  get element() { return index$1.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 index.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) {
    index$1.registerInstance(this, hostRef);
    this.notice = index$1.createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  async sendLink() {
    var _a, _b, _c, _d;
    Item.Connection.url = (_b = (_a = this.unpackedKey) === null || _a === void 0 ? void 0 : _a.iss) !== null && _b !== void 0 ? _b : "";
    Item.Connection.key = (_d = (_c = this.unpackedKey) === null || _c === void 0 ? void 0 : _c.token) !== null && _d !== void 0 ? _d : "";
    this.notice.emit(Notice.Notice.execute(this.t("Sending email..."), async () => {
      var _a, _b;
      let result;
      const response = await Handler.Handler.client.customer.createLink((_b = (_a = this.unpackedKey) === null || _a === void 0 ? void 0 : _a.customer) !== null && _b !== void 0 ? _b : "");
      if (response && !unknown.Error.is(response))
        result = [true, this.t("Email was sent.")];
      else
        result = [false, this.t("Failed to send email.")];
      return result;
    }));
  }
  render() {
    return [
      index$1.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 && (index$1.h("smoothly-submit", { color: "success", fill: "solid", onSubmit: () => this.sendLink() }, this.t("Send email"))),
    ];
  }
  get element() { return index$1.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) {
    index$1.registerInstance(this, hostRef);
    this.selected = index$1.createEvent(this, "selected", 7);
    this.apiKeys = [];
    this.open = true;
    this.expired = false;
  }
  componentWillLoad() {
    Handler.Handler.client.me.customerKeys.forEach(async (key) => {
      const apikey = await index$2.Key.getVerifier()
        .add(index$2.Remover.create(["exp"]))
        .verify(key, "customer");
      if (apikey)
        this.apiKeys = [...this.apiKeys, apikey];
    });
  }
  async login(index) {
    this.selected.emit([Handler.Handler.client.me.customerKeys[index], this.apiKeys[index]]);
    this.open = false;
  }
  render() {
    return [
      this.apiKeys.length > 0 ? (index$1.h("smoothly-dialog", { open: this.open, header: "Intergiro Customer" }, this.apiKeys.map((key, index) => (index$1.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) {
    index$1.registerInstance(this, hostRef);
    this.update = index$1.createEvent(this, "update", 7);
    this.add = index$1.createEvent(this, "add", 7);
  }
  componentWillLoad() {
    var _a;
    this.apiKey = (_a = Item.Connection.key) !== null && _a !== void 0 ? _a : "";
    Item.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 (index$1.h(index$1.Host, { style: this.getCustomCssVariables() }, (this.customer.status == "suspended" || this.customer.status == "pending") && (index$1.h("customer-warning", { color: "warning" })), index$1.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) {
    index$1.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 (index$1.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 index.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) {
    index$1.registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  render() {
    return this.customer.subscription && this.customer.subscription.length > 0 ? (this.customer.subscription.map(s => (index$1.h("customer-subscriptions-panel", { cosmetic: this.cosmetic, subscription: s })))) : (index$1.h("smoothly-display", null, this.t("No subscriptions exists.")));
  }
  get element() { return index$1.getElement(this); }
};
CustomerSubscriptions.style = styleCss;

exports.customer_address = CustomerAddress;
exports.customer_balance = CustomerBalance;
exports.customer_error = CustomerError;
exports.customer_login = CustomerLogin;
exports.customer_methods = CustomerMethods;
exports.customer_orders = CustomerOrders;
exports.customer_subscriptions = CustomerSubscriptions;
