import{r as t,h as e,a as s}from"./p-9add63ef.js";import{o as i}from"./p-b719a497.js";import"./p-8dccb656.js";import{a}from"./p-401e165e.js";import{a as r}from"./p-259c3935.js";import"./p-d3366af3.js";const n=":host{display:block}.license__name{font-weight:var(--sc-font-weight-semibold)}.license__details{display:grid;gap:0.25em;color:var(--sc-input-label-color)}";const o=n;const c=class{constructor(e){t(this,e);this.query={page:1,per_page:10};this.heading=wp.i18n.__("Licenses","surecart");this.isCustomer=undefined;this.allLink=undefined;this.licenses=[];this.copied=false;this.loading=false;this.error="";this.pagination={total:0,total_pages:0}}componentWillLoad(){i(this.el,(()=>{this.initialFetch()}))}nextPage(){this.query.page=this.query.page+1;this.initialFetch()}prevPage(){this.query.page=this.query.page-1;this.initialFetch()}async initialFetch(){try{this.loading=true;await this.getLicenses()}catch(t){console.error(t);this.error=(t===null||t===void 0?void 0:t.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}async getLicenses(){if(!this.isCustomer){return}const t=await await r({path:a("surecart/v1/licenses",{expand:["purchase","purchase.product","activations"],...this.query}),parse:false});this.pagination={total:parseInt(t.headers.get("X-WP-Total")),total_pages:parseInt(t.headers.get("X-WP-TotalPages"))};this.licenses=await t.json();return this.licenses}renderStatus(t){if(t==="active"){return e("sc-tag",{type:"success"},wp.i18n.__("Active","surecart"))}if(t==="revoked"){return e("sc-tag",{type:"danger"},wp.i18n.__("Revoked","surecart"))}if(t==="inactive"){return e("sc-tag",{type:"info"},wp.i18n.__("Not Activated","surecart"))}return e("sc-tag",{type:"info"},t)}async copyKey(t){try{await navigator.clipboard.writeText(t);this.copied=true;setTimeout((()=>{this.copied=false}),2e3)}catch(t){console.error(t);alert(wp.i18n.__("Error copying to clipboard","surecart"))}}renderLoading(){return e("sc-card",{"no-padding":true,style:{"--overflow":"hidden"}},e("sc-stacked-list",null,e("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},e("div",{style:{padding:"0.5em"}},e("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"40%"}})))))}renderEmpty(){return e("div",null,e("sc-divider",{style:{"--spacing":"0"}}),e("slot",{name:"empty"},e("sc-empty",{icon:"file-text"},wp.i18n.__("You don't have any licenses.","surecart"))))}renderContent(){var t,s;if(this.loading){return this.renderLoading()}if(((t=this.licenses)===null||t===void 0?void 0:t.length)===0){return this.renderEmpty()}return e("sc-card",{"no-padding":true},e("sc-stacked-list",null,(s=this.licenses)===null||s===void 0?void 0:s.map((({id:t,purchase:s,status:i,activation_limit:r,activation_count:n})=>{var o;return e("sc-stacked-list-row",{key:t,href:a(window.location.href,{action:"show",model:"license",id:t}),"mobile-size":0},e("div",{class:"license__details"},e("div",{class:"license__name"},(o=s===null||s===void 0?void 0:s.product)===null||o===void 0?void 0:o.name),e("div",null,this.renderStatus(i)," ",wp.i18n.sprintf(wp.i18n.__("%1s of %2s Activations Used","surecart"),n||0,r||"∞"))),e("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var t,s;return e("sc-dashboard-module",{key:"e8f903bae5d6b5d5346c5dca64ce1a3e649e1400",class:"purchase",part:"base",error:this.error},e("span",{key:"80177e4a370a35c1f6bde11d1904af1d232d7f25",slot:"heading"},e("slot",{key:"4d93f7b4a590f3a1d02d41d4af3c2a7a480c0f73",name:"heading"},this.heading||wp.i18n.__("License Keys","surecart"))),!!this.allLink&&!!((t=this.licenses)===null||t===void 0?void 0:t.length)&&e("sc-button",{key:"983d0d8227acc1e6e6be787a4c3e5d823f00a14e",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),e("sc-icon",{key:"54fb42588966d90e08929373557dc796b833690d",name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&e("sc-pagination",{key:"51f59025552bfdffa3c1cf9794b937fbe6314a53",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:(s=this===null||this===void 0?void 0:this.licenses)===null||s===void 0?void 0:s.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))}get el(){return s(this)}};c.style=o;export{c as sc_licenses_list};
//# sourceMappingURL=p-1e5c079b.entry.js.map