import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { E as Error } from './index-38089f62.js';
import './index-cd3eb450.js';
import { C as Connection, I as Item } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import { N as Notice } from './index-f068b00b.js';
import './App-15d9fce3.js';
import './index-b6cf748e.js';
import './_commonjsHelpers-8fe71198.js';
import './index-265fba1f.js';

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

function create(language) {
  return 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) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
    this.quantityStatus = createEvent(this, "quantityStatus", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  async emitChangeStatus(e) {
    const response = await 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(Error.is(response)
      ? Notice.failed(this.t("Failed to change status."))
      : 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
        ? [
          h("td", null, h("div", null, this.item.quantity ? this.item.quantity : this.item.unit ? 1 : "", this.item.unit)),
          h("td", null, h("div", null, this.item.name)),
          h("td", null, h("div", null, this.item.quantity
            ? t("@") + (Item.amount(this.item) / (this.item.quantity ? this.item.quantity : 1)).toFixed(2)
            : "")),
          h("td", null, h("div", null, this.item.vat ? this.item.vat.toFixed(2) : "")),
          h("td", null, h("div", null, Item.amount(this.item).toFixed(2), " ", this.currency)),
          h("td", null, 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 ? (h("ig-status-change", { status: argument[0], quantity: argument[1], unit: this.item.unit, onChangeStatus: (e) => this.emitChangeStatus(e) })) : (h("ig-status-change", { status: argument[0], amount: Item.amount(this.item), currency: this.currency, onChangeStatus: (e) => this.emitChangeStatus(e) }))))),
        ]
        : "",
    ];
  }
  get element() { return getElement(this); }
};
IntergirOrderItemsQuantity.style = styleCss;

export { IntergirOrderItemsQuantity as ig_order_items_quantity };
