import { Component, Element, Event, h, Listen, Prop, State } from "@stencil/core";
import { DateTime } from "isoly";
import * as tidily from "tidily";
import { ModelState } from "../../../model";
import * as translation from "../../translation";
export class IntergiroAuthorizationTableRow {
  constructor() {
    this.abbreviated = false;
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  handleColumnClick(column) {
    this.opened = column;
    this.columnClicked.emit({ index: this.index, column });
  }
  handleSelected(e) {
    if (ModelState.Authorization.is(this.state))
      this.authorizationSelected.emit({ authorization: this.state, checked: e.detail.selected });
    e.stopPropagation();
    e.preventDefault();
  }
  render() {
    var _a, _b, _c, _d, _e;
    const value = this.state.authorization;
    const hasCard = value.card && value.card.iin && value.card.last4;
    return [
      !this.abbreviated && (h("td", null,
        h("smoothly-checkbox", { disabled: !ModelState.Authorization.is(this.state), selected: this.selected }))),
      h("td", null,
        h("span", { onClick: () => this.handleColumnClick("number"), class: "openable" + (this.opened == "number" ? " opened" : "") }, (_b = (_a = value.number) !== null && _a !== void 0 ? _a : value.id) !== null && _b !== void 0 ? _b : this.t("unknown"))),
      !this.abbreviated && (h("td", null,
        h("span", { onClick: () => this.merchant && this.handleColumnClick("merchant"), class: this.merchant && "openable" + (this.opened == "merchant" ? " opened" : "") }, (_c = this.merchant) !== null && _c !== void 0 ? _c : this.t("unknown")))),
      h("td", { class: "right" },
        h("span", { onClick: () => ModelState.Authorization.is(this.state) && this.handleColumnClick("amount"), class: (ModelState.Authorization.is(this.state) && "openable") + (this.opened == "amount" ? " opened" : "") }, value.amount ? (h("smoothly-display-amount", { amount: value.amount, currency: value.currency })) : (this.t("unknown")))),
      h("td", null,
        h("span", { onClick: () => hasCard && this.handleColumnClick("card"), class: hasCard && "openable" + (this.opened == "card" ? " opened" : "") }, hasCard ? tidily.format(((_d = value.card) === null || _d === void 0 ? void 0 : _d.iin) + "******" + ((_e = value.card) === null || _e === void 0 ? void 0 : _e.last4), "card-number") : this.t("unknown"))),
      h("td", null,
        h("smoothly-display-date-time", { onClick: () => this.handleColumnClick("history"), class: "openable" + (this.opened == "history" ? " opened" : ""), datetime: DateTime.localize(value.created) })),
      h("td", null,
        h("span", { title: this.state.authorization.recurring && this.t("Recurring") }, this.state.authorization.recurring ? "R" : "")),
      h("td", null,
        h("ig-authorization-status", { value: this.state })),
    ];
  }
  static get is() { return "ig-authorization-table-row"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "state": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "ModelState.Authorization | ModelState.FailedAuthorization",
        "resolved": "Authorization | FailedAuthorization",
        "references": {
          "ModelState": {
            "location": "import",
            "path": "../../../model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "merchant": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "merchant",
      "reflect": false
    },
    "opened": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "opened",
      "reflect": false
    },
    "index": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "index",
      "reflect": false
    },
    "abbreviated": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "abbreviated",
      "reflect": false,
      "defaultValue": "false"
    },
    "selected": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "selected",
      "reflect": false
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get events() { return [{
      "method": "columnClicked",
      "name": "columnClicked",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "{ index: number; column: string }",
        "resolved": "{ index: number; column: string; }",
        "references": {}
      }
    }, {
      "method": "authorizationSelected",
      "name": "authorizationSelected",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "{ authorization: ModelState.Authorization; checked: boolean }",
        "resolved": "{ authorization: Authorization; checked: boolean; }",
        "references": {
          "ModelState": {
            "location": "import",
            "path": "../../../model"
          }
        }
      }
    }]; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "checked",
      "method": "handleSelected",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
