import{r as t,h as e,a as s}from"./p-9add63ef.js";import{o as i}from"./p-b719a497.js";import"./p-445fd8b4.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"),n||0,r||"∞"))),e("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var t,s;return e("sc-dashboard-module",{key:"e0d20b22a4337be1f0c7711d46ff1f09db9f7d27",class:"purchase",part:"base",error:this.error},e("span",{key:"eafb14077ebc3ed1ce3a96be308d91b830d82782",slot:"heading"},e("slot",{key:"caf47d40166ac37d865970ffbf4c7821c40ac439",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:"f78bbd5f471ebd853adc87c8909c24a5b323d4dd",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),e("sc-icon",{key:"692e4e7fe442969fc2051390118e0f60bc28ad88",name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&e("sc-pagination",{key:"7de25ba69f9c0b066081bdae607fdd75f3ffdf39",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-cccbaf87.entry.js.map