'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./App-1647a125.js');
require('./_commonjsHelpers-937cd5b3.js');
const index$2 = require('./index-1a9e1965.js');
require('./index-451ca284.js');
const index$3 = require('./index-ab186017.js');
const index = require('./index-36cf3884.js');
const index$4 = require('./index-061d0ccd.js');

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

const styleCss = "[hidden].sc-payfunc-account-method-h{display:none}.sc-payfunc-account-method-h{display:flex;padding:1em;padding-left:4.5em}";

const PayfuncAccountMethod = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.reorder = index$1.createEvent(this, "reorder", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.updateAccounts = index$1.createEvent(this, "updateAccounts", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async onUpdate(e, event) {
    this.notice.emit(index$2.Notice.execute(this.t(event == "delete" ? "Deleting payment method..." : "Updating payment methods..."), async () => {
      let result;
      const response = await index$3.Connection.put(`account/${this.account.id}/methods`, e.detail);
      if (index$4.dist.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 accounts = await index$3.Connection.get(`account/`);
        this.updateAccounts.emit(accounts);
      }
      return result;
    }));
  }
  render() {
    return (index$1.h("payfunc-payment-methods", { onUpdate: (e) => this.onUpdate(e, "update"), onDelete: (e) => this.onUpdate(e, "delete"), deletable: true, methods: this.account.method, mode: "table" }));
  }
  get element() { return index$1.getElement(this); }
};
PayfuncAccountMethod.style = styleCss;

exports.payfunc_account_method = PayfuncAccountMethod;
