'use strict';

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

const index$1 = require('./index-df541290.js');
const index$3 = require('./index-0a8af373.js');
require('./index-5e992066.js');
const index$2 = require('./index-c12b8888.js');
const index = require('./index-b7493032.js');
const index$4 = require('./index-3e5f1089.js');
require('./App-1e388484.js');
require('./index-0b6f1dd9.js');
require('./_commonjsHelpers-10109b76.js');
require('./index-fe328b96.js');

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

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

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

const IntergirOrderItemsQuantity = 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.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("ig-status-change", { status: argument[0], quantity: argument[1], unit: this.item.unit, onChangeStatus: (e) => this.emitChangeStatus(e) })) : (index$1.h("ig-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); }
};
IntergirOrderItemsQuantity.style = styleCss;

exports.ig_order_items_quantity = IntergirOrderItemsQuantity;
