'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./App-1647a125.js');
require('./_commonjsHelpers-937cd5b3.js');
const index$4 = require('./index-1a9e1965.js');
require('./index-451ca284.js');
const index$2 = require('./index-ab186017.js');
const index = require('./index-36cf3884.js');
const index$5 = require('./index-061d0ccd.js');
const index$3 = require('./index-a802b56a.js');

const sv = {
  Deselect: "Avmarkera",
  Select: "Markera",
  unknown: "okänd",
  none: "ingen",
  active: "aktiva",
  "$0 orders": "$0 ordrar",
  "Send login link via email": "Skicka inloggningslänk via e-post",
  "Successfully sent email": "E-post skickat",
  "Failed to send email": "Misslyckades med att skicka e-post",
  "The customer has no email set": "Kunden har ingen e-post satt",
  "Sending email...": "Skickar e-post...",
  daily: "daglig",
  weekly: "veckovis",
  monthly: "månadsvis",
  quarterly: "kvartalsvis",
  yearly: "årlig",
};

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

const styleCss = ".sc-payfunc-account-table-row-h{display:table-row}.sc-payfunc-account-table-row-h:hover{border-top:1px solid rgb(var(--smoothly-medium-color));border-bottom:1px solid rgb(var(--smoothly-medium-color));box-shadow:var(--smoothly-shadow)}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row>.openable.sc-payfunc-account-table-row{padding:.5em .3em;width:max-content;min-width:3em;display:inline-block}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row>smoothly-checkbox.sc-payfunc-account-table-row{display:inline-block;vertical-align:-40%;margin-left:.3em}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row>div.sc-payfunc-account-table-row{min-width:3em}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row>.openable.sc-payfunc-account-table-row:hover{background-color:rgb(var(--smoothly-dark-shade));cursor:pointer}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row>.openable.opened.sc-payfunc-account-table-row{border:solid 1px  rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));border-bottom:3px solid rgb(var(--smoothly-dark-shade));border-radius:0 0 2px 2px;margin-bottom:-2px}payfunc-status.sc-payfunc-account-table-row{margin-right:.2em;padding-right:0.5em;flex-shrink:5;width:100%}.sc-payfunc-account-table-row-h>td.sc-payfunc-account-table-row:last-child>div.sc-payfunc-account-table-row{width:100%;max-width:20em;display:flex;align-content:stretch;flex-wrap:nowrap}.sendLogin.sc-payfunc-account-table-row{cursor:pointer;vertical-align:-40%;display:inline-block}smoothly-trigger.sc-payfunc-account-table-row{border:none;padding-left:0.35em}";

const PayfuncAccountTableRow = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.columnClicked = index$1.createEvent(this, "columnClicked", 7);
    this.accountSelected = index$1.createEvent(this, "accountSelected", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.opened = "";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  handleColumnClick(column) {
    var _a;
    this.opened = column;
    this.columnClicked.emit({ id: (_a = this.account) === null || _a === void 0 ? void 0 : _a.id, column });
  }
  handleSelected(e) {
    this.accountSelected.emit({ account: this.account, checked: !this.selected });
    e.stopPropagation();
    e.preventDefault();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g;
    return index$2.Account.is(this.account)
      ? [
        index$1.h("td", null, index$1.h("smoothly-checkbox", { selected: this.selected })),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "number" ? " opened" : ""), onClick: () => this.handleColumnClick("number") }, this.account.number)),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "customer" ? " opened" : ""), onClick: () => this.handleColumnClick("customer") }, (_a = index$2.Customer.getLabel(this.account.customer)) !== null && _a !== void 0 ? _a : this.t("unknown"))),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "order" ? " opened" : ""), onClick: () => this.handleColumnClick("order") }, this.t("$0 orders", (_c = (_b = this.orders) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0))),
        this.whitelist ? (index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "subscription" ? " opened" : ""), onClick: () => this.handleColumnClick("subscription") }, !this.account.subscription || this.account.subscription.length < 1
          ? this.t("none")
          : this.account.subscription.length > 1
            ? this.account.subscription.length + " " + this.t("active")
            : this.t(typeof this.account.subscription[0].schedule == "object"
              ? this.account.subscription[0].schedule.frequency
              : this.account.subscription[0].schedule) +
              " " +
              index$2.Item.amount(this.account.subscription[0].items) +
              " " +
              this.account.subscription[0].currency))) : ([]),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "method" ? " opened" : ""), onClick: () => this.handleColumnClick("method") }, this.account.method[0]
          ? index$3.dist.format(this.account.method[0].iin + "******" + this.account.method[0].last4, "card-number")
          : this.t("none"))),
        this.whitelist ? (index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "balance" ? " opened" : ""), style: { color: this.account.total < 0 ? "red" : "" }, onClick: () => this.handleColumnClick("balance") }, index$3.dist.format(this.account.total, "price", this.account.currency)))) : ([]),
        index$1.h("td", null, index$1.h("smoothly-trigger", { disabled: !((_d = this.account.customer) === null || _d === void 0 ? void 0 : _d.email) }, index$1.h("smoothly-icon", { onClick: ((_e = this.account.customer) === null || _e === void 0 ? void 0 : _e.email) ? () => this.sendLogin() : undefined, class: "sendLogin", name: "mail", size: "small", toolTip: !((_f = this.account.customer) === null || _f === void 0 ? void 0 : _f.email)
            ? this.t("The customer has no email set")
            : this.t("Send login link via email") }))),
        index$1.h("td", null, index$1.h("div", null, index$1.h("payfunc-status", { status: (_g = this.account.status) !== null && _g !== void 0 ? _g : index$2.Account.Status.getStatus(this.account, this.orders ? this.orders[0] : undefined) }))),
      ]
      : null;
  }
  async sendLogin() {
    this.notice.emit(index$4.Notice.execute(this.t("Sending email..."), async () => {
      var _a;
      const response = await index$2.Connection.post(`account/${(_a = this.account) === null || _a === void 0 ? void 0 : _a.id}/link?email=true`, {});
      let result;
      if (!index$5.dist.Error.is(response))
        result = [true, this.t("Successfully sent email")];
      else
        result = [false, this.t("Failed to send email")];
      return result;
    }));
  }
  get element() { return index$1.getElement(this); }
};
PayfuncAccountTableRow.style = styleCss;

exports.payfunc_account_table_row = PayfuncAccountTableRow;
