'use strict';

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

const index$1 = require('./index-df541290.js');
const index$5 = require('./index-0a8af373.js');
const index$3 = require('./index-ad93d157.js');
require('./index-5e992066.js');
const index$2 = require('./index-c12b8888.js');
const index = require('./index-b7493032.js');
const index$4 = require('./index-3e5f1089.js');
require('./_commonjsHelpers-10109b76.js');
require('./App-1e388484.js');
require('./index-0b6f1dd9.js');
require('./index-fe328b96.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-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) {
    index$1.registerInstance(this, hostRef);
    this.columnClicked = index$1.createEvent(this, "columnClicked", 7);
    this.customerSelected = index$1.createEvent(this, "customerSelected", 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.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 index$2.Customer.is(this.customer)
      ? [
        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.customer.number)),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "contact" ? " opened" : ""), onClick: () => this.handleColumnClick("contact") }, (_a = index$2.Contact.getLabel(this.customer.contact)) !== 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.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) +
              " " +
              index$2.Item.amount(this.customer.subscription[0].items) +
              " " +
              this.customer.subscription[0].currency))) : ([]),
        index$1.h("td", null, index$1.h("div", { class: "openable" + (this.opened == "method" ? " opened" : ""), onClick: () => this.handleColumnClick("method") }, this.customer.method[0]
          ? index$3.dist.format(this.customer.method[0].iin + "******" + this.customer.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.customer.total < 0 ? "red" : "" }, onClick: () => this.handleColumnClick("balance") }, index$3.dist.format(this.customer.total, "price", this.customer.currency)))) : ([]),
        index$1.h("td", null, index$1.h("smoothly-trigger", { disabled: !((_d = this.customer.contact) === null || _d === void 0 ? void 0 : _d.email) }, index$1.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") }))),
        index$1.h("td", null, index$1.h("div", null, index$1.h("ig-status", { status: (_g = this.customer.status) !== null && _g !== void 0 ? _g : index$2.Customer.Status.getStatus(this.customer, 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(`customer/${(_a = this.customer) === null || _a === void 0 ? void 0 : _a.id}/link?email=true`, {});
      return !index$5.Error.is(response)
        ? [true, this.t("Successfully sent email")]
        : [false, this.t("Failed to send email")];
    }));
  }
  get element() { return index$1.getElement(this); }
};
IntergiroCustomerTableRow.style = styleCss;

exports.ig_customer_table_row = IntergiroCustomerTableRow;
