import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { _ as __, s as sprintf, a as _n } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$e } from './sc-alert2.js';
import { d as defineCustomElement$d } from './sc-block-ui2.js';
import { d as defineCustomElement$c } from './sc-button2.js';
import { d as defineCustomElement$b } from './sc-card2.js';
import { d as defineCustomElement$a } from './sc-dashboard-module2.js';
import { d as defineCustomElement$9 } from './sc-divider2.js';
import { d as defineCustomElement$8 } from './sc-empty2.js';
import { d as defineCustomElement$7 } from './sc-format-bytes2.js';
import { d as defineCustomElement$6 } from './sc-icon2.js';
import { d as defineCustomElement$5 } from './sc-skeleton2.js';
import { d as defineCustomElement$4 } from './sc-spacing2.js';
import { d as defineCustomElement$3 } from './sc-spinner2.js';
import { d as defineCustomElement$2 } from './sc-stacked-list2.js';
import { d as defineCustomElement$1 } from './sc-stacked-list-row2.js';
import { a as addQueryArgs } from './add-query-args.js';

const scDownloadsListCss = ":host{display:block}.download__details{opacity:0.75}";

const ScDownloadsList = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    this.purchases = [];
  }
  renderEmpty() {
    return (h("div", null, h("sc-divider", { style: { '--spacing': '0' } }), h("slot", { name: "empty" }, h("sc-empty", { icon: "download" }, __("You don't have any downloads.", 'surecart')))));
  }
  renderLoading() {
    return (h("sc-card", { "no-padding": true, style: { '--overflow': 'hidden' } }, h("sc-stacked-list", null, h("sc-stacked-list-row", { style: { '--columns': '2' }, "mobile-size": 0 }, h("div", { style: { padding: '0.5em' } }, h("sc-skeleton", { style: { width: '30%', marginBottom: '0.75em' } }), h("sc-skeleton", { style: { width: '20%' } }))))));
  }
  renderList() {
    return this.purchases.map(purchase => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _j;
      return (h("sc-stacked-list-row", { href: !(purchase === null || purchase === void 0 ? void 0 : purchase.revoked)
          ? addQueryArgs(window.location.href, {
            action: 'edit',
            model: 'download',
            id: purchase.id,
            nonce: this.requestNonce,
          })
          : null, key: purchase.id, "mobile-size": 0 }, h("sc-spacing", { style: {
          '--spacing': 'var(--sc-spacing-xx--small)',
        } }, h("div", null, h("strong", null, (_a = purchase === null || purchase === void 0 ? void 0 : purchase.product) === null || _a === void 0 ? void 0 : _a.name)), h("div", { class: "download__details" }, sprintf(_n('%s file', '%s files', (_d = (_c = (_b = purchase === null || purchase === void 0 ? void 0 : purchase.product) === null || _b === void 0 ? void 0 : _b.downloads) === null || _c === void 0 ? void 0 : _c.pagination) === null || _d === void 0 ? void 0 : _d.count, 'surecart'), (_g = (_f = (_e = purchase === null || purchase === void 0 ? void 0 : purchase.product) === null || _e === void 0 ? void 0 : _e.downloads) === null || _f === void 0 ? void 0 : _f.pagination) === null || _g === void 0 ? void 0 : _g.count), ' ', "\u2022", ' ', h("sc-format-bytes", { value: (_j = (_h = purchase === null || purchase === void 0 ? void 0 : purchase.product) === null || _h === void 0 ? void 0 : _h.downloads) === null || _j === void 0 ? void 0 : _j.data.map(item => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.media) === null || _a === void 0 ? void 0 : _a.byte_size; }).reduce((prev, curr) => prev + curr, 0) }))), h("sc-icon", { name: "chevron-right", slot: "suffix" })));
    });
  }
  renderContent() {
    var _a;
    if (this.loading) {
      return this.renderLoading();
    }
    if (((_a = this.purchases) === null || _a === void 0 ? void 0 : _a.length) === 0) {
      return this.renderEmpty();
    }
    return (h("sc-card", { "no-padding": true, style: { '--overflow': 'hidden' } }, h("sc-stacked-list", null, this.renderList())));
  }
  render() {
    return (h("sc-dashboard-module", { class: "downloads-list", error: this.error }, h("span", { slot: "heading" }, h("slot", { name: "heading" }, this.heading || __('Items', 'surecart'))), h("slot", { name: "before" }), !!this.allLink && (h("sc-button", { type: "link", href: this.allLink, slot: "end" }, __('View all', 'surecart'), h("sc-icon", { name: "chevron-right", slot: "suffix" }))), this.renderContent(), h("slot", { name: "after" }), this.busy && h("sc-block-ui", null)));
  }
  get el() { return this; }
  static get style() { return scDownloadsListCss; }
}, [1, "sc-downloads-list", {
    "allLink": [1, "all-link"],
    "heading": [1],
    "busy": [4],
    "loading": [4],
    "requestNonce": [1, "request-nonce"],
    "error": [1],
    "purchases": [16]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-downloads-list", "sc-alert", "sc-block-ui", "sc-button", "sc-card", "sc-dashboard-module", "sc-divider", "sc-empty", "sc-format-bytes", "sc-icon", "sc-skeleton", "sc-spacing", "sc-spinner", "sc-stacked-list", "sc-stacked-list-row"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-downloads-list":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScDownloadsList);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-card":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-dashboard-module":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-divider":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-empty":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-format-bytes":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-skeleton":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-spacing":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-stacked-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "sc-stacked-list-row":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}
defineCustomElement();

export { ScDownloadsList as S, defineCustomElement as d };
