'use strict';

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

const index = require('./index-cd6fab62.js');
const defaultI18n = require('./default-i18n-072e75d7.js');
require('./index-20b57ec7.js');
const addQueryArgs = require('./add-query-args-17c551b6.js');
require('./_commonjsHelpers-537d719a.js');

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

const ScDownloadsList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.purchases = [];
  }
  renderEmpty() {
    return (index.h("div", null, index.h("sc-divider", { style: { '--spacing': '0' } }), index.h("slot", { name: "empty" }, index.h("sc-empty", { icon: "download" }, defaultI18n.__("You don't have any downloads.", 'surecart')))));
  }
  renderLoading() {
    return (index.h("sc-card", { "no-padding": true, style: { '--overflow': 'hidden' } }, index.h("sc-stacked-list", null, index.h("sc-stacked-list-row", { style: { '--columns': '2' }, "mobile-size": 0 }, index.h("div", { style: { padding: '0.5em' } }, index.h("sc-skeleton", { style: { width: '30%', marginBottom: '0.75em' } }), index.h("sc-skeleton", { style: { width: '20%' } }))))));
  }
  renderList() {
    return this.purchases.map(purchase => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _j;
      return (index.h("sc-stacked-list-row", { href: !(purchase === null || purchase === void 0 ? void 0 : purchase.revoked)
          ? addQueryArgs.addQueryArgs(window.location.href, {
            action: 'edit',
            model: 'download',
            id: purchase.id,
            nonce: this.requestNonce,
          })
          : null, key: purchase.id, "mobile-size": 0 }, index.h("sc-spacing", { style: {
          '--spacing': 'var(--sc-spacing-xx--small)',
        } }, index.h("div", null, index.h("strong", null, (_a = purchase === null || purchase === void 0 ? void 0 : purchase.product) === null || _a === void 0 ? void 0 : _a.name)), index.h("div", { class: "download__details" }, defaultI18n.sprintf(defaultI18n._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", ' ', index.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) }))), index.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 (index.h("sc-card", { "no-padding": true, style: { '--overflow': 'hidden' } }, index.h("sc-stacked-list", null, this.renderList())));
  }
  render() {
    return (index.h("sc-dashboard-module", { class: "downloads-list", error: this.error }, index.h("span", { slot: "heading" }, index.h("slot", { name: "heading" }, this.heading || defaultI18n.__('Items', 'surecart'))), index.h("slot", { name: "before" }), !!this.allLink && (index.h("sc-button", { type: "link", href: this.allLink, slot: "end" }, defaultI18n.__('View all', 'surecart'), index.h("sc-icon", { name: "chevron-right", slot: "suffix" }))), this.renderContent(), index.h("slot", { name: "after" }), this.busy && index.h("sc-block-ui", null)));
  }
  get el() { return index.getElement(this); }
};
ScDownloadsList.style = scDownloadsListCss;

exports.sc_downloads_list = ScDownloadsList;
