'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./App-1647a125.js');
require('./_commonjsHelpers-937cd5b3.js');
const index$4 = require('./index-1a9e1965.js');
require('./index-451ca284.js');
const index$2 = require('./index-ab186017.js');
const index = require('./index-36cf3884.js');
const index$3 = require('./index-061d0ccd.js');

const sv = {
  VAT: "moms",
};

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

const styleCss = ".sc-payfunc-order-items-quantity-h{display:table-row;width:100%}[hidden].sc-payfunc-order-items-quantity-h{display:none}.sc-payfunc-order-items-quantity-h>td.sc-payfunc-order-items-quantity{vertical-align:middle;width:fit-content;padding-right:auto}.sc-payfunc-order-items-quantity-h>td.sc-payfunc-order-items-quantity>div.sc-payfunc-order-items-quantity{padding-right:auto;padding-left:0.15em}.sc-payfunc-order-items-quantity-h>td.sc-payfunc-order-items-quantity>div.sc-payfunc-order-items-quantity>payfunc-status-change.sc-payfunc-order-items-quantity{margin-right:.3em;padding-right:0.5em;flex-shrink:5;max-width:20em;width:100%;align-content:stretch}.sc-payfunc-order-items-quantity-h>td.sc-payfunc-order-items-quantity>div.status.sc-payfunc-order-items-quantity{display:flex;align-content:stretch;flex-wrap:nowrap}";

const PayfuncOrderItemsQuantity = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.quantityStatus = index$1.createEvent(this, "quantityStatus", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async emitChangeStatus(e) {
    const response = await index$2.Connection.post(`order/${this.order}/event`, {
      type: e.detail.type,
      items: typeof e.detail.items == "number" ? e.detail.items : Object.assign(Object.assign(Object.assign({}, this.item), e.detail.items), { status: undefined }),
    });
    this.notice.emit(index$3.dist.Error.is(response)
      ? index$4.Notice.failed(this.t("Failed to change status."))
      : index$4.Notice.succeded(this.t("Status changed.")));
  }
  sendQuantityStatus(status) {
    this.quantityStatus.emit(status);
  }
  render() {
    const t = this.t;
    this.item.quantity ? this.sendQuantityStatus(true) : "";
    return [
      this.item
        ? [
          index$1.h("td", null, index$1.h("div", null, this.item.quantity ? this.item.quantity : this.item.unit ? 1 : "", this.item.unit)),
          index$1.h("td", null, index$1.h("div", null, this.item.name)),
          index$1.h("td", null, index$1.h("div", null, this.item.quantity
            ? t("@") + (index$2.Item.amount(this.item) / (this.item.quantity ? this.item.quantity : 1)).toFixed(2)
            : "")),
          index$1.h("td", null, index$1.h("div", null, this.item.vat ? this.item.vat.toFixed(2) : "")),
          index$1.h("td", null, index$1.h("div", null, index$2.Item.amount(this.item).toFixed(2), " ", this.currency)),
          index$1.h("td", null, index$1.h("div", { class: "status" }, ["ordered", "charged", "refunded", "cancelled"]
            .map((status) => { var _a, _b; return [status, (_b = (_a = this.item.status) === null || _a === void 0 ? void 0 : _a.filter(s => s == status).length) !== null && _b !== void 0 ? _b : 0]; })
            .filter(argument => argument[1])
            .map(argument => this.item.quantity ? (index$1.h("payfunc-status-change", { status: argument[0], quantity: argument[1], unit: this.item.unit, onChangeStatus: (e) => this.emitChangeStatus(e) })) : (index$1.h("payfunc-status-change", { status: argument[0], amount: index$2.Item.amount(this.item), currency: this.currency, onChangeStatus: (e) => this.emitChangeStatus(e) }))))),
        ]
        : "",
    ];
  }
  get element() { return index$1.getElement(this); }
};
PayfuncOrderItemsQuantity.style = styleCss;

exports.payfunc_order_items_quantity = PayfuncOrderItemsQuantity;
