import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { d as dist } from './index-63517df5.js';
import './_commonjsHelpers-8fe71198.js';

const sv = {
  Scheme: "System",
  "Card number": "Kortnummer",
  Expires: "Giltigt t.o.m.",
  Close: "Stäng",
  "Add method": "Lägg till metod",
  "The customer has no payment method.": "Kunden har ingen betalningsmetod.",
};

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

const styleCss = "[hidden].sc-ig-payment-methods-h{display:none}section.sc-ig-payment-methods{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;font-weight:bold}section.sc-ig-payment-methods>*.sc-ig-payment-methods{width:10em}section.sc-ig-payment-methods>*.sc-ig-payment-methods:nth-of-type(2){width:15em}@media only screen and (min-width: 1000px){smoothly-icon.sc-ig-payment-methods{visibility:hidden}smoothly-reorder.sc-ig-payment-methods{float:left}smoothly-reorder.sc-ig-payment-methods>*.sc-ig-payment-methods{margin-top:10px}ig-payment-method-add.sc-ig-payment-methods{position:relative;display:block;visibility:visible;width:50%;float:right}}@media only screen and (max-width: 1000px){smoothly-icon.sc-ig-payment-methods{visibility:visible;position:fixed;right:5%;cursor:pointer}ig-payment-method-add.sc-ig-payment-methods,#desktop.sc-ig-payment-methods{display:none}ig-payment-method-add.sc-ig-payment-methods,#phone.sc-ig-payment-methods{display:block;width:25rem;max-width:90%;margin:0 auto}.sc-ig-payment-methods-h>smoothly-reorder.sc-ig-payment-methods>*.sc-ig-payment-methods,table.sc-ig-payment-methods{max-width:60%;margin:0 auto;margin-top:10px}}";

const IntergiroPaymentMethods = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.update = createEvent(this, "update", 7);
    this.delete = createEvent(this, "delete", 7);
    this.addable = false;
    this.deletable = false;
    this.mode = "card";
    this.opened = false;
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  renderMethods() {
    this.methods = [...this.methods];
  }
  deleteMethod(index) {
    window.setTimeout(() => {
      this.methods.splice(index, 1);
      this.renderMethods();
      this.delete.emit(this.methods);
    }, 500);
  }
  reorderMethods(event) {
    const fromIndex = event.detail[0];
    const toIndex = event.detail[1];
    const e = this.methods.splice(fromIndex, 1);
    this.methods.splice(toIndex, 0, ...e);
    this.update.emit(this.methods);
  }
  render() {
    return [
      this.addable
        ? [
          h("smoothly-icon", { name: this.opened ? "close-circle" : "add-circle", toolTip: this.opened ? this.t("Close") : this.t("Add method"), size: "large", onClick: () => (this.opened = !this.opened) }),
          h("ig-payment-method-add", { id: this.opened ? "phone" : "desktop", customer: this.customer, "api-key": this.apiKey, onAdd: () => this.renderMethods() }),
        ]
        : null,
      this.mode == "table" &&
        (this.methods.length > 0 ? (h("section", null, h("label", null, this.t("Scheme")), h("label", null, this.t("Card number")), h("label", null, this.t("Expires")))) : (h("p", null, this.t("The customer has no payment method.")))),
      h("smoothly-reorder", { onReorder: (event) => this.reorderMethods(event) }, this.methods.map((method, index) => [
        h("ig-payment-method", { mode: this.mode, method: method, deletable: this.deletable, onDeleteMethod: () => this.deleteMethod(index) }),
      ])),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroPaymentMethods.style = styleCss;

export { IntergiroPaymentMethods as ig_payment_methods };
