'use strict';

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

const index = require('./index-140bcbcd.js');
const Item = require('./Item-00ce8c24.js');
const index$1 = require('./index-76391849.js');
require('./Credentials-8e4749ab.js');
require('./Token-8c5ba5d9.js');
const index$2 = require('./index-d3079b93.js');
const unknown = require('./unknown-38d3748c.js');
require('./App-0b3e3f31.js');
const Notice = require('./Notice-e970b490.js');
require('./_commonjsHelpers-537d719a.js');
require('./index-09251373.js');
require('./TextDecoder-753156f3.js');

const styleCss$5 = ".sc-ig-customer-balance-h{display:block;padding-top:0.5em}[hidden].sc-ig-customer-balance-h{display:none}.sc-ig-customer-balance-h>section.sc-ig-customer-balance>ig-items-list.sc-ig-customer-balance{padding-top:1em}.sc-ig-customer-balance-h>section.sc-ig-customer-balance:first-of-type{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between}.sc-ig-customer-balance-h>section.sc-ig-customer-balance:last-of-type{display:block}ig-future-due-dates.sc-ig-customer-balance{min-width:13em}ig-orders-table.sc-ig-customer-balance{border:1px solid rgb(var(--smoothly-medium-color));margin-top:1em}main.sc-ig-customer-balance{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap}main.sc-ig-customer-balance>*.sc-ig-customer-balance{width:-webkit-min-content;width:-moz-min-content;width:min-content}";

const IntergiroCustomerBalance = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.filterOrders();
  }
  filterOrders() {
    const orders = this.orders
      ? this.orders.filter(o => o.payment.type == "customer" || o.payment.type == "card" ? o.payment.charge == "balance" : false)
      : undefined;
    this.ordersFiltered = orders;
  }
  render() {
    return [
      index.h("section", null, index.h("main", null, index.h("ig-schedule", { schedule: this.customer.schedule }), this.customer.limit ? index.h("ig-customer-limit", { customer: this.customer }) : []), index.h("ig-future-due-dates", { dates: index$1.Schedule.calculateDueDates(this.customer.schedule, 4) })),
      index.h("section", null, this.customer.balance.length > 0 ? index.h("ig-items-list", { items: this.customer.balance }) : [], this.ordersFiltered && this.ordersFiltered.length > 0 ? (index.h("ig-orders-table", { display: true, orders: this.ordersFiltered })) : ([])),
    ];
  }
  static get watchers() { return {
    "orders": ["filterOrders"]
  }; }
};
IntergiroCustomerBalance.style = styleCss$5;

const sv$4 = {
  Name: "Namn",
  Type: "Typ",
  Number: "Nummer",
  "Identity number": "Personnummer",
  Email: "E-post",
  "Phone number": "Telefonnummer",
  Address: "Adress",
};

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

const styleCss$4 = ".sc-ig-customer-contact-h{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-pack:justify;justify-content:space-between}[hidden].sc-ig-customer-contact-h{display:none}.sc-ig-customer-contact-h>section.sc-ig-customer-contact{width:50%;min-width:17em;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}.sc-ig-customer-contact-h>section.sc-ig-customer-contact>label.sc-ig-customer-contact{font-weight:bold}.sc-ig-customer-contact-h>section.sc-ig-customer-contact>ig-display-edit.sc-ig-customer-contact,.sc-ig-customer-contact-h>section.sc-ig-customer-contact>ig-email-addresses.sc-ig-customer-contact,.sc-ig-customer-contact-h>section.sc-ig-customer-contact>label.sc-ig-customer-contact,.sc-ig-customer-contact-h>section.sc-ig-customer-contact>ig-phone-numbers.sc-ig-customer-contact,.sc-ig-customer-contact-h>section.sc-ig-customer-contact>ig-addresses.sc-ig-customer-contact{padding-top:1em}.sc-ig-customer-contact-h>section.sc-ig-customer-contact>*.sc-ig-customer-contact:not(label){min-height:7em;max-width:14em}.sc-ig-customer-contact-h>section.sc-ig-customer-contact>label.sc-ig-customer-contact{padding-top:1em;margin-bottom:0.5em}";

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

const sv$3 = {
  "Deleting payment method...": "Raderar betalningsmetod...",
  "Updating payment methods...": "Uppdaterar betalningsmetoder...",
  "Failed to delete payment method.": "Kunde inte radera betalningsmetod.",
  "Failed to update payment methods.": "Kunde inte uppdatera betalningsmetoder.",
  "Payment method was deleted.": "Betalningsmetod raderades.",
  "Updated payment methods.": "Betalningsmetod uppdaterades.",
};

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

const styleCss$3 = "[hidden].sc-ig-customer-method-h{display:none}.sc-ig-customer-method-h{display:-ms-flexbox;display:flex;padding:1em;padding-left:4.5em}";

const IntergiroCustomerMethod = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.reorder = index.createEvent(this, "reorder", 7);
    this.notice = index.createEvent(this, "notice", 7);
    this.updateCustomers = index.createEvent(this, "updateCustomers", 7);
  }
  componentWillLoad() {
    this.t = create$3(this.element);
  }
  async onUpdate(e, event) {
    this.notice.emit(Notice.Notice.execute(this.t(event == "delete" ? "Deleting payment method..." : "Updating payment methods..."), async () => {
      let result;
      const response = await this.client.customer.setMethods(e.detail, this.customer.id);
      if (unknown.Error.is(response))
        result = [
          false,
          this.t(event == "delete" ? "Failed to delete payment method." : "Failed to update payment methods."),
        ];
      else {
        result = [true, this.t(event == "delete" ? "Payment method was deleted." : "Updated payment methods.")];
        const customers = await this.client.customer.list();
        this.updateCustomers.emit(customers);
      }
      return result;
    }));
  }
  render() {
    return (index.h("ig-payment-methods", { onUpdate: (e) => this.onUpdate(e, "update"), onDelete: (e) => this.onUpdate(e, "delete"), deletable: true, methods: this.customer.method, mode: "table" }));
  }
  get element() { return index.getElement(this); }
};
IntergiroCustomerMethod.style = styleCss$3;

const sv$2 = {
  "Cancelling subscription...": "Avbryter prenumerationen ...",
  "Subscription was cancelled.": "Prenumerationen avbröts.",
  "Failed to cancel subscription.": "Misslyckades med att avbryta prenumerationen.",
  "Updating subscription...": "Uppdaterar prenummeration.",
  "Subscription was updated.": "Prenumerationen uppdaterades.",
  "Failed to update subscription.": "Misslyckades med att uppdatera prenumerationen.",
  "End date": "Slutdatum",
  "Start date": "Startdatum",
  "Cancel subscription": "Avbryt prenumeration",
  ongoing: "pågående",
  Start: "Påbörjar",
  End: "Upphör",
};

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

const styleCss$2 = ".sc-ig-subscription-details-h{display:table-row}.sc-ig-subscription-details-h>td.sc-ig-subscription-details{border-top:solid 1px rgb(var(--smoothly-medium-shade));border-bottom:solid 1px rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));padding-top:0.5em}ig-future-due-dates.sc-ig-subscription-details{width:30%;padding:0.5em;margin:auto}ig-schedule.sc-ig-subscription-details{padding:1em;padding-left:4.5em}ig-items-list.sc-ig-subscription-details{padding:0.5em;margin:auto;width:50%}ig-items-list.number.sc-ig-subscription-details{width:15%}ig-display-edit.sc-ig-subscription-details{margin-left:4.5em;margin-bottom:1em;width:10em}.sc-ig-subscription-details-h>td.sc-ig-subscription-details>section.sc-ig-subscription-details{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:justify;justify-content:space-between}.sc-ig-subscription-details-h>td.sc-ig-subscription-details>section.sc-ig-subscription-details>smoothly-icon.sc-ig-subscription-details{cursor:pointer;margin-right:1em;margin-top:-0.5em}label.sc-ig-subscription-details{font-weight:bold;margin-left:4.5em}";

const IntergiroSubscriptionDetails = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.notice = index.createEvent(this, "notice", 7);
    this.opened = "";
  }
  componentWillLoad() {
    this.t = create$2(this.element);
  }
  cancel() {
    this.notice.emit(Notice.Notice.execute(this.t("Cancelling subscription..."), async () => {
      const response = await index$1.Connection.delete(`customer/${this.customer.id}/subscription/${this.subscription.id}`);
      return !unknown.Error.is(response)
        ? [true, this.t("Subscription was cancelled.")]
        : [false, this.t("Failed to cancel subscription.")];
    }));
  }
  update(value, property) {
    const update = { [property]: value };
    this.subscription = Object.assign(Object.assign({}, this.subscription), update);
    this.notice.emit(Notice.Notice.execute(this.t("Updating subscription..."), async () => {
      const response = await index$1.Connection.put(`customer/${this.customer.id}/subscription/${this.subscription.id}`, this.subscription);
      return !unknown.Error.is(response)
        ? [true, this.t("Subscription was updated.")]
        : [false, this.t("Failed to update subscription.")];
    }));
  }
  render() {
    var _a;
    let result;
    switch (this.opened) {
      case "number":
        result = (index.h("ig-number-details", { number: this.subscription.number, identifier: this.subscription.id, onNumberUpdated: (e) => this.update(e.detail, "number"), name: "subscription" }));
        break;
      case "amount":
        result = (index.h("ig-items-list", { onChanged: (e) => this.update(e.detail, "items"), editable: true, class: typeof this.subscription.items == "number" ? "number" : "", items: this.subscription.items, currency: this.subscription.currency }));
        break;
      case "schedule":
        result = index.h("ig-schedule", { schedule: this.subscription.schedule });
        break;
      case "end":
        result = [
          index.h("section", null, index.h("ig-display-edit", { deletable: false, label: this.t("End"), name: this.t("End date"), onChanged: (e) => this.update(e.detail, "end"), value: (_a = this.subscription.end) !== null && _a !== void 0 ? _a : this.t("ongoing") }), index.h("smoothly-icon", { onClick: () => this.cancel(), name: "trash", color: "default", fill: "solid", toolTip: this.t("Cancel subscription") })),
        ];
        break;
      case "start":
        result = [
          index.h("ig-display-edit", { deletable: false, label: this.t("Start"), name: this.t("Start date"), onChanged: (e) => this.update(e.detail, "start"), value: this.subscription.start }),
        ];
        break;
      case "due":
        result = (index.h("ig-future-due-dates", { dates: index$1.Schedule.calculateDueDates(this.subscription.schedule, 5, this.subscription.start, this.subscription.end) }));
        break;
      default:
        return "";
    }
    return index.h("td", { colSpan: 8 }, result);
  }
  get element() { return index.getElement(this); }
};
IntergiroSubscriptionDetails.style = styleCss$2;

const sv$1 = {
  Number: "Nummer",
  Amount: "Summa",
  Schedule: "Schema",
  Start: "Påbörjar",
  End: "Upphör",
  Due: "Nästa betalning",
  "There are no subscriptions to display.": "Det finns inga prenummerationer att visa.",
};

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

const styleCss$1 = ".sc-ig-subscription-table-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-ig-subscription-table-h{display:none}.sc-ig-subscription-table-h>p.sc-ig-subscription-table{padding-left:1em}.sc-ig-subscription-table-h>table.sc-ig-subscription-table{width:100%}.sc-ig-subscription-table-h>table.sc-ig-subscription-table>thead.sc-ig-subscription-table>tr.sc-ig-subscription-table{display:table-row;font-weight:bold;height:2em}.sc-ig-subscription-table-h>table.sc-ig-subscription-table>thead.sc-ig-subscription-table>tr.sc-ig-subscription-table>*.sc-ig-subscription-table{display:table-cell;padding-right:0.5em;padding-left:0.3em;vertical-align:middle;position:-webkit-sticky;position:sticky;top:1.55cm;z-index:1;text-align:left}.sc-ig-subscription-table-h>table.sc-ig-subscription-table>td.sc-ig-subscription-table{text-align:center}";

const IntergiroSubscriptionTable = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.opened = {};
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    if (e.detail["id"] && opened[e.detail.id] == e.detail.column)
      delete opened[e.detail.id];
    else
      opened[e.detail.id] = e.detail.column;
    this.opened = opened;
  }
  render() {
    return [
      this.subscriptions ? ([
        index.h("table", null, index.h("thead", null, index.h("tr", null, index.h("th", { color: "light" }, this.t("Number")), index.h("th", { color: "light" }, this.t("Amount")), index.h("th", { color: "light" }, this.t("Schedule")), index.h("th", { color: "light" }, this.t("Start")), index.h("th", { color: "light" }, this.t("End")), index.h("th", { color: "light" }, this.t("Due")))), this.subscriptions.map(s => {
          var _a;
          return [
            index.h("ig-subscription-table-row", { opened: this.opened[s.id], subscription: s }),
            index.h("ig-subscription-details", { opened: (_a = this.opened[s.id]) !== null && _a !== void 0 ? _a : "", subscription: s, customer: this.customer }),
          ];
        })),
      ]) : (index.h("p", null, this.t("There are no subscriptions to display."))),
    ];
  }
  get element() { return index.getElement(this); }
};
IntergiroSubscriptionTable.style = styleCss$1;

const sv = {
  daily: "daglig",
  weekly: "veckovis",
  monthly: "månadsvis",
  quarterly: "kvartalsvis",
  yearly: "årlig",
  ongoing: "pågående",
};

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

const styleCss = ".sc-ig-subscription-table-row-h{display:table-row}[hidden].sc-ig-subscription-table-row-h{display:none}.sc-ig-subscription-table-row-h:hover{border-top:1px solid rgb(var(--smoothly-medium-color));border-bottom:1px solid rgb(var(--smoothly-medium-color));-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow)}.sc-ig-subscription-table-row-h>td.sc-ig-subscription-table-row>.openable.sc-ig-subscription-table-row{padding:0.5em 0.3em;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:3em;display:inline-block}.opened.sc-ig-subscription-table-row,.openable.sc-ig-subscription-table-row{cursor:pointer}.opened.sc-ig-subscription-table-row{border:solid 1px rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));border-bottom:3px solid rgb(var(--smoothly-dark-shade));border-radius:0 0 2px 2px;margin-bottom:-2px}.sc-ig-subscription-table-row-h>td.sc-ig-subscription-table-row:first-of-type>.opened.sc-ig-subscription-table-row{border-left:none}";

const IntergiroSubscriptionTableRow = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.columnClicked = index.createEvent(this, "columnClicked", 7);
    this.opened = "";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  handleColumnClick(column) {
    this.opened = column;
    this.columnClicked.emit({ id: this.subscription.id, column });
  }
  render() {
    var _a;
    return [
      index.h("td", null, index.h("section", { class: "openable" + (this.opened == "number" ? " opened" : ""), onClick: () => this.handleColumnClick("number") }, (_a = this.subscription.number) !== null && _a !== void 0 ? _a : this.subscription.id)),
      index.h("td", null, index.h("smoothly-display-amount", { class: "openable" + (this.opened == "amount" ? " opened" : ""), onClick: () => this.handleColumnClick("amount"), amount: index$1.Item.amount(this.subscription.items), currency: this.subscription.currency })),
      index.h("td", null, index.h("section", { class: "openable" + (this.opened == "schedule" ? " opened" : ""), onClick: () => this.handleColumnClick("schedule") }, this.t(typeof this.subscription.schedule == "object"
        ? this.subscription.schedule.frequency
        : this.subscription.schedule))),
      index.h("td", null, index.h("section", { class: "openable" + (this.opened == "start" ? " opened" : ""), onClick: () => this.handleColumnClick("start") }, this.subscription.start)),
      index.h("td", null, index.h("section", { class: "openable" + (this.opened == "end" ? " opened" : ""), onClick: () => this.handleColumnClick("end") }, this.subscription.end ? this.subscription.end : this.t("ongoing"))),
      index.h("td", null, index.h("section", { class: "openable" + (this.opened == "due" ? " opened" : ""), onClick: () => this.handleColumnClick("due") }, index$1.Schedule.next(this.subscription.schedule, this.subscription.start))),
    ];
  }
  get element() { return index.getElement(this); }
};
IntergiroSubscriptionTableRow.style = styleCss;

exports.ig_customer_balance = IntergiroCustomerBalance;
exports.ig_customer_contact = IntergiroCustomerContact;
exports.ig_customer_method = IntergiroCustomerMethod;
exports.ig_subscription_details = IntergiroSubscriptionDetails;
exports.ig_subscription_table = IntergiroSubscriptionTable;
exports.ig_subscription_table_row = IntergiroSubscriptionTableRow;
