'use strict';

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

const index$1 = require('./index-df541290.js');
const index$4 = require('./index-0a8af373.js');
require('./index-5e992066.js');
const index$3 = require('./index-c12b8888.js');
const index = require('./index-b7493032.js');
const index$2 = require('./index-3e5f1089.js');
require('./App-1e388484.js');
require('./index-0b6f1dd9.js');
require('./_commonjsHelpers-10109b76.js');
require('./index-fe328b96.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 index.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) {
    index$1.registerInstance(this, hostRef);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.opened = "";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  cancel() {
    this.notice.emit(index$2.Notice.execute(this.t("Cancelling subscription..."), async () => {
      const response = await index$3.Connection.delete(`customer/${this.customer.id}/subscription/${this.subscription.id}`);
      return !index$4.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(index$2.Notice.execute(this.t("Updating subscription..."), async () => {
      const response = await index$3.Connection.put(`customer/${this.customer.id}/subscription/${this.subscription.id}`, this.subscription);
      return !index$4.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$1.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$1.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$1.h("ig-schedule", { schedule: this.subscription.schedule });
        break;
      case "end":
        result = [
          index$1.h("label", null, this.t("End")),
          index$1.h("section", null, index$1.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") }), index$1.h("smoothly-icon", { onClick: () => this.cancel(), name: "trash", color: "default", fill: "solid", toolTip: this.t("Cancel subscription") })),
        ];
        break;
      case "start":
        result = [
          index$1.h("label", null, this.t("Start")),
          index$1.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 = (index$1.h("ig-future-due-dates", { dates: index$3.Schedule.calculateDueDates(this.subscription.schedule, 5, this.subscription.start, this.subscription.end) }));
        break;
      default:
        return "";
    }
    return index$1.h("td", { colSpan: 8 }, result);
  }
  get element() { return index$1.getElement(this); }
};
IntergiroSubscriptionDetails.style = styleCss;

exports.ig_subscription_details = IntergiroSubscriptionDetails;
