'use strict';

const index$1 = require('./index-140bcbcd.js');
const index$2 = require('./index-3b10efe6.js');
const model = require('./model-7ac3bb05.js');
const PaymentDetails = require('./PaymentDetails-ea590e93.js');
const index = require('./index-d3079b93.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 index.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) {
    index$1.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 => (index$1.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 ? (index$1.h("p", null, t("The selected invoice choice costs $0.", index$2.dist.format(this.selected.fee, "price", this.currency)))) : ([]),
    ];
  }
  get element() { return index$1.getElement(this); }
};
PaymentDetails.paymentDetailsAdd("invoice", (option) => {
  const result = {
    type: "invoice",
    name: "Invoice",
    brand: option.service,
    component: (index$1.h("ig-invoice-details", { option: model.PaymentOptionInvoiceIs(option) ? option : undefined, currency: option.currency, ref: (e) => (result.element = e) })),
  };
  return result;
});
IntergiroInvoiceDetails.style = styleCss;

exports.IntergiroInvoiceDetails = IntergiroInvoiceDetails;
