import { r as registerInstance, h, g as getElement } from './index-08b73e9e.js';
import { d as dist$1 } from './index-8ba22472.js';
import { a as PaymentOptionInvoiceIs } from './model-23a8b6a7.js';
import { p as paymentDetailsAdd } from './PaymentDetails-c0a6f6c4.js';
import { d as dist } from './index-a0a71287.js';

const sv = {
  "The selected invoice choice costs $0.": "Avgiften för den valda fakturan är $0.",
  "Due within $0 days": "Betalas inom $0 dagar.",
  "Due before $0.": "Betalas före $0",
};

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

const styleCss = ".sc-ig-invoice-details-h>p.sc-ig-invoice-details{padding-left:0.4em;padding-right:0.4em}smoothly-radio.sc-ig-invoice-details{width:calc(100% - 2px)}";

const IntergiroInvoiceDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  async componentWillLoad() {
    this.t = create(this.element);
  }
  async getPayment(order, apiKey) {
    let result;
    if (this.option && this.selected) {
      if (!order.items || !order.currency || !order.customer)
        console.log("Error: must have items, currency, customer");
      else {
        result = {
          type: this.option.type,
          terms: this.selected,
          verify: { mode: "iframe", parent: window.location.origin },
        };
      }
    }
    return result;
  }
  render() {
    const t = this.t;
    if (!this.selected && this.option)
      this.selected = this.option.terms[0];
    return [
      this.option
        ? this.option.terms.map(term => (h("smoothly-radio", { onSmoothlySelected: () => (this.selected = term), checked: this.selected == term, name: "invoice-terms", value: term.due.toString() }, typeof term.due == "number" ? t("Due within $0 days", term.due) : t("Due before $0.", term.due))))
        : [],
      this.selected ? (h("p", null, t("The selected invoice choice costs $0.", dist$1.format(this.selected.fee, "price", this.currency)))) : ([]),
    ];
  }
  get element() { return getElement(this); }
};
paymentDetailsAdd("invoice", (option) => {
  const result = {
    type: "invoice",
    name: "Invoice",
    brand: option.service,
    component: (h("ig-invoice-details", { option: PaymentOptionInvoiceIs(option) ? option : undefined, currency: option.currency, ref: (e) => (result.element = e) })),
  };
  return result;
});
IntergiroInvoiceDetails.style = styleCss;

export { IntergiroInvoiceDetails as I };
