import{r as e,h as t,a as s}from"./p-e97fde0a.js";import{o as i}from"./p-b719a497.js";import{a}from"./p-d9fa04f9.js";import{a as r}from"./p-401e165e.js";import"./p-d3366af3.js";const c=":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 n=c;const o=class{constructor(t){e(this,t);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(e){console.error(e);this.error=(e===null||e===void 0?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}async getLicenses(){if(!this.isCustomer){return}const e=await await a({path:r("surecart/v1/licenses",{expand:["purchase","purchase.product","activations"],...this.query}),parse:false});this.pagination={total:parseInt(e.headers.get("X-WP-Total")),total_pages:parseInt(e.headers.get("X-WP-TotalPages"))};this.licenses=await e.json();return this.licenses}renderStatus(e){if(e==="active"){return t("sc-tag",{type:"success"},wp.i18n.__("Active","surecart"))}if(e==="revoked"){return t("sc-tag",{type:"danger"},wp.i18n.__("Revoked","surecart"))}if(e==="inactive"){return t("sc-tag",{type:"info"},wp.i18n.__("Not Activated","surecart"))}return t("sc-tag",{type:"info"},e)}async copyKey(e){try{await navigator.clipboard.writeText(e);this.copied=true;setTimeout((()=>{this.copied=false}),2e3)}catch(e){console.error(e);alert(wp.i18n.__("Error copying to clipboard","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%",marginBottom:"0.75em"}}),t("sc-skeleton",{style:{width:"40%"}})))))}renderEmpty(){return t("div",null,t("sc-divider",{style:{"--spacing":"0"}}),t("slot",{name:"empty"},t("sc-empty",{icon:"file-text"},wp.i18n.__("You don't have any licenses.","surecart"))))}renderContent(){var e,s;if(this.loading){return this.renderLoading()}if(((e=this.licenses)===null||e===void 0?void 0:e.length)===0){return this.renderEmpty()}return t("sc-card",{"no-padding":true},t("sc-stacked-list",null,(s=this.licenses)===null||s===void 0?void 0:s.map((({id:e,purchase:s,status:i,activation_limit:a,activation_count:c})=>{var n;return t("sc-stacked-list-row",{key:e,href:r(window.location.href,{action:"show",model:"license",id:e}),"mobile-size":0},t("div",{class:"license__details"},t("div",{class:"license__name"},(n=s===null||s===void 0?void 0:s.product)===null||n===void 0?void 0:n.name),t("div",null,this.renderStatus(i)," ",wp.i18n.sprintf(wp.i18n.__("%1s of %2s Activations Used"),c||0,a||"∞"))),t("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var e;return t("sc-dashboard-module",{key:"fc989681ab3152e9ec3dc7606cb1cf0bd9dd1444",class:"purchase",part:"base",error:this.error},t("span",{key:"a5b82af04312192c00355eac1ac9f09122a657dd",slot:"heading"},t("slot",{key:"f723eb7bd5ca0a862e15576fa4923ad12ab241bd",name:"heading"},this.heading||wp.i18n.__("License Keys","surecart"))),!!this.allLink&&!!((e=this.licenses)===null||e===void 0?void 0:e.length)&&t("sc-button",{key:"f2c77bbc3b501ac0949cb55ac6ca4211e7392e3b",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),t("sc-icon",{key:"fd935365e1bb1ee04dce5053614cc1d3fd4992b5",name:"chevron-right",slot:"suffix"})),this.renderContent())}get el(){return s(this)}};o.style=n;export{o as sc_licenses_list};
//# sourceMappingURL=p-7933c9e8.entry.js.map