import { Component, h, Prop } from '@stencil/core';
import { __ } from '@wordpress/i18n';
export class ScLicensesList {
  constructor() {
    this.licenses = [];
    this.activations = [];
  }
  renderStatus(status) {
    if (status === 'active') {
      return h("sc-tag", { type: "success" }, __('Active', 'surecart'));
    }
    if (status === 'revoked') {
      return h("sc-tag", { type: "danger" }, __('Revoked', 'surecart'));
    }
    if (status === 'inactive') {
      return h("sc-tag", { type: "info" }, __('Inactive', 'surecart'));
    }
    return h("sc-tag", { type: "info" }, status);
  }
  async copyKey(key) {
    try {
      await navigator.clipboard.writeText(key);
      this.copied = true;
      setTimeout(() => {
        this.copied = false;
      }, 2000);
    }
    catch (err) {
      console.error(err);
      alert(__('Error copying to clipboard', 'surecart'));
    }
  }
  render() {
    return (h("sc-dashboard-module", { class: "purchase", part: "base" },
      h("span", { slot: "heading" },
        h("slot", { name: "heading" }, this.heading || __('License Keys', 'surecart'))),
      h("sc-card", { "no-padding": true },
        h("sc-table", null,
          h("sc-table-cell", { slot: "head" }, __('Key', 'surecart')),
          h("sc-table-cell", { slot: "head", style: { width: '100px' } }, __('Status', 'surecart')),
          h("sc-table-cell", { slot: "head", style: { width: '100px' } }, __('Activations', 'surecart')),
          this.licenses.map(({ key, status, activations, activation_limit }) => {
            var _a;
            return (h("sc-table-row", { style: { '--columns': '3' } },
              h("sc-table-cell", null,
                h("sc-input", { value: key, readonly: true },
                  h("sc-button", { type: "default", size: "small", slot: "suffix", onClick: () => this.copyKey(key) }, this.copied ? __('Copied!', 'surecart') : __('Copy', 'surecart')))),
              h("sc-table-cell", null, this.renderStatus(status)),
              h("sc-table-cell", null, (_a = activations === null || activations === void 0 ? void 0 : activations.pagination) === null || _a === void 0 ? void 0 :
                _a.count,
                " / ",
                activation_limit || h("span", null, "\u221E"))));
          })))));
  }
  static get is() { return "sc-licenses-list"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-licenses-list.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-licenses-list.css"]
  }; }
  static get properties() { return {
    "licenses": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "License[]",
        "resolved": "License[]",
        "references": {
          "License": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    },
    "activations": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Activation[]",
        "resolved": "Activation[]",
        "references": {
          "Activation": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    },
    "heading": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "heading",
      "reflect": false
    },
    "copied": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "copied",
      "reflect": false
    }
  }; }
}
