D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafdxji
/
shihty.com
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
surecart
/
Filename :
p-5ca9af67.entry.js
back
Copy
import{r as i,h as t,a as s}from"./p-e97fde0a.js";import{a as e}from"./p-dd3464cd.js";import{o}from"./p-b719a497.js";import{a as l}from"./p-401e165e.js";import"./p-d3366af3.js";const d=":host{display:block}.purchase{display:flex;flex-direction:column;gap:var(--sc-spacing-large)}.single-download .single-download__preview{display:flex;align-items:center;justify-content:center;background:var(--sc-color-gray-200);border-radius:var(--sc-border-radius-small);height:4rem;min-width:4rem;width:4rem}";const n=d;const a=class{constructor(s){i(this,s);this.renderFileExt=i=>{var s,e,o,l,d,n,a,r,c;if((s=i===null||i===void 0?void 0:i.media)===null||s===void 0?void 0:s.filename){return(d=(l=(o=(e=i.media.filename).split)===null||o===void 0?void 0:o.call(e,"."))===null||l===void 0?void 0:l.pop)===null||d===void 0?void 0:d.call(l)}if(i===null||i===void 0?void 0:i.url){try{const t=new URL(i.url);if(t.pathname.includes(".")){return(c=(r=(a=(n=t.pathname).split)===null||a===void 0?void 0:a.call(n,"."))===null||r===void 0?void 0:r.pop)===null||c===void 0?void 0:c.call(r)}}catch(i){console.error(i)}}return t("sc-icon",{name:"file"})};this.customerId=undefined;this.productId=undefined;this.heading=undefined;this.downloads=undefined;this.downloading=undefined;this.busy=undefined;this.error=undefined;this.pagination={total:0,total_pages:0};this.query={page:1,per_page:20}}componentWillLoad(){o(this.el,(()=>{this.fetchItems()}))}async fetchItems(){if(!this.productId||!this.customerId){return}try{this.busy=true;await this.getItems()}catch(i){console.error(this.error);this.error=(i===null||i===void 0?void 0:i.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=false}}async getItems(){const i=await e({path:l(`surecart/v1/downloads/`,{product_ids:[this.productId],customer_ids:[this.customerId],downloadable:true,...this.query}),parse:false});this.pagination={total:parseInt(i.headers.get("X-WP-Total")),total_pages:parseInt(i.headers.get("X-WP-TotalPages"))};this.downloads=await i.json();return this.downloads}nextPage(){this.query.page=this.query.page+1;this.fetchItems()}prevPage(){this.query.page=this.query.page-1;this.fetchItems()}async downloadItem(i){var t,s;if(i===null||i===void 0?void 0:i.url){this.downloadFile(i.url,(t=i===null||i===void 0?void 0:i.name)!==null&&t!==void 0?t:"file");return}const o=(s=i===null||i===void 0?void 0:i.media)===null||s===void 0?void 0:s.id;if(!o)return;try{this.downloading=o;const i=await e({path:l(`surecart/v1/customers/${this.customerId}/expose/${o}`,{expose_for:60})});if(!(i===null||i===void 0?void 0:i.url)){throw{message:wp.i18n.__("Could not download the file.","surecart")}}this.downloadFile(i===null||i===void 0?void 0:i.url,i.filename)}catch(i){console.error(i);this.error=(i===null||i===void 0?void 0:i.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.downloading=null}}downloadFile(i,t){const s=document.createElement("a");s.href=i;s.download=t;document.body.appendChild(s);s.click();setTimeout((()=>{document.body.removeChild(s)}),0)}renderList(){var i,s;if((this===null||this===void 0?void 0:this.busy)&&!((i=this===null||this===void 0?void 0:this.downloads)===null||i===void 0?void 0:i.length)){return this.renderLoading()}if(!((s=this===null||this===void 0?void 0:this.downloads)===null||s===void 0?void 0:s.length)){return this.renderEmpty()}const e=this.downloads||[];return t("sc-card",{"no-padding":true},t("sc-stacked-list",null,e.map((i=>{var s,e,o,l;const d=i===null||i===void 0?void 0:i.media;return t("sc-stacked-list-row",{style:{"--columns":"1"}},t("sc-flex",{class:"single-download",justifyContent:"flex-start",alignItems:"center"},t("div",{class:"single-download__preview"},this.renderFileExt(i)),t("div",null,t("div",null,t("strong",null,(e=(s=d===null||d===void 0?void 0:d.filename)!==null&&s!==void 0?s:i===null||i===void 0?void 0:i.name)!==null&&e!==void 0?e:"")),t("sc-flex",{justifyContent:"flex-start",alignItems:"center",style:{gap:"0.5em"}},(d===null||d===void 0?void 0:d.byte_size)&&t("sc-format-bytes",{value:d.byte_size}),!!((o=d===null||d===void 0?void 0:d.release_json)===null||o===void 0?void 0:o.version)&&t("sc-tag",{type:"primary",size:"small",style:{"--sc-tag-primary-background-color":"#f3e8ff","--sc-tag-primary-color":"#6b21a8"}},"v",(l=d===null||d===void 0?void 0:d.release_json)===null||l===void 0?void 0:l.version)))),t("sc-button",{size:"small",slot:"suffix",onClick:()=>this.downloadItem(i),busy:(d===null||d===void 0?void 0:d.id)?this.downloading==(d===null||d===void 0?void 0:d.id):false,disabled:(d===null||d===void 0?void 0:d.id)?this.downloading==(d===null||d===void 0?void 0:d.id):false},wp.i18n.__("Download","surecart")))}))))}renderLoading(){return t("sc-card",{"no-padding":true,style:{"--overflow":"hidden"}},t("sc-stacked-list",null,t("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},t("div",{style:{padding:"0.5em"}},t("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),t("sc-skeleton",{style:{width:"20%"}})))))}renderEmpty(){return t("div",null,t("sc-divider",{style:{"--spacing":"0"}}),t("slot",{name:"empty"},t("sc-empty",{icon:"download"},wp.i18n.__("You don't have any downloads.","surecart"))))}render(){var i;return t("sc-dashboard-module",{key:"65aeac85deaf63e1ff72ce800cc82cb4309021b4",class:"purchase",part:"base",heading:wp.i18n.__("Downloads","surecart")},t("span",{key:"b414cae876550abbbe37fdb73fd8f6c7ac4d9dce",slot:"heading"},t("slot",{key:"8cb776835f359a0961e674c85eff78f28af41d47",name:"heading"},this.heading||wp.i18n.__("Downloads","surecart"))),this.renderList(),t("sc-pagination",{key:"2ddad307c9df1310b553a7117155a417fcdf414d",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(i=this===null||this===void 0?void 0:this.downloads)===null||i===void 0?void 0:i.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}),this.busy&&t("sc-block-ui",{key:"c69765404bc5dcf8e1f81705e9e0c0cbb52eab7d"}))}get el(){return s(this)}};a.style=n;export{a as sc_downloads_list}; //# sourceMappingURL=p-5ca9af67.entry.js.map