import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { E as Error } from './index-38089f62.js';
import { d as dist$1 } from './index-837ba18a.js';
import './index-cd3eb450.js';
import { a as Customer, b as Contact, I as Item, C as Connection } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import { N as Notice } from './index-f068b00b.js';
import './_commonjsHelpers-8fe71198.js';
import './App-15d9fce3.js';
import './index-b6cf748e.js';
import './index-265fba1f.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-ig-customer-table-row-h{display:table-row;border-top:1px solid rgba(var(--smoothly-medium-color), 0);border-bottom:1px solid rgba(var(--smoothly-medium-color), 0)}.sc-ig-customer-table-row-h:hover{-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow);border-top-color:rgb(var(--smoothly-medium-color));border-bottom-color:rgb(var(--smoothly-medium-color))}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row>.openable.sc-ig-customer-table-row{padding:.5em .3em;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:3em;display:inline-block}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row>smoothly-checkbox.sc-ig-customer-table-row{display:inline-block;vertical-align:-40%;margin-left:.3em}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row>div.sc-ig-customer-table-row{min-width:3em}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row>.openable.sc-ig-customer-table-row:hover{background-color:rgb(var(--smoothly-dark-shade));cursor:pointer}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row>.openable.opened.sc-ig-customer-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}ig-status.sc-ig-customer-table-row{margin-right:.2em;padding-right:0.5em;-ms-flex-negative:5;flex-shrink:5;width:100%}.sc-ig-customer-table-row-h>td.sc-ig-customer-table-row:last-child>div.sc-ig-customer-table-row{width:100%;max-width:20em;display:-ms-flexbox;display:flex;-ms-flex-line-pack:stretch;align-content:stretch;-ms-flex-wrap:nowrap;flex-wrap:nowrap}.sendLogin.sc-ig-customer-table-row{cursor:pointer;vertical-align:-40%;display:inline-block}smoothly-trigger.sc-ig-customer-table-row{border:none;padding-left:0.35em}";

const IntergiroCustomerTableRow = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.columnClicked = createEvent(this, "columnClicked", 7);
    this.customerSelected = createEvent(this, "customerSelected", 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.customer) === null || _a === void 0 ? void 0 : _a.id, column });
  }
  handleSelected(e) {
    this.customerSelected.emit({ customer: this.customer, checked: !this.selected });
    e.stopPropagation();
    e.preventDefault();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g;
    return Customer.is(this.customer)
      ? [
        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.customer.number)),
        h("td", null, h("div", { class: "openable" + (this.opened == "contact" ? " opened" : ""), onClick: () => this.handleColumnClick("contact") }, (_a = Contact.getLabel(this.customer.contact)) !== 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.customer.subscription || this.customer.subscription.length < 1
          ? this.t("none")
          : this.customer.subscription.length > 1
            ? this.customer.subscription.length + " " + this.t("active")
            : this.t(typeof this.customer.subscription[0].schedule == "object"
              ? this.customer.subscription[0].schedule.frequency
              : this.customer.subscription[0].schedule) +
              " " +
              Item.amount(this.customer.subscription[0].items) +
              " " +
              this.customer.subscription[0].currency))) : ([]),
        h("td", null, h("div", { class: "openable" + (this.opened == "method" ? " opened" : ""), onClick: () => this.handleColumnClick("method") }, this.customer.method[0]
          ? dist$1.format(this.customer.method[0].iin + "******" + this.customer.method[0].last4, "card-number")
          : this.t("none"))),
        this.whitelist ? (h("td", null, h("div", { class: "openable" + (this.opened == "balance" ? " opened" : ""), style: { color: this.customer.total < 0 ? "red" : "" }, onClick: () => this.handleColumnClick("balance") }, dist$1.format(this.customer.total, "price", this.customer.currency)))) : ([]),
        h("td", null, h("smoothly-trigger", { disabled: !((_d = this.customer.contact) === null || _d === void 0 ? void 0 : _d.email) }, h("smoothly-icon", { onClick: ((_e = this.customer.contact) === null || _e === void 0 ? void 0 : _e.email) ? () => this.sendLogin() : undefined, class: "sendLogin", name: "mail", size: "small", toolTip: !((_f = this.customer.contact) === 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("ig-status", { status: (_g = this.customer.status) !== null && _g !== void 0 ? _g : Customer.Status.getStatus(this.customer, 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(`customer/${(_a = this.customer) === null || _a === void 0 ? void 0 : _a.id}/link?email=true`, {});
      return !Error.is(response)
        ? [true, this.t("Successfully sent email")]
        : [false, this.t("Failed to send email")];
    }));
  }
  get element() { return getElement(this); }
};
IntergiroCustomerTableRow.style = styleCss;

export { IntergiroCustomerTableRow as ig_customer_table_row };
