1import{k as z,r as l,e as p,t as o,j as e,h as X,o as Y,C as G}from"./edge-BOITG1XR.js";import{D as J}from"./mod-LfxHWGtW.js";import{P as W}from"./mod-BHbsKpbp.js";import{S as Z}from"./mod-CKg_ZYcm.js";import{R as ee}from"./mod-RPxq32x0.js";import{L as k}from"./mod-DxqX0N6D.js";import{K as M}from"./mod-BBgDTOoh.js";import{C as se}from"./mod-BelLWb3f.js";import{R as te}from"./mod-CKYw6KsV.js";import{S as A}from"./mod-DdNgOIQN.js";import{T as ae}from"./mod-BuHkwEt_.js";import{C as le}from"./mod-qF7UVkYF.js";import{X as P}from"./mod-C3kaoPgB.js";import{S as ie}from"./mod-C9xhOiHj.js";const ne=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],D=z("calendar-plus",ne);const ce=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],re=z("ellipsis-vertical",ce),R=i=>i?new Date(i).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"}):"â",oe=({lic:i})=>i.is_active?i.is_trial?e.jsx("span",{className:"rounded-full px-2 py-0.5 text-xs font-semibold bg-violet-100 text-violet-600",children:"Trial"}):e.jsx("span",{className:"rounded-full px-2 py-0.5 text-xs font-semibold bg-emerald-100 text-emerald-600",children:"Active"}):e.jsx("span",{className:"rounded-full px-2 py-0.5 text-xs font-semibold bg-rose-100 text-rose-600",children:"Inactive"}),$={license_product_id:"",authorized_email:"",max_activations:1,expires_at:"",notes:"",quantity:1};function ke(){const[i,I]=l.useState([]),[d,K]=l.useState({}),[_,C]=l.useState(!0),[v,T]=l.useState(""),[y,q]=l.useState(""),[u,h]=l.useState(1),[F,S]=l.useState(null),[O,U]=l.useState([]),[N,c]=l.useState(null),[r,b]=l.useState($),[f,j]=l.useState(!1),[E,g]=l.useState(null),x=l.useCallback(async()=>{C(!0);try{const s=await p.get("/admin/digilicense/licenses",{params:{search:v,status:y,page:u,per_page:25}}),t=s.data?.data??s.data;I(t?.data??t??[]),K({total:t?.total,last_page:t?.last_page,current_page:t?.current_page})}catch{o.error("Failed to load licenses")}finally{C(!1)}},[v,y,u]);l.useEffect(()=>{x()},[x]),l.useEffect(()=>{p.get("/admin/digilicense/products").then(s=>U(s.data?.data??s.data??[])).catch(()=>{})},[]);const V=(s,t)=>{navigator.clipboard.writeText(t),S(s),o.success("Copied"),setTimeout(()=>S(null),2e3)},m=async(s,t="post",n={},a="Done")=>{try{await p[t](s,n),o.success(a),g(null),x()}catch(w){o.error(w.response?.data?.message??"Action failed")}},L=s=>t=>b(n=>({...n,[s]:t.target.value})),B=async()=>{j(!0);try{await p.post("/admin/digilicense/licenses",{...r,quantity:parseInt(r.quantity)||1}),o.success("License(s) created"),c(null),x()}catch(s){o.error(s.response?.data?.message??"Create failed")}finally{j(!1)}},H=async()=>{if(r.days){j(!0);try{await p.post(`/admin/digilicense/licenses/${N.license.id}/extend`,{days:parseInt(r.days)}),o.success("License extended"),c(null),x()}catch(s){o.error(s.response?.data?.message??"Extend failed")}finally{j(!1)}}},Q=()=>{const s=[["ID","License Key","Email","Product","Activations","Expires","Status"]];i.forEach(a=>s.push([a.id,a.license_key,a.authorized_email??"",a.license_product?.name??"",`${a.current_activations}/${a.max_activations??a.activation_limit}`,R(a.expires_at),a.is_active?"Active":"Inactive"]));const t=s.map(a=>a.map(w=>`"${String(w).replace(/"/g,'""')}"`).join(",")).join(` 2`),n=document.createElement("a");n.href="data:text/csv;charset=utf-8,"+encodeURIComponent(t),n.download="licenses.csv",n.click()};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-800",children:"License Keys"}),e.jsxs("p",{className:"text-sm text-slate-500",children:[d.total??"â"," total"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Q,className:"flex items-center gap-1.5 rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm text-slate-600 hover:bg-slate-50",children:[e.jsx(J,{className:"h-4 w-4"})," Export"]}),e.jsxs("button",{onClick:()=>{b($),c("create")},className:"flex items-center gap-2 rounded-xl bg-blue-600 text-white px-4 py-2 text-sm font-medium hover:bg-blue-700",children:[e.jsx(W,{className:"h-4 w-4"})," New Key"]})]})]}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-48",children:[e.jsx(Z,{className:"absolute left-3 top-2.5 h-4 w-4 text-slate-400"}
2),e.jsx("input",{value:v,onChange:s=>{T(s.target.value),h(1)},placeholder:"Search key or emailâ¦",className:"w-full pl-9 pr-4 py-2 rounded-xl border border-slate-200 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("select",{value:y,onChange:s=>{q(s.target.value),h(1)},className:"rounded-xl border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"inactive",children:"Inactive"}),e.jsx("option",{value:"trial",children:"Trial"}),e.jsx("option",{value:"expired",children:"Expired"})]}),e.jsx("button",{onClick:x,className:"rounded-xl border border-slate-200 p-2 hover:bg-slate-50",children:e.jsx(ee,{className:X("h-4 w-4 text-slate-500",_&&"animate-spin")})})]}),e.jsx("div",{className:"rounded-2xl bg-white border border-slate-100 shadow-sm overflow-hidden",onClick:()=>g(null),children:_?e.jsx("div",{className:"p-8 text-center",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-slate-400 mx-auto"})}):i.length===0?e.jsxs("div",{className:"p-12 text-center",children:[e.jsx(M,{className:"h-8 w-8 text-slate-300 mx-auto mb-2"}),e.jsx("p",{className:"text-slate-500",children:"No licenses found"})]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-100",children:e.jsx("tr",{children:["License Key","Email","Product","Activations","Expires","Status",""].map(s=>e.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-slate-500 uppercase tracking-wide",children:s},s))})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:i.map(s=>e.jsxs("tr",{className:"hover:bg-slate-50/50",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"text-xs font-mono bg-slate-100 rounded px-1.5 py-0.5",children:s.license_key}),e.jsx("button",{onClick:()=>V(s.id,s.license_key),className:"text-slate-400 hover:text-slate-600",children:F===s.id?e.jsx(Y,{className:"h-3.5 w-3.5 text-emerald-500"}):e.jsx(se,{className:"h-3.5 w-3.5"})})]})}),e.jsx("td",{className:"px-4 py-3 text-slate-600 max-w-32 truncate",children:s.authorized_email??s.user?.email??"â"}),e.jsx("td",{className:"px-4 py-3 text-slate-600",children:s.license_product?.name??"â"}),e.jsxs("td",{className:"px-4 py-3 text-slate-600",children:[s.current_activations??0," / ",s.max_activations??s.activation_limit??"â"]}),e.jsx("td",{className:"px-4 py-3 text-slate-500",children:R(s.expires_at)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(oe,{lic:s})}),e.jsxs("td",{className:"px-4 py-3 relative",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),g(E===s.id?null:s.id)},className:"rounded-lg p-1.5 hover:bg-slate-100 text-slate-500",children:e.jsx(re,{className:"h-4 w-4"})}),E===s.id&&e.jsxs("div",{className:"absolute right-8 top-2 z-10 w-44 rounded-xl bg-white border border-slate-200 shadow-lg py-1 text-sm",onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>m(`/admin/digilicense/licenses/${s.id}/reset`,"post",{},"Activations reset"),className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-slate-50 text-slate-700",children:[e.jsx(te,{className:"h-3.5 w-3.5"}),"Reset Activations"]}),e.jsxs("button",{onClick:()=>{b({days:30}),c({action:"extend",license:s}),g(null)},className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-slate-50 text-slate-700",children:[e.jsx(D,{className:"h-3.5 w-3.5"}),"Extend"]}),s.is_active?e.jsxs("button",{onClick:()=>m(`/admin/digilicense/licenses/${s.id}/suspend`,"post",{},"Suspended"),className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-slate-50 text-amber-600",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),"Suspend"]}):e.jsxs("button",{onClick:()=>m(`/admin/digilicense/licenses/${s.id}/unsuspend`,"post",{},"Unsuspended"),className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-slate-50 text-emerald-600",children:[e.jsx(M,{className:"h-3.5 w-3.5"}),"Unsuspend"]}),e.jsx("hr",{className:"my-1 border-slate-100"}),e.jsxs("button",{onClick:()=>m(`/admin/digilicense/licenses/${s.id}/revoke`,"post",{reason:"Admin revoke"},"Revoked"),className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-rose-50 text-rose-600",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),"Revoke"]}),e.jsxs("button",{onClick:()=>{confirm("Delete this license?")&&m(`/admin/digilicense/licenses/${s.id}`,"delete",{},"Deleted")},className:"flex w-full items-center gap-2 px-4 py-2 hover:bg-rose-50 text-rose-600",children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]},s.id))})]})}),d.last_page>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-slate-500",children:["Page ",d.current_page," of ",d.last_page]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>h(s=>Math.max(1,s-1)),disabled:u===1,className:"rounded-xl border border-slate-200 p-2 disabled:opacity-40 hover:bg-slate-50",children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>h(s=>Math.min(d.last_page,s+1)),disabled:u===d.last_page,className:"rounded-xl border border-slate-200 p-2 disabled:opacity-40 hover:bg-slate-50",children:e.jsx(G,{className:"h-4 w-4"})})]})]}),N==="create"&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-white shadow-xl",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-100 px-6 py-4",children:[e.jsx("h2",{className:"font-semibold text-slate-800",children:"New License Key"}),e.jsx("button",{onClick:()=>c(null),children:e.jsx(P,{className:"h-5 w-5 text-slate-400"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-slate-600",children:"Product *"}),e.jsxs("select",{value:r.license_product_id,onChange:L("license_product_id"),className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"Select productâ¦"}),O.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]})]}),[{label:"Authorized Email",key:"authorized_email",type:"email",placeholder:"[email protected]"},{label:"Max Activations",key:"max_activations",type:"number",placeholder:"1"},{label:"Expires At",key:"expires_at",type:"date",placeholder:""},{label:"Quantity",key:"quantity",type:"number",placeholder:"1"},{label:"Notes",key:"notes",type:"text",placeholder:"Optional"}].map(({label:s,key:t,type:n,placeholder:a})=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-slate-600",children:s}),e.jsx("input",{type:n,value:r[t]??"",onChange:L(t),placeholder:a,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]},t))]}),e.jsxs("div",{className:"flex justify-end gap-3 border-t border-slate-100 px-6 py-4",children:[e.jsx("button",{onClick:()=>c(null),className:"rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-600 hover:bg-slate-50",children:"Cancel"}),e.jsxs("button",{onClick:B,disabled:f||!r.license_product_id,className:"flex items-center gap-2 rounded-xl bg-blue-600 text-white px-4 py-2 text-sm font-medium hover:bg-blue-700 disabled:opacity-60",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(ie,{className:"h-4 w-4"})," Create"]})]})]})}),N?.action==="extend"&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{className:"w-full max-w-sm rounded-2xl bg-white shadow-xl",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-100 px-6 py-4",children:[e.jsx("h2",{className:"font-semibold text-slate-800",children:"Extend License"}),e.jsx("button",{onClick:()=>c(null),children:e.jsx(P,{className:"h-5 w-5 text-slate-400"})})]}),e.jsx("div",{className:"p-6",children:e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-slate-600",children:"Days to extend"}),e.jsx("input",{type:"number",min:"1",value:r.days??30,onChange:s=>b(t=>({...t,days:s.target.value})),className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]})}),e.jsxs("div",{className:"flex justify-end gap-3 border-t border-slate-100 px-6 py-4",children:[e.jsx("button",{onClick:()=>c(null),className:"rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-600 hover:bg-slate-50",children:"Cancel"}),e.jsxs("button",{onClick:H,disabled:f,className:"flex items-center gap-2 rounded-xl bg-blue-600 text-white px-4 py-2 text-sm font-medium hover:bg-blue-700 disabled:opacity-60",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(D,{className:"h-4 w-4"})," Extend"]})]})]})})]})}export{ke as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.