import{r as t,h as e,a as s}from"./p-e97fde0a.js";import{o as i}from"./p-b719a497.js";import{a}from"./p-dd3464cd.js";import{a as r}from"./p-401e165e.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 c=n;const o=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 a({path:r("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:a,activation_count:n})=>{var c;return e("sc-stacked-list-row",{key:t,href:r(window.location.href,{action:"show",model:"license",id:t}),"mobile-size":0},e("div",{class:"license__details"},e("div",{class:"license__name"},(c=s===null||s===void 0?void 0:s.product)===null||c===void 0?void 0:c.name),e("div",null,this.renderStatus(i)," ",wp.i18n.sprintf(wp.i18n.__("%1s of %2s Activations Used"),n||0,a||"∞"))),e("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var t,s;return e("sc-dashboard-module",{key:"9a275f0ffb7bdddcf72f025a2710a0483cadeac1",class:"purchase",part:"base",error:this.error},e("span",{key:"d17f7223640f58cfcdd82d1c047fc7f4944b34f5",slot:"heading"},e("slot",{key:"e6a466fd0024df20dc79c49f78bcd362e2f3d32c",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:"851aab21ab6f1f7d3933ec52ad1225f9e079f186",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),e("sc-icon",{key:"100a7992d865f30ee2007cd92226eb94ac50f4f9",name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&e("sc-pagination",{key:"8f08068489c332c9c51565f32beca4173b039b4e",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)}};o.style=c;export{o as sc_licenses_list};
//# sourceMappingURL=p-f319abac.entry.js.map