import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { E as Error } from './index-38089f62.js';
import './index-cd3eb450.js';
import { C as Connection } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import { N as Notice } from './index-f068b00b.js';
import './App-15d9fce3.js';
import './index-b6cf748e.js';
import './_commonjsHelpers-8fe71198.js';
import './index-265fba1f.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-ig-customer-method-h{display:none}.sc-ig-customer-method-h{display:-ms-flexbox;display:flex;padding:1em;padding-left:4.5em}";

const IntergiroCustomerMethod = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.reorder = createEvent(this, "reorder", 7);
    this.notice = createEvent(this, "notice", 7);
    this.updateCustomers = createEvent(this, "updateCustomers", 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(`customer/${this.customer.id}/methods`, e.detail);
      if (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 customers = await Connection.get(`customer/`);
        this.updateCustomers.emit(customers);
      }
      return result;
    }));
  }
  render() {
    return (h("ig-payment-methods", { onUpdate: (e) => this.onUpdate(e, "update"), onDelete: (e) => this.onUpdate(e, "delete"), deletable: true, methods: this.customer.method, mode: "table" }));
  }
  get element() { return getElement(this); }
};
IntergiroCustomerMethod.style = styleCss;

export { IntergiroCustomerMethod as ig_customer_method };
