'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./_commonjsHelpers-937cd5b3.js');
const index = require('./index-36cf3884.js');

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

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

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

const PayfuncPaymentMethods = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.update = index$1.createEvent(this, "update", 7);
    this.delete = index$1.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
        ? [
          index$1.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) }),
          index$1.h("payfunc-payment-method-add", { id: this.opened ? "phone" : "desktop", account: this.account, "api-key": this.apiKey, onAdd: () => this.renderMethods() }),
        ]
        : null,
      this.mode == "table" &&
        (this.methods.length > 0 ? (index$1.h("section", null, index$1.h("label", null, this.t("Scheme")), index$1.h("label", null, this.t("Card number")), index$1.h("label", null, this.t("Expires")))) : (index$1.h("p", null, this.t("The account has no payment method.")))),
      index$1.h("smoothly-reorder", { onReorder: (event) => this.reorderMethods(event) }, this.methods.map((method, index) => [
        index$1.h("payfunc-payment-method", { mode: this.mode, method: method, deletable: this.deletable, onDeleteMethod: () => this.deleteMethod(index) }),
      ])),
    ];
  }
  get element() { return index$1.getElement(this); }
};
PayfuncPaymentMethods.style = styleCss;

exports.payfunc_payment_methods = PayfuncPaymentMethods;
