import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$e } from './sc-alert2.js';
import { d as defineCustomElement$d } from './sc-button2.js';
import { d as defineCustomElement$c } from './sc-card2.js';
import { d as defineCustomElement$b } from './sc-dashboard-module2.js';
import { d as defineCustomElement$a } from './sc-form-control2.js';
import { d as defineCustomElement$9 } from './sc-icon2.js';
import { d as defineCustomElement$8 } from './sc-input2.js';
import { d as defineCustomElement$7 } from './sc-spinner2.js';
import { d as defineCustomElement$6 } from './sc-table2.js';
import { d as defineCustomElement$5 } from './sc-table-cell2.js';
import { d as defineCustomElement$4 } from './sc-table-row2.js';
import { d as defineCustomElement$3 } from './sc-tag2.js';
import { d as defineCustomElement$2 } from './sc-tooltip2.js';

const scLicensesListCss = ":host{display:block}";

const ScLicensesList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    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 style() { return scLicensesListCss; }
}, [1, "sc-licenses-list", {
    "licenses": [16],
    "activations": [16],
    "heading": [1],
    "copied": [4]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-licenses-list", "sc-alert", "sc-button", "sc-card", "sc-dashboard-module", "sc-form-control", "sc-icon", "sc-input", "sc-spinner", "sc-table", "sc-table-cell", "sc-table-row", "sc-tag", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-licenses-list":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScLicensesList$1);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "sc-card":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-dashboard-module":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-table":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-table-cell":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-table-row":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-tag":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-tooltip":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScLicensesList = ScLicensesList$1;
const defineCustomElement = defineCustomElement$1;

export { ScLicensesList, defineCustomElement };
