import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { d as dist$1 } from './index-046ba252.js';
import { d as dist } from './index-63517df5.js';
import './_commonjsHelpers-8fe71198.js';

const sv = {
  create: "skapad",
  order: "beställa",
  cancel: "avbryt",
  charge: "debitera",
  pay: "betala",
  refund: "återbetala",
  deny: "neka",
  pending: "väntande",
  defer: "skicka",
  Quantity: "Antal",
  Amount: "Summa",
};

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

const styleCss = ".sc-ig-status-change-h{display:inline-block}[hidden].sc-ig-status-change-h{display:none}button.sc-ig-status-change{display:block;padding:.2em .3em;border:none;font-size:inherit}button.sc-ig-status-change:focus{outline:unset}content.sc-ig-status-change>*.sc-ig-status-change{text-align:center;height:2.5em;min-width:2.5em}content.sc-ig-status-change>.sc-ig-status-change:first-child{border-top-left-radius:5px;border-bottom-left-radius:5px}content.sc-ig-status-change>.sc-ig-status-change:last-child{border-top-right-radius:5px;border-bottom-right-radius:5px}#charge.sc-ig-status-change{background-color:rgb(var(--smoothly-success-color))}#cancel.sc-ig-status-change{background-color:rgb(var(--smoothly-danger-color))}#refund.sc-ig-status-change{background-color:rgb(var(--smoothly-danger-color))}#synchronize.sc-ig-status-change{background-color:rgb(var(--smoothly-dark-color))}#amount.sc-ig-status-change{min-width:6em;padding:0;background-color:rgb(var(--smoothly-dark-color))}content.sc-ig-status-change{display:-ms-flexbox;display:flex}.sc-ig-status-change-h>smoothly-popup.sc-ig-status-change{display:inline}";

const IntergiroStatusChange = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.changeStatus = createEvent(this, "changeStatus", 7);
  }
  get mode() {
    return this.amount && dist$1.Currency.is(this.currency) ? "amount" : "quantity";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  emitChangeStatus(type) {
    var _a, _b, _c;
    const value = !((_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.value)
      ? 1
      : this.mode == "quantity"
        ? Number.parseInt((_b = this.inputElement) === null || _b === void 0 ? void 0 : _b.value)
        : Number.parseFloat((_c = this.inputElement) === null || _c === void 0 ? void 0 : _c.value);
    this.changeStatus.emit({ type, items: this.mode == "quantity" ? { quantity: value } : value });
    if (this.popupElement)
      this.popupElement.visible = false;
  }
  render() {
    var _a;
    const t = this.t;
    let events;
    switch (this.status) {
      case "created":
      case "deferred":
      case "pending":
        events = [];
        break;
      case "ordered":
        events = [];
        break;
      case "charged":
      case "paid":
        events = ["refund"];
        break;
      default:
      case "denied":
      case "cancelled":
      case "refunded":
      case "synchronized":
        events = [];
        break;
    }
    return [
      events.length != 0 ? (h("smoothly-popup", { ref: (e) => (this.popupElement = e) }, h("main", null, h("ig-status", { quantity: this.quantity, unit: this.unit, status: this.status })), h("content", { slot: "popup" }, this.quantity == 1 ? ("") : this.mode == "quantity" ? (h("smoothly-select", { color: "dark", identifier: "quantity", ref: (e) => (this.inputElement = e) }, generateOptions((_a = this.quantity) !== null && _a !== void 0 ? _a : 1).map(c => (c = this.quantity ? (h("option", { value: c }, c)) : (h("option", { value: c, selected: true }, c)))))) : (h("smoothly-input", { type: "price", name: "amount", id: "amount", value: this.amount, ref: (e) => (this.inputElement = e) }, t("Amount"), " (", this.currency, ")")), events.map(event => (h("button", { onClick: () => this.emitChangeStatus(event), id: event, name: event }, h("smoothly-icon", { toolTip: t(event), name: event == "cancel"
          ? "close"
          : event == "charge"
            ? "checkmark"
            : event == "refund"
              ? "arrow-undo"
              : "", color: event == "cancel"
          ? "danger"
          : event == "charge"
            ? "success"
            : event == "refund"
              ? "danger"
              : "medium" }))))))) : (h("div", null, h("span", null, h("ig-status", { quantity: this.quantity, unit: this.unit, status: this.status })))),
    ];
  }
  get element() { return getElement(this); }
};
function generateOptions(count) {
  const result = [];
  for (let c = 1; c <= count; c++)
    result.push(c);
  return result;
}
IntergiroStatusChange.style = styleCss;

export { IntergiroStatusChange as ig_status_change };
