import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './App-418c0118.js';
import './_commonjsHelpers-91fffb88.js';
import { N as Notice } from './index-4920b0b3.js';
import './index-66cd4113.js';
import { C as Connection, I as Item } from './index-ec2a4942.js';
import { d as dist } from './index-fdd60c34.js';
import { d as dist$1 } from './index-909faba2.js';

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

function create(language) {
  return 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) {
    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(dist$1.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("payfunc-status-change", { status: argument[0], quantity: argument[1], unit: this.item.unit, onChangeStatus: (e) => this.emitChangeStatus(e) })) : (h("payfunc-status-change", { status: argument[0], amount: Item.amount(this.item), currency: this.currency, onChangeStatus: (e) => this.emitChangeStatus(e) }))))),
        ]
        : "",
    ];
  }
  get element() { return getElement(this); }
};
PayfuncOrderItemsQuantity.style = styleCss;

export { PayfuncOrderItemsQuantity as payfunc_order_items_quantity };
