'use strict';

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

const index = require('./index-140bcbcd.js');
const index$1 = require('./index-f23d1d6b.js');
require('./Item-00ce8c24.js');
const index$2 = require('./index-ac98852d.js');
require('./Credentials-8e4749ab.js');
require('./Token-8c5ba5d9.js');
const index$3 = require('./index-d3079b93.js');
require('./App-0b3e3f31.js');
const ClientIdentifier = require('./ClientIdentifier-c4353526.js');
const sort = require('./sort-2cd3789e.js');
const unknown = require('./unknown-38d3748c.js');
const Notice = require('./Notice-e970b490.js');
const index$4 = require('./index-2d6d8231.js');
require('./_commonjsHelpers-537d719a.js');
require('./index-09251373.js');
require('./TextDecoder-753156f3.js');
require('./index-bddf9814.js');
require('./index-dc498c54.js');

const styleCss$3 = ".sc-ig-customers-h{display:block;width:100%;max-width:90em;margin:auto}ig-customer-create-popup.sc-ig-customers{bottom:3.5em;margin-right:2.5em}";

const IntergiroCustomers = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.updateCustomers = index.createEvent(this, "updateCustomers", 7);
    this.selected = {};
  }
  componentWillLoad() {
    if (!this.customersFiltered)
      this.filterCustomers();
  }
  handleFilterChanged(event) {
    this.filter = event.detail;
    event.stopPropagation();
  }
  filterCustomers() {
    const result = this.customers && (this.filter ? index$1.dist.filter(this.filter, this.customers) : [...this.customers]);
    this.customersFiltered = result;
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
  }
  onCreate(e) {
    this.updateCustomers.emit(e.detail);
  }
  render() {
    return [
      index.h("ig-filter", { template: index$2.Customer.template, filter: this.filter }),
      index.h("ig-customer-actions", { whitelist: this.whitelist, selected: this.selected }),
      index.h("ig-customers-table", { client: this.client, customers: this.customersFiltered, orders: this.orders, selected: this.selected, whitelist: this.whitelist }),
      index.h("ig-customer-create-popup", { hidden: true, onCreate: (e) => this.onCreate(e) }),
      index.h("ig-customers-footer", { customers: this.customersFiltered }),
    ];
  }
  static get watchers() { return {
    "customers": ["filterCustomers"],
    "filter": ["filterCustomers"]
  }; }
};
IntergiroCustomers.style = styleCss$3;

const styleCss$2 = "";

const IntergiroPortalSettlements = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.selected = {};
  }
  componentWillLoad() {
    this.settlementsChanged();
  }
  settlementsChanged() {
    var _a;
    if (!this.settlementsFiltered)
      this.settlementsFiltered = (_a = this.settlements) === null || _a === void 0 ? void 0 : _a.sort((a, b) => (a.period.start < b.period.start ? 1 : -1));
  }
  handleFilterChanged(event) {
    this.settlementsFiltered = event.detail;
    event.stopPropagation();
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
  }
  render() {
    return [
      index.h("ig-filter", { value: this.settlements, template: index$2.Settlement.template }),
      index.h("ig-portal-settlement-table", { settlements: this.settlementsFiltered, interchange: this.interchange }),
      index.h("ig-portal-settlement-footer", { color: "light", selected: this.selected, interchange: this.interchange, settlements: this.settlementsFiltered }),
    ];
  }
  static get watchers() { return {
    "settlements": ["settlementsChanged"]
  }; }
};
IntergiroPortalSettlements.style = styleCss$2;

const styleCss$1 = ".sc-portal-defer-view-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-portal-defer-view-h{display:none}";

const PortalDeferView = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.filter = {
      client: index$1.dist.is(ClientIdentifier.ClientIdentifier.value),
      status: index$1.dist.some(index$1.dist.or("created", "ordered", "denied", "pending")),
    };
    this.deferFilter = {
      client: index$1.dist.is(ClientIdentifier.ClientIdentifier.value),
      status: index$1.dist.some(index$1.dist.or("deferred")),
    };
  }
  componentWillLoad() {
    const result = this.orders && index$1.dist.filter(index$1.dist.and(index$1.dist.parse("deferred")).generalize(), this.orders);
    this.filteredOrders = result && sort.sort(result, "created");
  }
  render() {
    return [
      index.h("portal-create-order", { orders: this.orders, emailOption: this.emailOption, currency: this.currency }),
      index.h("portal-display-defer-list", { orders: this.orders, filter: this.deferFilter }),
      index.h("ig-orders", { orders: this.filteredOrders }),
    ];
  }
};
PortalDeferView.style = styleCss$1;

const sv = {
  "Login failed. Make sure email and password are correct.": "Inloggning misslyckades. Kontrollera e-post och lösenord.",
  Email: "E-post",
  Password: "Lösenord",
  "Log in": "Logga in",
};

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

const styleCss = ".sc-portal-login-h{display:block}[hidden].sc-portal-login-h{display:none}.sc-portal-login-h>smoothly-dialog.sc-portal-login{top:60px;z-index:2}*.sc-portal-login{z-index:0}header.sc-portal-login{background-color:rgb(var(--smoothly-default-shade))}form.sc-portal-login{position:relative}smoothly-input.sc-portal-login{border:1px solid rgb(var(--smoothly-medium-color))}smoothly-submit.sc-portal-login{margin-top:0.4em}";

const PortalLogin = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.notice = index.createEvent(this, "notice", 7);
    this.userChanged = index.createEvent(this, "userChanged", 7);
  }
  componentWillLoad() {
    var _a;
    this.t = create(this.element);
    this.done = !!((_a = index$4.PayfuncPortal.client) === null || _a === void 0 ? void 0 : _a.me.user);
  }
  async attemptLogin(e) {
    if (index$4.PayfuncPortal.client)
      index$4.PayfuncPortal.client.me.onUnauthorized = async () => {
        var _a, _b, _c;
        const result = await ((_a = index$4.PayfuncPortal.client) === null || _a === void 0 ? void 0 : _a.me.login((_b = e.detail.user) !== null && _b !== void 0 ? _b : "", (_c = e.detail.password) !== null && _c !== void 0 ? _c : ""));
        if (index$2.User.is(result)) {
          this.userChanged.emit({ user: result });
          this.done = true;
        }
        else
          this.notice.emit(Notice.Notice.failed(this.t("Login failed. Make sure email and password are correct.")));
        return !unknown.Error.is(result);
      };
  }
  render() {
    const t = this.t;
    return [
      index.h("smoothly-dialog", { open: this.done != true, header: "PayFunc Portal" }, index.h("form", null, index.h("smoothly-input", { style: { borderBottom: "none" }, type: "email", name: "user" }, t("Email")), index.h("smoothly-input", { type: "password", name: "password" }, t("Password")), index.h("smoothly-submit", { color: "success", prevent: true, expand: "block", onSubmit: (e) => this.attemptLogin(e) }, t("Log in")))),
      index.h("slot", null),
    ];
  }
  get element() { return index.getElement(this); }
};
PortalLogin.style = styleCss;

exports.ig_customers = IntergiroCustomers;
exports.ig_portal_settlements = IntergiroPortalSettlements;
exports.portal_defer_view = PortalDeferView;
exports.portal_login = PortalLogin;
