1import{d as c,j as e}from"./react-vendor-BYeqKmV6.js";import{aE as g,aD as i,a1 as A,e as P,k as H,B as x,f as _,i as O,j as $,g as F,h as K,d as z}from"./index-C5_t1zCf.js";import{B as m}from"./badge-DDIK1BT-.js";import{C as l,a as o,d as J,e as Q,b as X}from"./card-CpuziIzR.js";import{I as f}from"./input-D3p5gISb.js";import{L as v}from"./label-BjIbRJ8Q.js";import{T as q,d as V,e as D,c as r,a as W,b as a}from"./table-BVyRy5sJ.js";import{T as E,c as I,a as L}from"./tooltip-Cp3oS7K4.js";import{K as N}from"./key-round-DHnA-xHk.js";import{P as Y}from"./plus-CNbRgllw.js";import{L as U}from"./loader-circle-KzlnbA1r.js";import{S as Z}from"./send-CL9StcTN.js";import{C as ee}from"./circle-x-D0HO2Dwk.js";import"./ui-vendor-FeF8SYpf.js";import"./data-vendor-JFafzwTy.js";const b="Gotomarket2026",R=`https://t.me/${b}`;function se(t,h,n,d){return t==="revoked"?e.jsx(m,{variant:"destructive",children:"Revoked"}):d&&new Date(d)<new Date?e.jsx(m,{variant:"outline",className:"text-muted-foreground",children:"Expired"}):n>0&&h>=n?e.jsx(m,{variant:"secondary",children:"Used up"}):e.jsx(m,{className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 border-0",children:"Active"})}function ge(){const{data:t,isLoading:h,refetch:n}=g.adminSupplier.listInviteCodes.useQuery(),[d,u]=c.useState(!1),[C,w]=c.useState(""),[y,k]=c.useState(1),[p,S]=c.useState(""),j=g.adminSupplier.createInviteCode.useMutation({onSuccess:s=>{i.success(`Invite code created: ${s?.code}`),u(!1),w(""),k(1),S(""),n()},onError:s=>i.error(A(s))}),T=g.adminSupplier.revokeInviteCode.useMutation({onSuccess:()=>{i.success("Invite code revoked"),n()},onError:s=>i.error(A(s))}),G=s=>{navigator.clipboard.writeText(s).then(()=>{i.success(`Copied: ${s}`)})},M=t?.filter(s=>s.status==="active"&&(!s.expiresAt||new Date(s.expiresAt)>new Date)&&(s.maxUses===0||s.usedCount<s.maxUses)).length??0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(N,{className:"w-6 h-6 text-primary"}),"Supplier Invite Codes"]}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:"Generate invite codes for supplier registration. Each supplier must enter a valid code before signing up."})]}),e.jsxs(P,{open:d,onOpenChange:u,children:[e.jsx(H,{asChild:!0,children:e.jsxs(x,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Generate Code"]})}),e.jsxs(_,{className:"max-w-sm",children:[e.jsxs(O,{children:[e.jsx($,{children:"Generate Invite Code"}),e.jsx(F,{children:"A random code will be generated. Share it with the supplier via Telegram or other channels."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{children:"Note (optional)"}),e.jsx(f,{placeholder:"e.g. For John Smith",value:C,onChange:s=>w(s.target.value),maxLength:256}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Internal label â not shown to the supplier"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{children:"Max Uses"}),e.jsx(f,{type:"number",min:0,max:1e3,value:y,onChange:s=>k(parseInt(s.target.value)||1)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"0 = unlimited uses"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{children:"Expires At (optional)"}),e.jsx(f,{type:"datetime-local",value:p,onChange:s=>S(s.target.value)})]})]}),e.jsxs(K,{children:[e.jsx(x,{variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsxs(x,{disabled:j.isPending,onClick:()=>j.mutate({note:C||void 0,maxUses:y,expiresAt:p?new Date(p).toISOString():null}),children:[j.isPending?e.jsx(U,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(N,{className:"w-4 h-4 mr-2"}),"Generate"]})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(l,{children:e.jsxs(o,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Codes"}),e.jsx("p",{className:"text-2xl font-bold",children:t?.length??0})]})}),e.jsx(l,{children:e.jsxs(o,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Active"}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:M})]})}),e.jsx(l,{children:e.jsxs(o,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Used"}),e.jsx("p",{className:"text-2xl font-bold",children:t?.reduce((s,B)=>s+B.usedCount,0)??0})]})}),e.jsx(l,{className:"bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-800",children:e.jsxs(o,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300 font-medium",children:"Contact Channel"}),e.jsxs("a",{href:R,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 mt-1 text-blue-600 dar
1k:text-blue-400 hover:underline text-sm font-semibold",children:[e.jsx(Z,{className:"w-3.5 h-3.5"}),"@",b]})]})})]}),e.jsxs(l,{children:[e.jsxs(J,{className:"pb-3",children:[e.jsx(Q,{className:"text-base",children:"All Invite Codes"}),e.jsxs(X,{children:["Share codes with suppliers via Telegram"," ",e.jsxs("a",{href:R,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:["@",b]}),". Suppliers must enter the code before registering."]})]}),e.jsx(o,{className:"p-0",children:h?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(U,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):t?.length?e.jsxs(q,{children:[e.jsx(V,{children:e.jsxs(D,{children:[e.jsx(r,{children:"Code"}),e.jsx(r,{children:"Note"}),e.jsx(r,{children:"Status"}),e.jsx(r,{children:"Uses"}),e.jsx(r,{children:"Expires"}),e.jsx(r,{children:"Created"}),e.jsx(r,{className:"text-right",children:"Actions"})]})}),e.jsx(W,{children:t.map(s=>e.jsxs(D,{children:[e.jsx(a,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"font-mono text-sm font-semibold tracking-wider bg-muted px-2 py-0.5 rounded",children:s.code}),e.jsxs(E,{children:[e.jsx(I,{asChild:!0,children:e.jsx("button",{onClick:()=>G(s.code),className:"text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(z,{className:"w-3.5 h-3.5"})})}),e.jsx(L,{children:"Copy code"})]})]})}),e.jsx(a,{className:"text-muted-foreground text-sm max-w-[160px] truncate",children:s.note||"â"}),e.jsx(a,{children:se(s.status,s.usedCount,s.maxUses,s.expiresAt?s.expiresAt.toString():null)}),e.jsxs(a,{className:"text-sm",children:[s.usedCount," / ",s.maxUses===0?"â":s.maxUses]}),e.jsx(a,{className:"text-sm text-muted-foreground",children:s.expiresAt?new Date(s.expiresAt).toLocaleDateString():"Never"}),e.jsx(a,{className:"text-sm text-muted-foreground",children:new Date(s.createdAt).toLocaleDateString()}),e.jsxs(a,{className:"text-right",children:[s.status==="active"&&e.jsxs(E,{children:[e.jsx(I,{asChild:!0,children:e.jsx(x,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive hover:bg-destructive/10",disabled:T.isPending,onClick:()=>T.mutate({id:s.id}),children:e.jsx(ee,{className:"w-4 h-4"})})}),e.jsx(L,{children:"Revoke code"})]}),s.status==="revoked"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Revoked"})]})]},s.id))})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(N,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No invite codes yet. Generate one to get started."})]})})]})]})}export{ge 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.