'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./_commonjsHelpers-937cd5b3.js');
const index = require('./index-36cf3884.js');

const sv = {
  "Account number": "Kontonummer",
  Customer: "Kund",
  Method: "Metod",
  Orders: "Ordrar",
  Subscription: "Prenumeration",
  Balance: "Saldo",
  "Select all accounts": "Markera alla kunder",
  "Deselect all accounts": "Avmarkera alla kunder",
  "Loading accounts from server.": "Laddar konton från servern.",
  "There are no accounts to display.": "Det finns inga konton att visa.",
  "Load more accounts": "Ladda in fler konton",
};

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

const styleCss = ".sc-payfunc-accounts-table-h{display:block;width:100%;max-width:90em;margin:auto;border:1px solid rgb(var(--smoothly-medium-color))}[hidden].sc-payfunc-accounts-table-h{display:none}.sc-payfunc-accounts-table-h>p.sc-payfunc-accounts-table{padding-left:.5em}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table{width:100%}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table>thead.sc-payfunc-accounts-table>tr.sc-payfunc-accounts-table{display:table-row;font-weight:bold;height:2em}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table>thead.sc-payfunc-accounts-table>tr.sc-payfunc-accounts-table>*.sc-payfunc-accounts-table{display:table-cell;padding-right:.5em;padding-left:.3em;vertical-align:middle;position:sticky;top:1.55cm;z-index:1;text-align:left}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table>thead.sc-payfunc-accounts-table>tr.sc-payfunc-accounts-table>*.sc-payfunc-accounts-table>smoothly-icon.sc-payfunc-accounts-table{vertical-align:-50%;margin-left:.1em}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table>td.sc-payfunc-accounts-table{text-align:center}.sc-payfunc-accounts-table-h>table.sc-payfunc-accounts-table>td.sc-payfunc-accounts-table>button.sc-payfunc-accounts-table>smoothly-icon.sc-payfunc-accounts-table{cursor:pointer}";

const PayfuncAccountsTable = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.selectedChanged = index$1.createEvent(this, "selectedChanged", 7);
    this.selected = {};
    this.count = 100;
    this.opened = {};
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  onChecked(event) {
    this.selected = {};
    if (event.detail.selected && this.accounts)
      for (const account of this.accounts)
        this.selected[account.id] = account;
    this.selectedChanged.emit(this.selected);
    event.stopPropagation();
    event.preventDefault();
  }
  handleToggle(event) {
    const accounts = Object.assign({}, this.selected);
    if (event.detail.checked)
      accounts[event.detail.account.id] = event.detail.account;
    else
      delete accounts[event.detail.account.id];
    this.selectedChanged.emit((this.selected = accounts));
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    if (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;
  }
  render() {
    const t = this.t;
    let result;
    if (!this.accounts)
      result = index$1.h("p", null, t("Loading accounts from server."));
    else if (this.accounts.length <= 0)
      result = index$1.h("p", null, t("There are no accounts to display."));
    else {
      result = [
        index$1.h("table", null, index$1.h("thead", null, index$1.h("tr", null, index$1.h("th", { style: { width: "5%" }, color: "light" }, index$1.h("smoothly-checkbox", { "select-all": true })), index$1.h("th", { color: "light" }, t("Account number")), index$1.h("th", { color: "light" }, t("Customer")), index$1.h("th", { color: "light" }, t("Orders")), this.whitelist ? index$1.h("th", { color: "light" }, t("Subscription")) : [], index$1.h("th", { color: "light" }, t("Method")), this.whitelist ? index$1.h("th", { color: "light" }, t("Balance")) : [], index$1.h("th", { color: "light" }, t("Login")), index$1.h("th", { color: "light" }, t("Status")))), this.accounts
          ? this.accounts
            .slice(0, this.count)
            .map(account => {
            var _a, _b;
            return [
              index$1.h("payfunc-account-table-row", { account: account, whitelist: this.whitelist, orders: this.orders ? this.orders[account.id] : undefined, opened: (_a = this.opened[account.id]) !== null && _a !== void 0 ? _a : "", selected: this.selected.hasOwnProperty.call(this.selected, account.id) }),
              index$1.h("payfunc-account-details", { opened: (_b = this.opened[account.id]) !== null && _b !== void 0 ? _b : "", orders: this.orders ? this.orders[account.id] : undefined, whitelist: this.whitelist, account: account }),
            ];
          })
          : null, index$1.h("td", { colSpan: 8 }, this.count < this.accounts.length ? (index$1.h("button", { onClick: () => (this.count += 100) }, index$1.h("smoothly-icon", { name: "chevron-down-circle", size: "large", toolTip: this.t("Load more accounts") }))) : (""))),
      ];
    }
    return result;
  }
  get element() { return index$1.getElement(this); }
};
PayfuncAccountsTable.style = styleCss;

exports.payfunc_accounts_table = PayfuncAccountsTable;
