JezK
Edit File: sc-purchase-downloads-list2.js
import{proxyCustomElement,HTMLElement,h,Fragment}from"@stencil/core/internal/client";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 scPurchaseDownloadsListCss=":host{display:block}.download__details{opacity:0.75}",ScPurchaseDownloadsListStyle0=scPurchaseDownloadsListCss,ScPurchaseDownloadsList=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.allLink=void 0,this.heading=void 0,this.busy=void 0,this.loading=void 0,this.requestNonce=void 0,this.error=void 0,this.purchases=[]}renderEmpty(){return h("div",null,h("sc-divider",{style:{"--spacing":"0"}}),h("slot",{name:"empty"},h("sc-empty",{icon:"download"},wp.i18n.__("You don't have any downloads.","surecart"))))}renderLoading(){return h("sc-card",{"no-padding":!0,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((e=>{var s,t,o,n,d;const i=null==e?void 0:e.variant,a=((null===(s=null==i?void 0:i.downloads)||void 0===s?void 0:s.data)||[]).filter((e=>!e.archived)),l=(null==i?void 0:i.downloads_enabled)&&a.length>0?a:(null===(n=null===(o=null===(t=null==e?void 0:e.product)||void 0===t?void 0:t.downloads)||void 0===o?void 0:o.data)||void 0===n?void 0:n.filter((e=>!e.archived)))||[],c=l.length,r=(l||[]).map((e=>{var s;return(null==e?void 0:e.media)?null===(s=null==e?void 0:e.media)||void 0===s?void 0:s.byte_size:0})),m=r.reduce(((e,s)=>e+s),0);return h("sc-stacked-list-row",{href:(null==e?void 0:e.revoked)?null:addQueryArgs(window.location.href,{action:"show",model:"download",id:e.id,nonce:this.requestNonce}),key:e.id,"mobile-size":0},h("sc-spacing",{style:{"--spacing":"var(--sc-spacing-xx--small)"}},h("div",null,h("strong",null,null===(d=null==e?void 0:e.product)||void 0===d?void 0:d.name)),h("div",{class:"download__details"},wp.i18n.sprintf(wp.i18n._n("%s file","%s files",c,"surecart"),c),!!m&&h(Fragment,null," ","• ",h("sc-format-bytes",{value:m})))),h("sc-icon",{name:"chevron-right",slot:"suffix"}))}))}renderContent(){var e;return this.loading?this.renderLoading():0===(null===(e=this.purchases)||void 0===e?void 0:e.length)?this.renderEmpty():h("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},h("sc-stacked-list",null,this.renderList()))}render(){return h("sc-dashboard-module",{key:"a088dd66ad05397273b3a2ca13c432b1ed5420e2",class:"downloads-list",error:this.error},h("span",{key:"ee2b187421431ee581fd5baf683d115094c21d53",slot:"heading"},h("slot",{key:"1b83b443594a6d4cecc2a2e99359f00089d1831e",name:"heading"},this.heading||wp.i18n.__("Items","surecart"))),h("slot",{key:"501369a7bc63b18426b279d7ec1e95ab8efc5ee6",name:"before"}),!!this.allLink&&h("sc-button",{key:"3593d3bb4b1d1aadd279b4b35a28c77eabce35ec",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),h("sc-icon",{key:"31cef6334166345b9f7955d8bf42f30bc4313d9e",name:"chevron-right",slot:"suffix"})),this.renderContent(),h("slot",{key:"7560eac98fa4bf7ba1093cbd428874fa4c3183c4",name:"after"}),this.busy&&h("sc-block-ui",{key:"17e6761b09ac048a1f5d7500193e5d4f2a6b5d2c"}))}get el(){return this}static get style(){return ScPurchaseDownloadsListStyle0}},[1,"sc-purchase-downloads-list",{allLink:[1,"all-link"],heading:[1],busy:[4],loading:[4],requestNonce:[1,"request-nonce"],error:[1],purchases:[16]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-purchase-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"].forEach((e=>{switch(e){case"sc-purchase-downloads-list":customElements.get(e)||customElements.define(e,ScPurchaseDownloadsList);break;case"sc-alert":customElements.get(e)||defineCustomElement$e();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$d();break;case"sc-button":customElements.get(e)||defineCustomElement$c();break;case"sc-card":customElements.get(e)||defineCustomElement$b();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$a();break;case"sc-divider":customElements.get(e)||defineCustomElement$9();break;case"sc-empty":customElements.get(e)||defineCustomElement$8();break;case"sc-format-bytes":customElements.get(e)||defineCustomElement$7();break;case"sc-icon":customElements.get(e)||defineCustomElement$6();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$5();break;case"sc-spacing":customElements.get(e)||defineCustomElement$4();break;case"sc-spinner":customElements.get(e)||defineCustomElement$3();break;case"sc-stacked-list":customElements.get(e)||defineCustomElement$2();break;case"sc-stacked-list-row":customElements.get(e)||defineCustomElement$1()}}))}export{ScPurchaseDownloadsList as S,defineCustomElement as d};