'use strict';

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

const index$1 = require('./index-df541290.js');
require('./index-447d4f97.js');
const index = require('./index-aa81d689.js');
require('./index-6b2ca967.js');
require('./_commonjsHelpers-5bbc2693.js');
require('./index-b2d76b32.js');
require('./index-b5a1c9c0.js');
require('./index-13b50665.js');
require('./index-2f460f13.js');
require('./App-1e388484.js');
require('./index-50f629f5.js');
require('./index-fe50ed35.js');
require('./index-c277d1ea.js');

const sv = {
  "Loading orders from server.": "Laddar ordrar från servern.",
  "There are no orders to display.": "Det finns inga ordrar att visa.",
  "Order number": "Ordernummer",
  Customer: "Kund",
  Amount: "Summa",
  Receipt: "Kvitto",
  Payment: "Betalning",
  Created: "Skapad",
  Status: "Status",
  "Select all orders": "Markera alla ordrar",
  "Deselect all orders": "Avmarkera alla ordrar",
  "Download order report": "Ladda ner orderrapport",
  "Load more orders": "Ladda in fler ordrar",
};

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

const styleCss = ".sc-payfunc-orders-table-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-payfunc-orders-table-h{display:none}.sc-payfunc-orders-table-h>table.sc-payfunc-orders-table{width:100%}.sc-payfunc-orders-table-h>p.sc-payfunc-orders-table{padding-left:.5em}[id].sc-payfunc-orders-table{scroll-margin-top:calc(1.6cm + 2em)}thead.sc-payfunc-orders-table>tr.sc-payfunc-orders-table{display:table-row;font-weight:bold;height:2em;border-top:solid 1px rgb(var(--smoothly-dark-shadow));border-bottom:solid 1px rgb(var(--smoothly-dark-shadow))}thead.sc-payfunc-orders-table>tr.sc-payfunc-orders-table>*.sc-payfunc-orders-table{display:table-cell;padding-right:.5em;padding-left:.3em;vertical-align:middle;position:sticky;top:1.55cm;z-index:1;text-align:left}thead.sc-payfunc-orders-table>tr.sc-payfunc-orders-table>*.sc-payfunc-orders-table>smoothly-icon.sc-payfunc-orders-table{vertical-align:-50%;margin-left:.1em}.sc-payfunc-orders-table-h .loadMore.sc-payfunc-orders-table{text-align:center}.sc-payfunc-orders-table-h>table.sc-payfunc-orders-table>td.sc-payfunc-orders-table>button.sc-payfunc-orders-table:focus{outline:none}payfunc-orders-table-row.sc-payfunc-orders-table{display:table-row-group;border-top:1px solid transparent}payfunc-orders-table-row.sc-payfunc-orders-table:last-of-type{border-bottom:1px solid transparent}payfunc-orders-table-row.sc-payfunc-orders-table:hover{border-top:1px solid rgb(var(--smoothly-medium-color));border-bottom:1px solid rgb(var(--smoothly-medium-color));box-shadow:var(--smoothly-shadow)}payfunc-orders-table-row[hidden].sc-payfunc-orders-table{display:none}";

const PayfuncOrdersTable = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.selectedChanged = index$1.createEvent(this, "selectedChanged", 7);
    this.selected = {};
    this.display = false;
    this.opened = {};
    this.count = 100;
    this.hash = false;
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  componentDidRender() {
    var _a;
    if (window.location.hash && !this.hash) {
      const element = document.getElementById(window.location.hash.substring(1));
      if (element) {
        element.scrollIntoView();
        const order = (_a = this.orders) === null || _a === void 0 ? void 0 : _a.find(order => { var _a; return ((_a = order.number) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, "").toLowerCase()) == window.location.hash.substring(1); });
        if (order) {
          const opened = Object.assign({}, this.opened);
          opened[order.id] = "number";
          this.opened = opened;
        }
        this.hash = true;
      }
    }
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    if (Object.prototype.hasOwnProperty.call(e.detail, "id") && opened[e.detail.id] == e.detail.column)
      delete opened[e.detail.id];
    else
      opened[e.detail.id] = e.detail.column;
    this.opened = opened;
  }
  handleToggle(event) {
    const orders = Object.assign({}, this.selected);
    if (event.detail.checked)
      orders[event.detail.order.id] = event.detail.order;
    else
      delete orders[event.detail.order.id];
    this.selectedChanged.emit((this.selected = orders));
  }
  onChecked(event) {
    this.selected = {};
    if (event.detail.selected && this.orders)
      for (const order of this.orders)
        this.selected[order.id] = order;
    this.selectedChanged.emit(this.selected);
    event.stopPropagation();
    event.preventDefault();
  }
  render() {
    const t = this.t;
    let result;
    if (!this.orders)
      result = index$1.h("p", null, t("Loading orders from server."));
    else if (this.orders.length <= 0)
      result = index$1.h("p", null, t("There are no orders to display."));
    else {
      const amountOrders = this.orders.length;
      result = (index$1.h("table", null, index$1.h("thead", null, index$1.h("tr", null, !this.display ? (index$1.h("th", { style: { width: "5%" }, color: "light" }, index$1.h("smoothly-checkbox", { "select-all": true }))) : (""), index$1.h("th", { color: "light" }, t("Order number")), !this.display ? index$1.h("th", { color: "light" }, t("Customer")) : "", index$1.h("th", { color: "light" }, t("Amount")), this.receipt ? index$1.h("th", { color: "light" }, t("Receipt")) : "", index$1.h("th", { color: "light" }, t("Payment")), index$1.h("th", { color: "light" }, t("Created")), index$1.h("th", { color: "light" }, t("Status")))), this.orders
        .slice(0, this.count)
        .map(order => {
        var _a;
        return [
          index$1.h("payfunc-orders-table-row", { id: (_a = order.number) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, "").toLowerCase(), selected: this.selected.hasOwnProperty.call(this.selected, order.id), order: order, display: this.display, opened: this.opened.hasOwnProperty.call(this.opened, order.id) ? this.opened[order.id] : "", receipt: this.receipt }),
          index$1.h("payfunc-orders-table-details", { order: order, opened: this.opened.hasOwnProperty.call(this.opened, order.id) ? this.opened[order.id] : "" }),
        ];
      }), index$1.h("td", { class: "loadMore", colSpan: 7 }, this.count < amountOrders ? (index$1.h("button", { onClick: () => (this.count += 100) }, index$1.h("smoothly-icon", { name: "chevron-down-circle", size: "large", toolTip: t("Load more orders") }))) : ("")), index$1.h("td", null)));
    }
    return result;
  }
  get element() { return index$1.getElement(this); }
};
PayfuncOrdersTable.style = styleCss;

exports.payfunc_orders_table = PayfuncOrdersTable;
