import { r as registerInstance, c as createEvent, h, g as getElement } from './index-08b73e9e.js';
import { d as dist$1 } from './index-8ba22472.js';
import { d as dist } from './index-a0a71287.js';
import './_commonjsHelpers-9943807e.js';

const sv = {
  "Top up balance": "Fyll på saldo",
  Cancel: "Avbryt",
  Amount: "Summa",
  "Equalize balance to zero.": "Justera saldot till noll.",
};

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

const styleCss = ".sc-ig-balance-add-h{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;min-width:15em}[hidden].sc-ig-balance-add-h{display:none}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add{display:-ms-flexbox;display:flex;width:100%;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center;max-width:15em}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add:last-of-type{margin-top:.5em}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add>smoothly-display.sc-ig-balance-add{font-size:xx-large}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add>smoothly-icon.sc-ig-balance-add{cursor:pointer;padding-left:1em}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add>smoothly-input.sc-ig-balance-add{border:1px solid rgb(var(--smoothly-medium-color))}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add>smoothly-submit.sc-ig-balance-add smoothly-icon.sc-ig-balance-add{margin-right:-.4em}.sc-ig-balance-add-h>form.sc-ig-balance-add>section.sc-ig-balance-add>smoothly-trigger.sc-ig-balance-add{padding-left:1em;margin-right:-1em}smoothly-submit.sc-ig-balance-add,smoothly-trigger.sc-ig-balance-add{border:none}";

const IntergiroBalanceAdd = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.addFunds = createEvent(this, "addFunds", 7);
    this.opened = false;
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async submit(event) {
    const amount = dist$1.parse(event.detail.price, "price", this.customer.currency);
    const order = {
      number: "Manual balance charge.",
      items: {
        name: "Manual balance charge.",
        price: amount,
      },
      currency: this.customer.currency,
      payment: { type: "customer", charge: "balance" },
      customer: this.customer.id,
    };
    this.addFunds.emit(order);
    this.opened = false;
    const form = document.getElementsByTagName("form")[0];
    form.reset();
  }
  render() {
    return [
      h("form", null, h("section", null, h("smoothly-display", { type: "price", value: this.customer.total, currency: this.customer.currency }), this.customer.balance.length > 0 && this.customer.total < 0 ? (h("smoothly-trigger", { style: { display: this.opened ? "" : "none" } }, h("smoothly-icon", { toolTip: this.t("Equalize balance to zero."), name: "arrow-up-circle-outline", size: "small", color: "medium", fill: "clear" }))) : ([]), h("smoothly-icon", { toolTip: this.opened ? this.t("Cancel") : this.t("Top up balance"), color: this.opened ? "medium" : "default", fill: this.opened ? "clear" : "solid", name: this.opened ? "close" : "add-circle", onClick: () => (this.opened = !this.opened) })), h("section", { style: { display: this.opened ? "" : "none" } }, h("smoothly-input", { name: "price", type: "price", currency: this.customer.currency }, this.t("Amount")), h("smoothly-submit", { prevent: true, onSubmit: (event) => this.submit(event) }, h("smoothly-icon", { toolTip: this.t("Top up balance"), class: "add", color: "success", fill: "clear", name: "add-circle" })))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroBalanceAdd.style = styleCss;

export { IntergiroBalanceAdd as ig_balance_add };
