import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import './index-ce48c20e.js';
import { d as dist } from './index-63517df5.js';
import './index-38089f62.js';
import './index-046ba252.js';
import './_commonjsHelpers-8fe71198.js';
import './index-837ba18a.js';
import './index-265fba1f.js';
import './index-cd3eb450.js';
import './App-15d9fce3.js';
import './index-f068b00b.js';
import './index-e20749b7.js';
import './index-b6cf748e.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",
  Contact: "Kontakt",
  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 dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-ig-orders-table-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-ig-orders-table-h{display:none}.sc-ig-orders-table-h>table.sc-ig-orders-table{width:100%}.sc-ig-orders-table-h>p.sc-ig-orders-table{padding-left:.5em}[id].sc-ig-orders-table{scroll-margin-top:calc(1.6cm + 2em)}thead.sc-ig-orders-table>tr.sc-ig-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-ig-orders-table>tr.sc-ig-orders-table>*.sc-ig-orders-table{display:table-cell;padding-right:.5em;padding-left:.3em;vertical-align:middle;position:-webkit-sticky;position:sticky;top:1.55cm;z-index:1;text-align:left}[embedded].sc-ig-orders-table-h thead.sc-ig-orders-table>tr.sc-ig-orders-table>*.sc-ig-orders-table{top:0}thead.sc-ig-orders-table>tr.sc-ig-orders-table>*.sc-ig-orders-table>smoothly-icon.sc-ig-orders-table{vertical-align:-50%;margin-left:.1em}.sc-ig-orders-table-h .loadMore.sc-ig-orders-table{text-align:center}.sc-ig-orders-table-h>table.sc-ig-orders-table>td.sc-ig-orders-table>button.sc-ig-orders-table:focus{outline:none}ig-orders-table-row.sc-ig-orders-table{display:table-row-group;border-top:1px solid transparent}ig-orders-table-row.sc-ig-orders-table:last-of-type{border-bottom:1px solid transparent}ig-orders-table-row[hidden].sc-ig-orders-table{display:none}";

const IntergiroOrdersTable = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.selectedChanged = 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 = h("p", null, t("Loading orders from server."));
    else if (this.orders.length <= 0)
      result = h("p", null, t("There are no orders to display."));
    else {
      const amountOrders = this.orders.length;
      result = (h("table", null, h("thead", null, h("tr", null, !this.display ? (h("th", { style: { width: "5%" }, color: "light" }, h("smoothly-checkbox", { "select-all": true }))) : (""), h("th", { color: "light" }, t("Order number")), !this.display ? h("th", { color: "light" }, t("Contact")) : "", h("th", { color: "light" }, t("Amount")), this.receipt ? h("th", { color: "light" }, t("Receipt")) : "", h("th", { color: "light" }, t("Payment")), h("th", { color: "light" }, t("Created")), h("th", { color: "light" }, t("Status")))), this.orders
        .slice(0, this.count)
        .map(order => {
        var _a;
        return [
          h("ig-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 }),
          h("ig-orders-table-details", { order: order, opened: this.opened.hasOwnProperty.call(this.opened, order.id) ? this.opened[order.id] : "" }),
        ];
      }), h("td", { class: "loadMore", colSpan: 7 }, this.count < amountOrders ? (h("button", { onClick: () => (this.count += 100) }, h("smoothly-icon", { name: "chevron-down-circle", size: "large", toolTip: t("Load more orders") }))) : ("")), h("td", null)));
    }
    return result;
  }
  get element() { return getElement(this); }
};
IntergiroOrdersTable.style = styleCss;

export { IntergiroOrdersTable as ig_orders_table };
