import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { E as Error } from './index-38089f62.js';
import './index-cd3eb450.js';
import { C as Connection, c as Schedule } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import { N as Notice } from './index-f068b00b.js';
import './App-15d9fce3.js';
import './index-b6cf748e.js';
import './_commonjsHelpers-8fe71198.js';
import './index-265fba1f.js';

const sv = {
  "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(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = ".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:.5em}ig-future-due-dates.sc-ig-subscription-details{width:30%;padding:.5em;margin:auto}ig-schedule.sc-ig-subscription-details{padding:1em;padding-left:4.5em}ig-items-list.sc-ig-subscription-details{padding:.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:-.5em}label.sc-ig-subscription-details{font-weight:bold;margin-left:4.5em}";

const IntergiroSubscriptionDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
    this.opened = "";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  cancel() {
    this.notice.emit(Notice.execute(this.t("Cancelling subscription..."), async () => {
      const response = await Connection.delete(`customer/${this.customer.id}/subscription/${this.subscription.id}`);
      return !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.execute(this.t("Updating subscription..."), async () => {
      const response = await Connection.put(`customer/${this.customer.id}/subscription/${this.subscription.id}`, this.subscription);
      return !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 = (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 = (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 = h("ig-schedule", { schedule: this.subscription.schedule });
        break;
      case "end":
        result = [
          h("label", null, this.t("End")),
          h("section", null, h("ig-display-edit", { deletable: false, 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") }), h("smoothly-icon", { onClick: () => this.cancel(), name: "trash", color: "default", fill: "solid", toolTip: this.t("Cancel subscription") })),
        ];
        break;
      case "start":
        result = [
          h("label", null, this.t("Start")),
          h("ig-display-edit", { deletable: false, name: this.t("Start date"), onChanged: (e) => this.update(e.detail, "start"), value: this.subscription.start }),
        ];
        break;
      case "due":
        result = (h("ig-future-due-dates", { dates: Schedule.calculateDueDates(this.subscription.schedule, 5, this.subscription.start, this.subscription.end) }));
        break;
      default:
        return "";
    }
    return h("td", { colSpan: 8 }, result);
  }
  get element() { return getElement(this); }
};
IntergiroSubscriptionDetails.style = styleCss;

export { IntergiroSubscriptionDetails as ig_subscription_details };
