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-6135d661.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 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()}))}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 o;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"},(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,a||"∞"))),e("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var t;return e("sc-dashboard-module",{key:"5fca3fe2d936824b5a5d05cf056436d2618e37c5",class:"purchase",part:"base",error:this.error},e("span",{key:"f77dc153da8da257c194cda3cddd767a71f02dd8",slot:"heading"},e("slot",{key:"5a7e5e54c9ad2d882b40f04e83302f2035103de1",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:"8426296f2e7bb8c298672b67766286bc13a5aa51",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),e("sc-icon",{key:"2dbb9966fe39e845b7194f8576a01461df69ba0d",name:"chevron-right",slot:"suffix"})),this.renderContent())}get el(){return s(this)}};c.style=o;export{c as sc_licenses_list};
//# sourceMappingURL=p-5f116bbf.entry.js.map