'use strict';

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

const index$1 = require('./index-df541290.js');
const index$4 = require('./index-0a8af373.js');
require('./index-5e992066.js');
const index$3 = require('./index-c12b8888.js');
const index = require('./index-b7493032.js');
const index$2 = require('./index-3e5f1089.js');
require('./App-1e388484.js');
require('./index-0b6f1dd9.js');
require('./_commonjsHelpers-10109b76.js');
require('./index-fe328b96.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-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) {
    index$1.registerInstance(this, hostRef);
    this.reorder = index$1.createEvent(this, "reorder", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.updateCustomers = index$1.createEvent(this, "updateCustomers", 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(`customer/${this.customer.id}/methods`, e.detail);
      if (index$4.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 index$3.Connection.get(`customer/`);
        this.updateCustomers.emit(customers);
      }
      return result;
    }));
  }
  render() {
    return (index$1.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 index$1.getElement(this); }
};
IntergiroCustomerMethod.style = styleCss;

exports.ig_customer_method = IntergiroCustomerMethod;
