import { r as registerInstance, h, g as getElement } from './index-08b73e9e.js';
import { P as PaymentOptionInstallmentIs } from './model-23a8b6a7.js';
import { p as paymentDetailsAdd } from './PaymentDetails-c0a6f6c4.js';
import { d as dist } from './index-a0a71287.js';

const sv = {
  "$0 $1 / month in $2 months": "$0 $1 / månad i $2 månader",
  "$0 $1 in initial fee and $2 $3 reccuring. Total cost is $4 $5 and the effective rate is $6%": "$0 $1 i uppläggningsavgift och $2 $3 i månadsavgift. Total kostnad är $4 $5 och den effektiva räntan är $6%",
};

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

const styleCss = ".sc-ig-installment-details-h{display:block;margin:1em}[hidden].sc-ig-installment-details-h{display:none}smoothly-radio.sc-ig-installment-details{text-align:center;border-left:solid 1px rgb(var(--smoothly-medium-color));border-right:solid 1px rgb(var(--smoothly-medium-color))}smoothly-radio.sc-ig-installment-details:first-of-type{border-top:solid 1px rgb(var(--smoothly-medium-color));border-top-left-radius:4px;border-top-right-radius:4px}smoothly-radio.sc-ig-installment-details:last-of-type{border-bottom:solid 1px rgb(var(--smoothly-medium-color));border-bottom-left-radius:4px;border-bottom-right-radius:4px}p.sc-ig-installment-details{color:rgb(var(--smoothly-medium-color))}";

const IntergiroInstallmentDetails = 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,
          plan: this.selected,
          verify: { mode: "iframe", parent: window.location.origin },
        };
      }
    }
    return result;
  }
  onSelected(e) {
    if (typeof e.detail == "object" && typeof e.detail.value == "string" && this.option)
      this.selected = this.option.plans.find(plan => plan.length.toString() == e.detail.value);
  }
  limit(value, decimals) {
    const factor = decimals == 0 ? 1 : 100;
    return Math.round((value + Number.EPSILON) * factor) / factor;
  }
  render() {
    const t = this.t;
    if (!this.selected && Array.isArray(this.option) && this.option.length > 0)
      this.selected = this.option.plans[0];
    const rate = this.selected && this.selected.effectiveRate ? this.selected.effectiveRate * 100 : "-";
    return [
      this.option
        ? this.option.plans.map(plan => (h("smoothly-radio", { checked: this.selected == plan, name: "invoice-plan", value: plan.length.toString() }, t("$0 $1 / month in $2 months", this.currency, this.limit(plan.amount, 0), plan.length))))
        : [],
      this.selected ? (h("p", null, t("$0 $1 in initial fee and $2 $3 reccuring. Total cost is $4 $5 and the effective rate is $6%", this.currency, this.selected.fees.initial, this.currency, this.selected.fees.reaccuring, this.currency, this.limit(this.selected.total, 0), typeof rate == "number" ? this.limit(rate, 2).toString() : rate))) : ([]),
    ];
  }
  get element() { return getElement(this); }
};
paymentDetailsAdd("installment", option => {
  const result = {
    type: "installment",
    name: "Installment Plan",
    brand: option.service,
    component: (h("ig-installment-details", { ref: e => (result.element = e), option: PaymentOptionInstallmentIs(option) ? option : undefined, currency: option.currency })),
  };
  return result;
});
IntergiroInstallmentDetails.style = styleCss;

export { IntergiroInstallmentDetails as I };
