import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './App-418c0118.js';
import './_commonjsHelpers-91fffb88.js';
import { N as Notice } from './index-4920b0b3.js';
import './index-66cd4113.js';
import { A as Account, a as Customer, I as Item, C as Connection } from './index-df45deab.js';
import { d as dist } from './index-fdd60c34.js';
import { d as dist$2 } from './index-909faba2.js';
import { d as dist$1 } from './index-ff2f9e0e.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 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) {
    registerInstance(this, hostRef);
    this.columnClicked = createEvent(this, "columnClicked", 7);
    this.accountSelected = createEvent(this, "accountSelected", 7);
    this.notice = 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 Account.is(this.account)
      ? [
        h("td", null, h("smoothly-checkbox", { selected: this.selected })),
        h("td", null, h("div", { class: "openable" + (this.opened == "number" ? " opened" : ""), onClick: () => this.handleColumnClick("number") }, this.account.number)),
        h("td", null, h("div", { class: "openable" + (this.opened == "customer" ? " opened" : ""), onClick: () => this.handleColumnClick("customer") }, (_a = Customer.getLabel(this.account.customer)) !== null && _a !== void 0 ? _a : this.t("unknown"))),
        h("td", null, 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 ? (h("td", null, 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) +
              " " +
              Item.amount(this.account.subscription[0].items) +
              " " +
              this.account.subscription[0].currency))) : ([]),
        h("td", null, h("div", { class: "openable" + (this.opened == "method" ? " opened" : ""), onClick: () => this.handleColumnClick("method") }, this.account.method[0]
          ? dist$1.format(this.account.method[0].iin + "******" + this.account.method[0].last4, "card-number")
          : this.t("none"))),
        this.whitelist ? (h("td", null, h("div", { class: "openable" + (this.opened == "balance" ? " opened" : ""), style: { color: this.account.total < 0 ? "red" : "" }, onClick: () => this.handleColumnClick("balance") }, dist$1.format(this.account.total, "price", this.account.currency)))) : ([]),
        h("td", null, h("smoothly-trigger", { disabled: !((_d = this.account.customer) === null || _d === void 0 ? void 0 : _d.email) }, 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") }))),
        h("td", null, h("div", null, h("payfunc-status", { status: (_g = this.account.status) !== null && _g !== void 0 ? _g : Account.Status.getStatus(this.account, this.orders ? this.orders[0] : undefined) }))),
      ]
      : null;
  }
  async sendLogin() {
    this.notice.emit(Notice.execute(this.t("Sending email..."), async () => {
      var _a;
      const response = await Connection.post(`account/${(_a = this.account) === null || _a === void 0 ? void 0 : _a.id}/link?email=true`, {});
      let result;
      if (!dist$2.Error.is(response))
        result = [true, this.t("Successfully sent email")];
      else
        result = [false, this.t("Failed to send email")];
      return result;
    }));
  }
  get element() { return getElement(this); }
};
PayfuncAccountTableRow.style = styleCss;

export { PayfuncAccountTableRow as payfunc_account_table_row };
