'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-0b1e2673.js');
require('./_commonjsHelpers-937cd5b3.js');
const index = require('./index-36cf3884.js');
const index$2 = require('./index-8a61808f.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 index.dist.create({
    sv,
  }, language);
}

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

const PayfuncStatusChange = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.changeStatus = index$1.createEvent(this, "changeStatus", 7);
  }
  get mode() {
    return this.amount && index$2.dist.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 ? (index$1.h("smoothly-popup", { ref: (e) => (this.popupElement = e) }, index$1.h("main", null, index$1.h("payfunc-status", { quantity: this.quantity, unit: this.unit, status: this.status })), index$1.h("content", { slot: "popup" }, this.quantity == 1 ? ("") : this.mode == "quantity" ? (index$1.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 ? (index$1.h("option", { value: c }, c)) : (index$1.h("option", { value: c, selected: true }, c)))))) : (index$1.h("smoothly-input", { type: "price", name: "amount", id: "amount", value: this.amount, ref: (e) => (this.inputElement = e) }, t("Amount"), " (", this.currency, ")")), events.map(event => (index$1.h("button", { onClick: () => this.emitChangeStatus(event), id: event, name: event }, index$1.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" }))))))) : (index$1.h("div", null, index$1.h("span", null, index$1.h("payfunc-status", { quantity: this.quantity, unit: this.unit, status: this.status })))),
    ];
  }
  get element() { return index$1.getElement(this); }
};
function generateOptions(count) {
  const result = [];
  for (let c = 1; c <= count; c++)
    result.push(c);
  return result;
}
PayfuncStatusChange.style = styleCss;

exports.payfunc_status_change = PayfuncStatusChange;
