import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './App-418c0118.js';
import './_commonjsHelpers-91fffb88.js';
import { N as Notice } from './index-4920b0b3.js';
import './index-66cd4113.js';
import { C as Connection } from './index-df45deab.js';
import { d as dist } from './index-fdd60c34.js';
import { d as dist$1 } from './index-909faba2.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 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) {
    registerInstance(this, hostRef);
    this.reorder = createEvent(this, "reorder", 7);
    this.notice = createEvent(this, "notice", 7);
    this.updateAccounts = createEvent(this, "updateAccounts", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async onUpdate(e, event) {
    this.notice.emit(Notice.execute(this.t(event == "delete" ? "Deleting payment method..." : "Updating payment methods..."), async () => {
      let result;
      const response = await Connection.put(`account/${this.account.id}/methods`, e.detail);
      if (dist$1.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 Connection.get(`account/`);
        this.updateAccounts.emit(accounts);
      }
      return result;
    }));
  }
  render() {
    return (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 getElement(this); }
};
PayfuncAccountMethod.style = styleCss;

export { PayfuncAccountMethod as payfunc_account_method };
