PageSourceSearch

https://smartmentor.ai/assets/AdminDashboard.CkKc9HF2.js

js smartmentor.ai collected 2026-10-05 16:21:26 UTC 438,642 bytes, 1 lines download raw bytes

1import{j as e,g as t,P as s,Q as r,H as a,G as l,O as n,y as o,m as i,d}from"./vendor-ui-core.DP8knyZn.js";import{r as c,f as u}from"./vendor-react.BBoGJFYM.js";import{k as x,e as p,j as m,s as h,C as g,E as b,F as y,G as f,J as v,p as j,u as w,L as N,D as k,K as _,o as C,q as B,r as T,M as S,N as $,B as F,O as A,w as R,m as E,Q as L,t as D,I as M,S as I,H as P,R as U,T as O,U as z}from"./index.CdjOtu-m.js";import{L as H,a as q,b as W,c as V}from"./vendor-ui-display.BT2Z6Vpo.js";import{aJ as G,L as K,k as Y,l as J,a5 as Q,aL as X,aO as Z,e as ee,aK as te,aP as se,R as re,aQ as ae,m as le,D as ne,F as oe,a0 as ie,p as de,x as ce,am as ue,aR as xe,ac as pe,aj as me,aS as he,T as ge,q as be,X as ye,aT as fe,aU as ve,aV as je,b as we,aW as Ne,aX as ke,U as _e,a3 as Ce,aY as Be,aZ as Te,O as Se,a_ as $e,ad as Fe,av as Ae,a$ as Re,b0 as Ee,z as Le,r as De,f as Me,c as Ie,g as Pe,b1 as Ue,b2 as Oe,b3 as ze,E as He,b4 as qe,_ as We,b5 as Ve,b6 as Ge,b7 as Ke,b8 as Ye,y as Je,ak as Qe,b9 as Xe,ba as Ze,bb as et,aF as tt,bc as st,bd as rt,an as at,be as lt,bf as nt,bg as ot,d as it,aa as dt,bh as ct,bi as ut,bj as xt,bk as pt,bl as mt,bm as ht,bn as gt,bo as bt,bp as yt,at as ft,bq as vt,br as jt,bs as wt,aN as Nt,aE as kt,A as _t,o as Ct,bt as Bt,h as Tt}from"./vendor-icons.BjAWwE8z.js";import{a as St,b as $t}from"./vendor-utils.BlEnRQrd.js";import{S as Ft}from"./switch.CbirtM2y.js";import{A as At,h as Rt,a as Et,b as Lt,c as Dt,d as Mt,e as It,f as Pt,g as Ut}from"./alert-dialog.DmbxRrbo.js";import{R as Ot,B as zt,C as Ht,X as qt,Y as Wt,T as Vt,a as Gt,b as Kt,c as Yt,d as Jt}from"./vendor-charts.RWeJ_I16.js";import"./vendor-supabase.DS-aP8MZ.js";import"./vendor-ui-forms.CjLBxE3d.js";import"./vendor-query.CfjDb5WU.js";import"./vendor-media.DY6E_qVO.js";import"./vendor-motion.DCvbjL6b.js";const Qt=V;c.forwardRef(({className:t,...s},r)=>e.jsx(H,{ref:r,className:x("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t),...s})).displayName=H.displayName;c.forwardRef(({className:t,...s},r)=>e.jsx(q,{ref:r,className:x("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",t),...s})).displayName=q.displayName;const Xt=c.forwardRef(({className:t,...s},r)=>e.jsx(W,{ref:r,className:x("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...s}));Xt.displayName=W.displayName;var Zt=.999,es=/[\\\/_+.#"@\[\(\{&]/,ts=/[\\\/_+.#"@\[\(\{&]/g,ss=/[\s-]/,rs=/[\s-]/g;function as(e,t,s,r,a,l,n){if(l===t.length)return a===e.length?1:.99;var o=`${a},${l}`;if(void 0!==n[o])return n[o];for(var i,d,c,u,x=r.charAt(l),p=s.indexOf(x,a),m=0;p>=0;)(i=as(e,t,s,r,p+1,l+1,n))>m&&(p===a?i*=1:es.test(e.charAt(p-1))?(i*=.8,(c=e.slice(a,p-1).match(ts))&&a>0&&(i*=Math.pow(Zt,c.length))):ss.test(e.charAt(p-1))?(i*=.9,(u=e.slice(a,p-1).match(rs))&&a>0&&(i*=Math.pow(Zt,u.length))):(i*=.17,a>0&&(i*=Math.pow(Zt,p-a))),e.charAt(p)!==t.charAt(l)&&(i*=.9999)),(i<.1&&s.charAt(p-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&s.charAt(p-1)!==r.charAt(l))&&(.1*(d=as(e,t,s,r,p+1,l+2,n))>i&&(i=.1*d)),i>m&&(m=i),p=s.indexOf(x,p+1);return n[o]=m,m}function ls(e){return e.toLowerCase().replace(rs," ")}function ns(e,t,s){return as(e=s&&s.length>0?""+(e+" "+s.join(" ")):e,t,ls(e),ls(t),0,0,{})}var os='[cmdk-group=""]',is='[cmdk-group-items=""]',ds='[cmdk-item=""]',cs=`${ds}:not([aria-disabled="true"])`,us="cmdk-item-select",xs="data-value",ps=(e,t,s)=>ns(e,t,s),ms=c.createContext(void 0),hs=()=>c.useContext(ms),gs=c.createContext(void 0),bs=()=>c.useContext(gs),ys=c.createContext(void 0),fs=c.forwardRef((e,r)=>{let a=Rs(()=>{var t,s;return{search:"",value:null!=(s=null!=(t=e.value)?t:e.defaultValue)?s:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),l=Rs(()=>new Set),n=Rs(()=>new Map),o=Rs(()=>new Map),i=Rs(()=>new Set),d=Fs(e),{label:u,children:x,value:p,onValueChange:m,filter:h,shouldFilter:g,loop:b,disablePointerSelection:y=!1,vimBindings:f=!0,...v}=e,j=t(),w=t(),N=t(),k=c.useRef(null),_=Ds();As(()=>
1{if(void 0!==p){let e=p.trim();a.current.value=e,C.emit()}},[p]),As(()=>{_(6,A)},[]);let C=c.useMemo(()=>({subscribe:e=>(i.current.add(e),()=>i.current.delete(e)),snapshot:()=>a.current,setState:(e,t,s)=>{var r,l,n,o;if(!Object.is(a.current[e],t)){if(a.current[e]=t,"search"===e)F(),S(),_(1,$);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(N);e?e.focus():null==(r=document.getElementById(j))||r.focus()}if(_(7,()=>{var e;a.current.selectedItemId=null==(e=R())?void 0:e.id,C.emit()}),s||_(5,A),void 0!==(null==(l=d.current)?void 0:l.value)){let e=null!=t?t:"";return void(null==(o=(n=d.current).onValueChange)||o.call(n,e))}}C.emit()}},emit:()=>{i.current.forEach(e=>e())}}),[]),B=c.useMemo(()=>({value:(e,t,s)=>{var r;t!==(null==(r=o.current.get(e))?void 0:r.value)&&(o.current.set(e,{value:t,keywords:s}),a.current.filtered.items.set(e,T(t,s)),_(2,()=>{S(),C.emit()}))},item:(e,t)=>(l.current.add(e),t&&(n.current.has(t)?n.current.get(t).add(e):n.current.set(t,new Set([e]))),_(3,()=>{F(),S(),a.current.value||$(),C.emit()}),()=>{o.current.delete(e),l.current.delete(e),a.current.filtered.items.delete(e);let t=R();_(4,()=>{F(),(null==t?void 0:t.getAttribute("id"))===e&&$(),C.emit()})}),group:e=>(n.current.has(e)||n.current.set(e,new Set),()=>{o.current.delete(e),n.current.delete(e)}),filter:()=>d.current.shouldFilter,label:u||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:j,inputId:N,labelId:w,listInnerRef:k}),[]);function T(e,t){var s,r;let l=null!=(r=null==(s=d.current)?void 0:s.filter)?r:ps;return e?l(e,a.current.search,t):0}function S(){if(!a.current.search||!1===d.current.shouldFilter)return;let e=a.current.filtered.items,t=[];a.current.filtered.groups.forEach(s=>{let r=n.current.get(s),a=0;r.forEach(t=>{let s=e.get(t);a=Math.max(s,a)}),t.push([s,a])});let s=k.current;E().sort((t,s)=>{var r,a;let l=t.getAttribute("id"),n=s.getAttribute("id");return(null!=(r=e.get(n))?r:0)-(null!=(a=e.get(l))?a:0)}).forEach(e=>{let t=e.closest(is);t?t.appendChild(e.parentElement===t?e:e.closest(`${is} > *`)):s.appendChild(e.parentElement===s?e:e.closest(`${is} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let s=null==(t=k.current)?void 0:t.querySelector(`${os}[${xs}="${encodeURIComponent(e[0])}"]`);null==s||s.parentElement.appendChild(s)})}function $(){let e=E().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(xs);C.setState("value",t||void 0)}function F(){var e,t,s,r;if(!a.current.search||!1===d.current.shouldFilter)return void(a.current.filtered.count=l.current.size);a.current.filtered.groups=new Set;let i=0;for(let n of l.current){let l=T(null!=(t=null==(e=o.current.get(n))?void 0:e.value)?t:"",null!=(r=null==(s=o.current.get(n))?void 0:s.keywords)?r:[]);a.current.filtered.items.set(n,l),l>0&&i++}for(let[l,o]of n.current)for(let e of o)if(a.current.filtered.items.get(e)>0){a.current.filtered.groups.add(l);break}a.current.filtered.count=i}function A(){var e,t,s;let r=R();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(s=null==(t=r.closest(os))?void 0:t.querySelector('[cmdk-group-heading=""]'))||s.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function R(){var e;return null==(e=k.current)?void 0:e.querySelector(`${ds}[aria-selected="true"]`)}function E(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(cs))||[])}function L(e){let t=E()[e];t&&C.setState("value",t.getAttribute(xs))}function D(e){var t;let s=R(),r=E(),a=r.findIndex(e=>e===s),l=r[a+e];null!=(t=d.current)&&t.loop&&(l=a+e<0?r[r.length-1]:a+e===r.length?r[0]:r[a+e]),l&&C.setState("value",l.getAttribute(xs))}function M(e){let t,s=R(),r=null==s?void 0:s.closest(os);for(;r&&!t;)r=e>0?Ss(r,os):$s(r,os),t=null==r?void 0:r.querySelector(cs);t?C.setState("value",t.getAttribute(xs)):D(e)}let I=()=>L(E().length-1),P=e=>{e.preventDefault(),e.metaKey?I():e.altKey?M(1):D(1)},U=e=>{e.preventDefault(),e.metaKey?L(0):e.altKey?M(-1):D(-1)};return c.createElement(s.div,{ref:r,tabIndex:-1,...v,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=v.onKeyDown)||t.call(v,e);let s=e.nativeEvent.isComposing||229===e.keyCode;if(!e.defaultPrevented&&!s)switch(e.key){case"n":case"j":f&&e.ctrlKey&&P(e);break;case"ArrowDown":P(e);break;case"p":case"k":f&&e.ctrlKey&&U(e);break;case"ArrowUp":U(e);break;case"Home":e.preventDefault(),L(0);break;case"End":e.preventDefault(),I();break;case"Enter":{e.preventDefault();let t=R();if(t){let e=new Event(us);t.dispatchEvent(e)}}}}},c.createElement("label",{"cmdk-label":"",htmlFor:B.inputId,id:B.labelId,style:Is},u),Ms(e,e=>c.createElement(gs.Provider,{value:C},c.createElement(ms.Provider,{value:B},e))))}),vs=c.forwardRef((e,a)=>{var l,n;let o=t(),i=c.useRef(null),d=c.useContext(ys),u=hs(),x=Fs(e),p=null!=(n=null==(l=x.current)?void 0:l.forceMount)?n:null==d?void 0:d.forceMount;As(()=>
1{if(!p)return u.item(o,null==d?void 0:d.id)},[p]);let m=Ls(o,i,[e.value,e.children,i],e.keywords),h=bs(),g=Es(e=>e.value&&e.value===m.current),b=Es(e=>!(!p&&!1!==u.filter())||(!e.search||e.filtered.items.get(o)>0));function y(){var e,t;f(),null==(t=(e=x.current).onSelect)||t.call(e,m.current)}function f(){h.setState("value",m.current,!0)}if(c.useEffect(()=>{let t=i.current;if(t&&!e.disabled)return t.addEventListener(us,y),()=>t.removeEventListener(us,y)},[b,e.onSelect,e.disabled]),!b)return null;let{disabled:v,value:j,onSelect:w,forceMount:N,keywords:k,..._}=e;return c.createElement(s.div,{ref:r(i,a),..._,id:o,"cmdk-item":"",role:"option","aria-disabled":!!v,"aria-selected":!!g,"data-disabled":!!v,"data-selected":!!g,onPointerMove:v||u.getDisablePointerSelection()?void 0:f,onClick:v?void 0:y},e.children)}),js=c.forwardRef((e,a)=>{let{heading:l,children:n,forceMount:o,...i}=e,d=t(),u=c.useRef(null),x=c.useRef(null),p=t(),m=hs(),h=Es(e=>!(!o&&!1!==m.filter())||(!e.search||e.filtered.groups.has(d)));As(()=>m.group(d),[]),Ls(d,u,[e.value,e.heading,x]);let g=c.useMemo(()=>({id:d,forceMount:o}),[o]);return c.createElement(s.div,{ref:r(u,a),...i,"cmdk-group":"",role:"presentation",hidden:!h||void 0},l&&c.createElement("div",{ref:x,"cmdk-group-heading":"","aria-hidden":!0,id:p},l),Ms(e,e=>c.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":l?p:void 0},c.createElement(ys.Provider,{value:g},e))))}),ws=c.forwardRef((e,t)=>{let{alwaysRender:a,...l}=e,n=c.useRef(null),o=Es(e=>!e.search);return a||o?c.createElement(s.div,{ref:r(n,t),...l,"cmdk-separator":"",role:"separator"}):null}),Ns=c.forwardRef((e,t)=>{let{onValueChange:r,...a}=e,l=null!=e.value,n=bs(),o=Es(e=>e.search),i=Es(e=>e.selectedItemId),d=hs();return c.useEffect(()=>{null!=e.value&&n.setState("search",e.value)},[e.value]),c.createElement(s.input,{ref:t,...a,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":d.listId,"aria-labelledby":d.labelId,"aria-activedescendant":i,id:d.inputId,type:"text",value:l?e.value:o,onChange:e=>{l||n.setState("search",e.target.value),null==r||r(e.target.value)}})}),ks=c.forwardRef((e,t)=>{let{children:a,label:l="Suggestions",...n}=e,o=c.useRef(null),i=c.useRef(null),d=Es(e=>e.selectedItemId),u=hs();return c.useEffect(()=>{if(i.current&&o.current){let e,t=i.current,s=o.current,r=new ResizeObserver(()=>{e=requestAnimationFrame(()=>{let e=t.offsetHeight;s.style.setProperty("--cmdk-list-height",e.toFixed(1)+"px")})});return r.observe(t),()=>{cancelAnimationFrame(e),r.unobserve(t)}}},[]),c.createElement(s.div,{ref:r(o,t),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":l,id:u.listId},Ms(e,e=>c.createElement("div",{ref:r(i,u.listInnerRef),"cmdk-list-sizer":""},e)))}),_s=c.forwardRef((e,t)=>{let{open:s,onOpenChange:r,overlayClassName:i,contentClassName:d,container:u,...x}=e;return c.createElement(a,{open:s,onOpenChange:r},c.createElement(l,{container:u},c.createElement(n,{"cmdk-overlay":"",className:i}),c.createElement(o,{"aria-label":e.label,"cmdk-dialog":"",className:d},c.createElement(fs,{ref:t,...x}))))}),Cs=c.forwardRef((e,t)=>Es(e=>0===e.filtered.count)?c.createElement(s.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Bs=c.forwardRef((e,t)=>{let{progress:r,children:a,label:l="Loading...",...n}=e;return c.createElement(s.div,{ref:t,...n,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":l},Ms(e,e=>c.createElement("div",{"aria-hidden":!0},e)))}),Ts=Object.assign(fs,{List:ks,Item:vs,Input:Ns,Group:js,Separator:ws,Dialog:_s,Empty:Cs,Loading:Bs});function Ss(e,t){let s=e.nextElementSibling;for(;s;){if(s.matches(t))return s;s=s.nextElementSibling}}function $s(e,t){let s=e.previousElementSibling;for(;s;){if(s.matches(t))return s;s=s.previousElementSibling}}function Fs(e){let t=c.useRef(e);return As(()=>{t.current=e}),t}var As="undefined"==typeof window?c.useEffect:c.useLayoutEffect;function Rs(e){let t=c.useRef();return void 0===t.current&&(t.current=e()),t}function Es(e){let t=bs(),s=()=>e(t.snapshot());
1return c.useSyncExternalStore(t.subscribe,s,s)}function Ls(e,t,s,r=[]){let a=c.useRef(),l=hs();return As(()=>{var n;let o=(()=>{var e;for(let t of s){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():a.current}})(),i=r.map(e=>e.trim());l.value(e,o,i),null==(n=t.current)||n.setAttribute(xs,o),a.current=o}),a}var Ds=()=>{let[e,t]=c.useState(),s=Rs(()=>new Map);return As(()=>{s.current.forEach(e=>e()),s.current=new Map},[e]),(e,r)=>{s.current.set(e,r),t({})}};function Ms({asChild:e,children:t},s){return e&&c.isValidElement(t)?c.cloneElement(function(e){let t=e.type;return"function"==typeof t?t(e.props):"render"in t?t.render(e.props):e}(t),{ref:t.ref},s(t.props.children)):s(t)}var Is={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Ps=c.forwardRef(({className:t,...s},r)=>e.jsx(Ts,{ref:r,className:x("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...s}));Ps.displayName=Ts.displayName;c.forwardRef(({className:t,...s},r)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(G,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Ts.Input,{ref:r,className:x("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...s})]})).displayName=Ts.Input.displayName;const Us=c.forwardRef(({className:t,...s},r)=>e.jsx(Ts.List,{ref:r,className:x("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...s}));Us.displayName=Ts.List.displayName;const Os=c.forwardRef((t,s)=>e.jsx(Ts.Empty,{ref:s,className:"py-6 text-center text-sm",...t}));Os.displayName=Ts.Empty.displayName;const zs=c.forwardRef(({className:t,...s},r)=>e.jsx(Ts.Group,{ref:r,className:x("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...s}));zs.displayName=Ts.Group.displayName;c.forwardRef(({className:t,...s},r)=>e.jsx(Ts.Separator,{ref:r,className:x("-mx-1 h-px bg-border",t),...s})).displayName=Ts.Separator.displayName;const Hs=c.forwardRef(({className:t,...s},r)=>e.jsx(Ts.Item,{ref:r,className:x("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",t),...s}));Hs.displayName=Ts.Item.displayName;const qs={dark:{sectionBg:"transparent",cardBg:"rgba(255,255,255,0.04)",cardBorder:"rgba(255,255,255,0.09)",tabBg:"rgba(255,255,255,0.04)",tabActiveBg:"rgba(139,92,246,0.28)",tabActiveBorder:"rgba(139,92,246,0.70)",tabHoverBg:"rgba(255,255,255,0.06)",tabText:"rgba(255,255,255,0.50)",tabActiveText:"#ffffff",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.65)",mutedText:"rgba(255,255,255,0.38)",labelText:"rgba(255,255,255,0.55)",accentText:"#a78bfa",inputBg:"rgba(255,255,255,0.05)",inputBorder:"rgba(255,255,255,0.12)",inputFocusBorder:"rgba(139,92,246,0.70)",inputText:"#ffffff",btnBg:"linear-gradient(135deg, #5b21b6 0%, #7c3aed 100%)",btnBorder:"rgba(139,92,246,0.55)",btnText:"#ffffff",divider:"rgba(255,255,255,0.07)",iconBg:"rgba(139,92,246,0.16)",shimmer:"rgba(255,255,255,0.06)",successColor:"#6ee7b7"},light:{sectionBg:"transparent",cardBg:"rgba(255,255,255,0.07)",cardBorder:"rgba(255,255,255,0.14)",tabBg:"rgba(255,255,255,0.06)",tabActiveBg:"rgba(167,139,250,0.28)",tabActiveBorder:"rgba(167,139,250,0.80)",tabHoverBg:"rgba(255,255,255,0.10)",tabText:"rgba(255,255,255,0.55)",tabActiveText:"#ffffff",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.80)",mutedText:"rgba(255,255,255,0.50)",labelText:"rgba(255,255,255,0.65)",accentText:"#c4b5fd",inputBg:"rgba(255,255,255,0.08)",inputBorder:"rgba(255,255,255,0.18)",inputFocusBorder:"rgba(167,139,250,0.80)",inputText:"#ffffff",btnBg:"linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%)",btnBorder:"rgba(167,139,250,0.65)",btnText:"#ffffff",divider:"rgba(255,255,255,0.12)",iconBg:"rgba(167,139,250,0.20)",shimmer:"rgba(255,255,255,0.10)",successColor:"#a7f3d0"}},Ws=[{key:"terms-of-use",label:"Terms of Use",short:"Terms",icon:Q},{key:"privacy-policy",label:"Privacy Policy",short:"Privacy",icon:X},{key:"refund-policy",label:"Refund Policy",short:"Refund",icon:Z},{key:"contact-us",label:"Contact Us",short:"Contact",icon:ee}],Vs=({id:t,value:s,onChange:r,placeholder:a,p:l})=>{const[n,o]=c.useState(!1);return e.jsx("input",{id:t,value:s,onChange:e=>r(e.target.value),placeholder:a,onFocus:()=>o(!0),onBlur:()=>o(!1),className:"w-full rounded-xl px-3.5 py-2.5 text-sm transition-all duration-200 outline-none",style:{background:l.inputBg,border:`1px solid ${n?l.inputFocusBorder:l.inputBorder}`,color:l.inputText,fontFamily:"'Inter', sans-serif",boxShadow:n?`0 0 0 3px ${l.inputFocusBorder}22`:"none"}})},Gs=({id:t,value:s,onChange:r,placeholder:a,p:l})=>{const[n,o]=c.useState(!1);return e.jsx("textarea",{id:t,value:s,onChange:e=>r(e.target.value),placeholder:a,onFocus:()=>o(!0),onBlur:()=>o(!1),className:"w-full rounded-xl px-3.5 py-2.5 text-sm transition-all duration-200 outline-none resize-y font-mono",style:{minHeight:380,background:l.inputBg,border:`1px solid ${n?l.inputFocusBorder:l.inputBorder}
1`,color:l.inputText,lineHeight:1.6,boxShadow:n?`0 0 0 3px ${l.inputFocusBorder}22`:"none"}})},Ks=()=>{const[t,s]=c.useState({}),[r,a]=c.useState(!0),[l,n]=c.useState({}),[o,i]=c.useState({}),[d,u]=c.useState(Ws[0].key),{toast:x}=p(),{resolvedTheme:g}=m(),b="light"===g?qs.light:qs.dark;c.useEffect(()=>{y()},[]);const y=async()=>{a(!0);try{const{data:e,error:t}=await h.from("policy_documents").select("*").order("document_type");if(t)throw t;const r=(e??[]).reduce((e,t)=>(e[t.document_type]=t,e),{});s(r)}catch{x({title:"Error",description:"Failed to fetch policy documents",variant:"destructive"})}finally{a(!1)}},f=(e,t,r)=>{s(s=>({...s,[e]:{...s[e],[t]:r}}))};if(r)return e.jsx("div",{className:"flex items-center justify-center rounded-2xl py-16",style:{background:b.cardBg,border:`1px solid ${b.cardBorder}`},children:e.jsx(K,{className:"w-8 h-8 animate-spin",style:{color:b.accentText}})});const v=Ws.find(e=>e.key===d),j=t[d];return e.jsxs("div",{className:"relative overflow-hidden rounded-2xl transition-all duration-300",style:{background:b.cardBg,border:`1px solid ${b.cardBorder}`,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[e.jsx("div",{"aria-hidden":!0,className:"absolute top-0 left-0 right-0 h-px",style:{background:b.shimmer}}),e.jsx("div",{className:"flex gap-1 p-3 overflow-x-auto",style:{borderBottom:`1px solid ${b.divider}`},role:"tablist","aria-label":"Policy documents",children:Ws.map(t=>{const s=d===t.key,r=t.icon;return e.jsxs("button",{role:"tab","aria-selected":s,"aria-controls":`panel-${t.key}`,id:`tab-${t.key}`,onClick:()=>u(t.key),className:"flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-semibold whitespace-nowrap transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",style:{background:s?b.tabActiveBg:b.tabBg,border:`1px solid ${s?b.tabActiveBorder:"transparent"}`,color:s?b.tabActiveText:b.tabText,fontFamily:"'Roboto Slab', serif",letterSpacing:"0.02em"},onMouseEnter:e=>{s||(e.currentTarget.style.background=b.tabHoverBg)},onMouseLeave:e=>{s||(e.currentTarget.style.background=b.tabBg)},children:[e.jsx(r,{className:"w-3.5 h-3.5","aria-hidden":!0}),e.jsx("span",{className:"hidden sm:inline",children:t.label}),e.jsx("span",{className:"sm:hidden",children:t.short})]},t.key)})}),e.jsxs("div",{id:`panel-${d}`,role:"tabpanel","aria-labelledby":`tab-${d}`,className:"p-5 sm:p-6 space-y-5",children:[e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx(v.icon,{className:"w-4 h-4",style:{color:b.accentText},"aria-hidden":!0}),e.jsx("h2",{className:"text-base font-bold",style:{color:b.headlineColor,fontFamily:"'Roboto Slab', serif"},children:v.label})]}),j&&e.jsxs("p",{className:"text-[11px]",style:{color:b.mutedText},children:["Version ",j.version," · Last updated"," ",new Date(j.updated_at).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"})]})]})}),j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`title-${d}`,className:"text-xs font-semibold uppercase tracking-wider",style:{color:b.labelText,fontFamily:"'Roboto Slab', serif"},children:"Document Title"}),e.jsx(Vs,{id:`title-${d}`,value:j.title,onChange:e=>f(d,"title",e),placeholder:"Enter document title",p:b})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`content-${d}`,className:"text-xs font-semibold uppercase tracking-wider",style:{color:b.labelText,fontFamily:"'Roboto Slab', serif"},children:"Content"}),e.jsx(Gs,{id:`content-${d}`,value:j.content,onChange:e=>f(d,"content",e),placeholder:"Enter document content (HTML supported)",p:b}),e.jsx("p",{className:"text-[11px]",style:{color:b.mutedText},children:"Supports HTML: h1–h3, p, ul/ol/li, a tags."})]}),e.jsxs("button",{onClick:()=>(async e=>{var s;const r=t[e];if(r){n(t=>({...t,[e]:!0}));try{const{error:t}=await h.from("policy_documents").update({title:r.title,content:r.content,version:r.version+1}).eq("document_type",e);if(t)throw t;const a=(null==(s=Ws.find(t=>t.key===e))?void 0:s.label)??e;x({title:"Saved",description:`${a} updated successfully`}),i(t=>({...t,[e]:!0})),setTimeout(()=>i(t=>({...t,[e]:!1})),2200),await y()}catch{x({title:"Error",description:"Failed to save policy",variant:"destructive"})}finally{n(t=>({...t,[e]:!1}))}}})(d),disabled:l[d],className:"flex items-center gap-2 rounded-xl px-5 py-2.5 text-sm font-semibold transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40 disabled:opacity-60",style:{background:o[d]?"rgba(16,185,129,0.22)":b.btnBg,border:`1px solid ${o[d]?"rgba(16,185,129,0.55)":b.btnBorder}`,color:b.btnText,boxShadow:"0 2px 10px rgba(139,92,246,0.22)"},"aria-busy":l[d],children:[l[d]?e.jsx(K,{className:"w-4 h-4 animate-spin","aria-hidden":!0}):o[d]?e.jsx(Y,{className:"w-4 h-4","aria-hidden":!0}):e.jsx(J,{className:"w-4 h-4","aria-hidden":!0}),l[d]?"Saving…":o[d]?"Saved!":"Save Changes"]})]}):e.jsx("p",{className:"text-sm py-6 text-center",style:{color:b.mutedText},children:"Policy document not found."})]})]})},Ys={UPDATE:{bg:"rgba(251,191,36,0.12)",color:"#fbbf24",border:"rgba(251,191,36,0.30)"},SELECT:{bg:"rgba(96,165,250,0.12)",color:"#60a5fa",border:"rgba(96,165,250,0.30)"},DELETE:{bg:"rgba(239,68,68,0.12)",color:"#f87171",border:"rgba(239,68,68,0.30
1)"},read:{bg:"rgba(110,231,183,0.12)",color:"#6ee7b7",border:"rgba(110,231,183,0.30)"}},Js=({type:t})=>{const s=Ys[t]??{bg:"rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.55)",border:"rgba(255,255,255,0.14)"};return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold",style:{background:s.bg,color:s.color,border:`1px solid ${s.border}`},children:t})},Qs=({name:t,email:s,p:r})=>e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",style:{color:r.bodyText},children:t||"Unknown"}),s&&e.jsx("p",{className:"text-xs mt-0.5 truncate max-w-[180px]",style:{color:r.mutedText},title:s,children:s})]}),Xs=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(null),[d,u]=c.useState("7"),[x,p]=c.useState(""),[w,N]=c.useState("all"),[k,_]=c.useState(1),C=c.useCallback(async()=>{n(!0),i(null);try{const e=new Date;e.setDate(e.getDate()-parseInt(d));let t=h.from("profile_access_log").select("*").gte("accessed_at",e.toISOString()).order("accessed_at",{ascending:!1});"all"!==w&&(t=t.eq("access_type",w));const{data:s,error:r}=await t;if(r)throw r;if(!s||0===s.length)return void a([]);const l=new Set;s.forEach(e=>{l.add(e.user_id),l.add(e.accessed_by)});const{data:n}=await h.from("profiles").select("user_id, full_name, email").in("user_id",Array.from(l)),o=new Map((n||[]).map(e=>[e.user_id,e]));a(s.map(e=>({...e,profile_owner:o.get(e.user_id),accessor:o.get(e.accessed_by)})))}catch(e){i((null==e?void 0:e.message)||"Failed to load audit logs")}finally{n(!1)}},[d,w]);c.useEffect(()=>{C()},[C]),c.useEffect(()=>{_(1)},[x,w,d]);const B=r.filter(e=>{var t,s,r,a,l,n,o,i,d;if(!x)return!0;const c=x.toLowerCase();return(null==(s=null==(t=e.profile_owner)?void 0:t.full_name)?void 0:s.toLowerCase().includes(c))||(null==(a=null==(r=e.profile_owner)?void 0:r.email)?void 0:a.toLowerCase().includes(c))||(null==(n=null==(l=e.accessor)?void 0:l.full_name)?void 0:n.toLowerCase().includes(c))||(null==(i=null==(o=e.accessor)?void 0:o.email)?void 0:i.toLowerCase().includes(c))||(null==(d=e.access_type)?void 0:d.toLowerCase().includes(c))||(e.ip_address||"").toLowerCase().includes(c)}),T=Math.max(1,Math.ceil(B.length/50)),S=B.slice(50*(k-1),50*k),$={background:s.inputBg,border:`1.5px solid ${s.inputBorder}`,borderRadius:10,color:s.headlineColor,height:40};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row flex-wrap gap-3 items-stretch sm:items-center",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:s.mutedText}}),e.jsx("input",{placeholder:"Search by name, email, IP…",value:x,onChange:e=>p(e.target.value),style:{background:s.inputBg,border:`1.5px solid ${s.inputBorder}`,borderRadius:10,color:s.headlineColor,padding:"9px 14px 9px 38px",fontSize:14,fontFamily:"inherit",width:"100%",outline:"none"}})]}),e.jsxs(g,{value:d,onValueChange:u,children:[e.jsx(b,{className:"w-full sm:w-[160px]",style:$,children:e.jsx(y,{placeholder:"Date range"})}),e.jsxs(f,{style:{background:s.sectionBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(v,{value:"7",style:{color:s.bodyText},children:"Last 7 days"}),e.jsx(v,{value:"30",style:{color:s.bodyText},children:"Last 30 days"}),e.jsx(v,{value:"90",style:{color:s.bodyText},children:"Last 90 days"})]})]}),e.jsxs(g,{value:w,onValueChange:N,children:[e.jsxs(b,{className:"w-full sm:w-[150px]",style:$,children:[e.jsx(te,{className:"h-3.5 w-3.5 mr-1.5 opacity-60"}),e.jsx(y,{placeholder:"Action"})]}),e.jsxs(f,{style:{background:s.sectionBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(v,{value:"all",style:{color:s.bodyText},children:"All Actions"}),e.jsx(v,{value:"UPDATE",style:{color:s.bodyText},children:"Update"}),e.jsx(v,{value:"SELECT",style:{color:s.bodyText},children:"Select"}),e.jsx(v,{value:"DELETE",style:{color:s.bodyText},children:"Delete"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>{const e=[["Timestamp","Profile Owner","Owner Email","Accessed By","Accessor Email","Action","IP Address","User Agent"],...B.map(e=>{var t,s,r,a;return[St(new Date(e.accessed_at),"yyyy-MM-dd HH:mm:ss"),(null==(t=e.profile_owner)?void 0:t.full_name)||"Unknown",(null==(s=e.profile_owner)?void 0:s.email)||"N/A",(null==(r=e.accessor)?void 0:r.full_name)||"Unknown",(null==(a=e.accessor)?void 0:a.email)||"N/A",e.access_type,e.ip_address||"N/A",e.user_agent||"N/A"]})].map(e=>e.map(e=>`"${String(e).replace(/"/g,'""')}"`).join(",")).join("\n"),t=new Blob([e],{type:"text/csv;charset=utf-8;"}),s=window.URL.createObjectURL(t),r=document.createElement("a");r.href=s,r.download=`audit-logs-${St(new Date,"yyyy-MM-dd")}.csv`,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(s)},disabled:0===B.length,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 active:scale-[0.97]",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`,color:0===B.length?s.mutedText:s.bodyText,cursor:0===B.length?"not-allowed":"pointer",fontFamily:"inherit",opacity:0===B.length?.5:1},"aria-label":"Export to CSV",children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export"})]}),e.jsxs("button",{onClick:C,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 active:scale-[0.97]",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},"aria-label":"Refresh logs",children:[e.jsx(re,{className:"h-4 w-4 "+(l?"animate-spin":"")}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]})]}),!l&&!o&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs",style:{color:s.mutedText},children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),r.length," total events"]}),e.jsx("span",{style:{color:s.divider},children:"·"}),e.jsxs("span",{children:[B.length," matching"]}),x&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:s.divider},children:"·"}),e.jsx("button",{onClick:()=>p(""),className:"underline hover:no-underline",style:{color:s.accentText,background:"none",border:"none",cursor:"pointer",fontFamily:"inherit",fontSize:"inherit"},children:"Clear search"})]})]}),l?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-4",children:[e.jsx(K,{className:"h-8 w-8 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading audit logs…"})]}):o?e.jsxs("div",{className:"rounded-2xl flex flex-col items-center justify-center py-12 gap-4 text-center",style:{background:s.
1cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(le,{className:"h-8 w-8",style:{color:s.errorText??"#f87171"}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:o}),e.jsxs("button",{onClick:C,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold hover:opacity-80",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]}):0===S.length?e.jsxs("div",{className:"rounded-2xl flex flex-col items-center justify-center py-16 gap-4 text-center",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(ae,{className:"h-10 w-10",style:{color:s.mutedText}}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"No audit logs found"}),e.jsx("p",{className:"text-sm mt-1",style:{color:s.mutedText},children:x?"Try adjusting your search terms":"No activity in the selected time range"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[760px] text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Timestamp","Profile Owner","Accessed By","Action","IP Address","User Agent"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-[10px] font-bold uppercase tracking-[0.12em] whitespace-nowrap",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:S.map((t,r)=>{var a,l,n,o;return e.jsxs("tr",{className:"transition-colors duration-150",style:{borderBottom:r<S.length-1?`1px solid ${s.tableBorder}`:"none"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsxs("td",{className:"py-3 px-4 whitespace-nowrap text-xs",style:{color:s.mutedText},children:[St(new Date(t.accessed_at),"MMM dd, yyyy"),e.jsx("br",{}),e.jsx("span",{style:{color:s.mutedText,opacity:.7},children:St(new Date(t.accessed_at),"HH:mm:ss")})]}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(Qs,{name:(null==(a=t.profile_owner)?void 0:a.full_name)||"Unknown",email:null==(l=t.profile_owner)?void 0:l.email,p:s})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(Qs,{name:(null==(n=t.accessor)?void 0:n.full_name)||"Unknown",email:null==(o=t.accessor)?void 0:o.email,p:s})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(Js,{type:t.access_type})}),e.jsx("td",{className:"py-3 px-4 text-xs font-mono",style:{color:s.mutedText},children:t.ip_address||"—"}),e.jsx("td",{className:"py-3 px-4 text-xs max-w-[180px] truncate",style:{color:s.mutedText},title:t.user_agent||void 0,children:t.user_agent||"—"})]},t.id)})})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-xs",style:{color:s.mutedText},children:["Showing"," ",e.jsxs("span",{style:{color:s.bodyText,fontWeight:600},children:[50*(k-1)+1,"–",Math.min(50*k,B.length)]})," ","of ",e.jsx("span",{style:{color:s.bodyText,fontWeight:600},children:B.length})," logs"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:1===k,className:"flex items-center gap-1.5 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 active:scale-[0.97]",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`,color:1===k?s.mutedText:s.bodyText,cursor:1===k?"not-allowed":"pointer",opacity:1===k?.45:1,fontFamily:"inherit"},"aria-label":"Previous page",children:[e.jsx(ne,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Prev"})]}),e.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:Math.min(T,7)},(t,r)=>{const a=T<=7||r<3?r+1:3===r?k:T-(6-r);return e.jsx("button",{onClick:()=>_(a),className:"w-8 h-8 rounded-lg text-xs font-semibold transition-all hover:opacity-80",style:{background:a===k?s.tileActiveBg??"rgba(139,92,246,0.30)":"transparent",border:`1px solid ${a===k?s.tileActiveBorder??"rgba(139,92,246,0.75)":s.cardBorder}`,color:a===k?"#fff":s.mutedText,cursor:"pointer",fontFamily:"inherit"},children:a},r)})}),e.jsxs("button",{onClick:()=>_(e=>Math.min(T,e+1)),disabled:k===T,className:"flex items-center gap-1.5 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 active:scale-[0.97]",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`,color:k===T?s.mutedText:s.bodyText,cursor:k===T?"not-allowed":"pointer",opacity:k===T?.45:1,fontFamily:"inherit"},"aria-label":"Next page",children:[e.jsx("span",{className:"hidden sm:inline",children:"Next"}),e.jsx(oe,{className:"h-4 w-4"})]})]})]})]})]})},Zs={signup_reward_credits:5,first_purchase_reward_referrer_credits:10,first_purchase_reward_referee_credits:5,monthly_cap_per_referrer:100,max_signups_per_month:20,cooldown_days:7,enabled:!0,social_share_monthly_limit:5,social_share_reward_credits:1,experience_share_reward_credits:1}
1,er=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),tr=({id:t,type:s="number",value:r,onChange:a,min:l,p:n,disabled:o})=>e.jsx("input",{id:t,type:s,value:r,min:l,disabled:o,onChange:e=>a(parseInt(e.target.value)||0),style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${n.inputBorder}`,background:n.inputBg,color:n.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s",opacity:o?.5:1},onFocus:e=>!o&&(e.target.style.borderColor=n.inputFocusBorder),onBlur:e=>e.target.style.borderColor=n.inputBorder}),sr=({icon:t,title:s,description:r,children:a,p:l})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${l.divider}`,background:l.tableHeaderBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:l.badgeBg,border:`1px solid ${l.badgeBorder}`},children:e.jsx(t,{className:"h-4 w-4",style:{color:l.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:l.tableHeaderText},children:s}),r&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:l.mutedText},children:r})]})]}),e.jsx("div",{className:"p-6",children:a})]}),rr=({id:t,label:s,hint:r,value:a,onChange:l,p:n,disabled:o})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:t,className:"text-xs font-bold uppercase tracking-wide block",style:{color:n.labelText},children:s}),r&&e.jsx("p",{className:"text-[11px]",style:{color:n.mutedText},children:r}),e.jsx(tr,{id:t,value:a,onChange:l,min:0,p:n,disabled:o})]}),ar=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState(Zs),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(!1),x=(e,t)=>{a(s=>({...s,[e]:t})),u(!0)},p=async()=>{n(!0);try{const{data:e,error:t}=await h.from("referral_policy").select("*").maybeSingle();if(t)throw t;if(e){const t=e;a({signup_reward_credits:t.signup_reward_credits,first_purchase_reward_referrer_credits:t.first_purchase_reward_referrer_credits,first_purchase_reward_referee_credits:t.first_purchase_reward_referee_credits,monthly_cap_per_referrer:t.monthly_cap_per_referrer,max_signups_per_month:t.max_signups_per_month,cooldown_days:t.cooldown_days,enabled:t.enabled,social_share_monthly_limit:t.social_share_monthly_limit??5,social_share_reward_credits:t.social_share_reward_credits??1,experience_share_reward_credits:t.experience_share_reward_credits??1}),u(!1)}}catch(e){w.error("Failed to load referral settings")}finally{n(!1)}};c.useEffect(()=>{p()},[]);return l?e.jsx("div",{className:"w-full flex items-center justify-center py-20",style:{background:s.sectionBg},children:e.jsx(K,{className:"h-8 w-8 animate-spin",style:{color:s.accentText}})}):e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:s.sectionBg,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsx(er,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 lg:px-8 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsxs("button",{type:"button",onClick:p,disabled:l||o,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 disabled:opacity-50",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4 "+(l?"animate-spin":"")}),"Refresh"]}),d&&e.jsx("span",{className:"text-xs px-2 py-1 rounded-full",style:{background:"rgba(251,191,36,0.15)",color:"#fbbf24",border:"1px solid rgba(251,191,36,0.3)"},children:"Unsaved changes"})]}),e.jsxs("div",{className:"rounded-2xl px-6 py-4 flex items-center justify-between",style:{background:r.enabled?"rgba(52,211,153,0.08)":"rgba(248,113,113,0.08)",border:"1px solid "+(r.enabled?"rgba(52,211,153,0.25)":"rgba(248,113,113,0.25)")},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ie,{className:"h-5 w-5",style:{color:r.enabled?s.greenAccent:s.redAccent}}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:s.headlineColor},children:"Referral Program"}),e.jsx("p",{className:"text-xs",style:{color:s.mutedText},children:r.enabled?"Active — users can earn rewards through referrals":"Disabled — no new referral rewards will be granted"})]})]}),e.jsx(Ft,{checked:r.enabled,onCheckedChange:e=>x("enabled",e)})]}
1),e.jsx(sr,{icon:de,title:"Referral Rewards",description:"Credits awarded for signup and first purchase events",p:s,children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-5",children:[e.jsx(rr,{id:"signup-reward",label:"Signup Reward (Referrer)",hint:"Credits given to referrer when referred user signs up",value:r.signup_reward_credits,onChange:e=>x("signup_reward_credits",e),p:s}),e.jsx(rr,{id:"purchase-referrer",label:"First Purchase — Referrer",hint:"Credits given to referrer on referred user's first purchase",value:r.first_purchase_reward_referrer_credits,onChange:e=>x("first_purchase_reward_referrer_credits",e),p:s}),e.jsx(rr,{id:"purchase-referee",label:"First Purchase — Referee",hint:"Bonus credits given to the new user on their first purchase",value:r.first_purchase_reward_referee_credits,onChange:e=>x("first_purchase_reward_referee_credits",e),p:s})]})}),e.jsx(sr,{icon:ce,title:"Limits & Caps",description:"Monthly caps and cooldown controls to prevent abuse",p:s,children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-5",children:[e.jsx(rr,{id:"monthly-cap",label:"Monthly Cap Per Referrer",hint:"Maximum total credits a single referrer can earn per month",value:r.monthly_cap_per_referrer,onChange:e=>x("monthly_cap_per_referrer",e),p:s}),e.jsx(rr,{id:"max-signups",label:"Max Signups Per Month",hint:"Maximum rewarded referral signups per user per month",value:r.max_signups_per_month,onChange:e=>x("max_signups_per_month",e),p:s}),e.jsx(rr,{id:"cooldown",label:"Cooldown Period (Days)",hint:"Minimum days between eligible referral actions",value:r.cooldown_days,onChange:e=>x("cooldown_days",e),p:s})]})}),e.jsx(sr,{icon:ue,title:"Social & Experience Sharing",description:"Rewards for sharing on social platforms and posting experiences",p:s,children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-5",children:[e.jsx(rr,{id:"social-limit",label:"Social Share Monthly Limit",hint:"Max rewarded social shares per user per month",value:r.social_share_monthly_limit,onChange:e=>x("social_share_monthly_limit",e),p:s}),e.jsx(rr,{id:"social-reward",label:"Social Share Reward",hint:"Credits per qualifying social share",value:r.social_share_reward_credits,onChange:e=>x("social_share_reward_credits",e),p:s}),e.jsx(rr,{id:"experience-reward",label:"Experience Share Reward",hint:"Credits per qualifying experience post",value:r.experience_share_reward_credits,onChange:e=>x("experience_share_reward_credits",e),p:s})]})}),e.jsxs("button",{type:"button",onClick:async()=>{i(!0);try{const{error:e}=await h.from("referral_policy").update(r).eq("id","00000000-0000-0000-0000-000000000001");if(e)throw e;w.success("Referral settings saved successfully"),u(!1)}catch(e){w.error((null==e?void 0:e.message)||"Failed to save settings")}finally{i(!1)}},disabled:o||!d,className:"w-full flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{height:48,background:d?s.btnPrimaryBg:s.stepLockedBg,border:d?"none":`1px solid ${s.stepLockedBorder}`,color:d?"#fff":s.mutedText,cursor:o||!d?"not-allowed":"pointer",fontFamily:"inherit"},children:[o?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(J,{className:"h-4 w-4"}),o?"Saving...":d?"Save Settings":"All Changes Saved"]})]})]})},lr={title:"",credits:0,price_inr:0,discount_inr:0,is_featured:!1,active:!0},nr=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),or=({children:t,htmlFor:s,p:r})=>e.jsx("label",{htmlFor:s,style:{display:"block",fontSize:12,fontWeight:700,color:r.labelText,letterSpacing:"0.06em",textTransform:"uppercase",marginBottom:6},children:t}),ir=({id:t,type:s="text",value:r,onChange:a,placeholder:l,p:n})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),placeholder:l,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${n.inputBorder}`,background:n.inputBg,color:n.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=n.inputFocusBorder,onBlur:e=>e.target.style.borderColor=n.inputBorder}),dr=({checked:t,onChange:s,label:r,p:a})=>e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer select-none",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":t,onClick:()=>s(!t),className:"relative rounded-full transition-all duration-200 flex-shrink-0",style:{width:40,height:22,background:t?a.btnPrimaryBg:a.stepLockedBg,border:`1.5px solid ${t?"rgba(139,92,246,0.60)":a.stepLockedBorder}`},children:e.jsx("span",{className:"absolute top-0.5 rounded-full transition-all duration-200",style:{width:16,height:16,background:t?"#fff":a.mutedText,left:t?"calc(100% - 18px)":2}})}),e.jsx("span",{className:"text-sm",style:{color:a.bodyText},children:r})]}),cr=({message:t,type:s,p:r})=>e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-3 text-sm font-medium",role:"alert",style:{background:"error"===s?"rgba(248,113,113,0.12)":"rgba(110,231,183,0.12)",border:"1px solid "+("error"===s?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)"),color:"error"===s?r.redAccent:r.greenAccent},children:["error"===s?e.jsx(le,{className:"h-4 w-4 flex-shrink-0"}):e.jsx(be,{className:"h-4 w-4 flex-shrink-0"}),t]}),ur=({form:t,setForm:s,onSave:r,onClose:a,saving:l,isEdit:n,p:o})=>{const i=e=>t=>{s(s=>({...s,[e]:["credits","price_inr","discount_inr"].includes(e)?parseFloat(t)||0:t}))};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{background:o.modalOverlay,backdropFilter:"blur(4px)"},onClick:e=>e.target===e.currentTarget&&a(),children:e.jsxs("div",{className:"w-full max-w-md rounded-3xl overflow-hidden",style:{background:"linear-gradient(160deg, #15002B 0%, #2A
1044C 50%, #1A0235 100%)",border:`1px solid ${o.cardBorder}`,boxShadow:"0 32px 64px rgba(0,0,0,0.5)"},children:[e.jsxs("div",{className:"px-6 pt-6 pb-5 flex items-center justify-between",style:{borderBottom:`1px solid ${o.divider}`},children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em] mb-0.5",style:{color:o.accentText},children:"Credit Packs"}),e.jsx("h3",{className:"text-lg font-bold",style:{fontFamily:"'Roboto Slab', serif",color:o.headlineColor},children:n?"Edit Pack":"Create New Pack"})]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-xl p-1.5 transition-opacity hover:opacity-70",style:{background:o.stepLockedBg,border:`1px solid ${o.stepLockedBorder}`,color:o.bodyText,cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx(or,{htmlFor:"pack-title",p:o,children:"Title"}),e.jsx(ir,{id:"pack-title",value:t.title,onChange:i("title"),placeholder:"e.g. Starter Pack",p:o})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(or,{htmlFor:"pack-credits",p:o,children:"Credits"}),e.jsx(ir,{id:"pack-credits",type:"number",value:t.credits,onChange:i("credits"),placeholder:"10",p:o})]}),e.jsxs("div",{children:[e.jsx(or,{htmlFor:"pack-price",p:o,children:"Price (₹)"}),e.jsx(ir,{id:"pack-price",type:"number",value:t.price_inr,onChange:i("price_inr"),placeholder:"299",p:o})]})]}),e.jsxs("div",{children:[e.jsx(or,{htmlFor:"pack-discount",p:o,children:"Discount (₹)"}),e.jsx(ir,{id:"pack-discount",type:"number",value:t.discount_inr,onChange:i("discount_inr"),placeholder:"0",p:o})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsx(dr,{checked:t.is_featured,onChange:e=>s(t=>({...t,is_featured:e})),label:"Featured Pack",p:o}),e.jsx(dr,{checked:t.active,onChange:e=>s(t=>({...t,active:e})),label:"Active",p:o})]}),e.jsxs("button",{type:"button",onClick:r,disabled:l||!t.title.trim(),className:"w-full flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-40 mt-2",style:{height:46,background:o.btnPrimaryBg,color:"#fff",border:"none",cursor:l?"not-allowed":"pointer",fontFamily:"inherit"},children:[l?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(be,{className:"h-4 w-4"}),l?"Saving…":n?"Save Changes":"Create Pack"]})]})]})})},xr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(null),[x,p]=c.useState(!1),[g,b]=c.useState(null),[y,f]=c.useState(lr),[v,w]=c.useState(null),N=(e,t="success")=>{w({message:e,type:t}),setTimeout(()=>w(null),4e3)},k=c.useCallback(async()=>{try{n(!0);const{data:e,error:t}=await h.from("credit_packs").select("*").order("display_order");if(t)throw t;a(e||[])}catch(e){N((null==e?void 0:e.message)||"Failed to fetch credit packs","error")}finally{n(!1)}},[]);c.useEffect(()=>{k()},[k]);const _=()=>{b(null),f(lr),p(!0)};return l?e.jsxs("div",{className:"w-full flex items-center justify-center py-20",style:{background:s.sectionBg},children:[e.jsx(nr,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading credit packs…"})]})]}):e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(nr,{p:s}),x&&e.jsx(ur,{form:y,setForm:f,onSave:async()=>{i(!0);try{const e={...y},{error:t}=g?await h.from("credit_packs").update(e).eq("id",g.id):await h.from("credit_packs").insert([e]);if(t)throw t;N(`Pack ${g?"updated":"created"} successfully`),p(!1),k()}catch(e){N((null==e?void 0:e.message)||"Failed to save pack","error")}finally{i(!1)}},onClose:()=>p(!1),saving:o,isEdit:!!g,p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 py-8 space-y-6",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("button",{type:"button",onClick:_,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold transition-all hover:opacity-90",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(xe,{className:"h-4 w-4"})," Add Pack"]})}),v&&e.jsx(cr,{message:v.message,type:v.type,p:s}),0===r.length?e.jsxs("div",{className:"rounded-2xl p-12 text-center",style:{background:s.
1cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(pe,{className:"h-10 w-10 mx-auto mb-3",style:{color:s.mutedText}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"No credit packs yet"}),e.jsx("p",{className:"text-sm mt-1",style:{color:s.mutedText},children:"Create your first pack to get started"}),e.jsxs("button",{type:"button",onClick:_,className:"mt-5 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold transition-all hover:opacity-90 mx-auto",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(xe,{className:"h-4 w-4"})," Create First Pack"]})]}):e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:700},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Title","Credits","Price","Discount","Featured","Status","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:r.map((t,l)=>e.jsxs("tr",{style:{borderBottom:l<r.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold",style:{color:s.bodyText},children:t.title}),t.is_featured&&e.jsx(me,{className:"h-3.5 w-3.5 fill-current",style:{color:s.orangeAccent}})]})}),e.jsx("td",{className:"py-3 px-4 font-semibold",style:{color:s.purpleAccent},children:t.credits}),e.jsxs("td",{className:"py-3 px-4 font-semibold",style:{color:s.greenAccent},children:["₹",t.price_inr]}),e.jsx("td",{className:"py-3 px-4",style:{color:t.discount_inr>0?s.orangeAccent:s.mutedText},children:t.discount_inr>0?`₹${t.discount_inr}`:"—"}),e.jsx("td",{className:"py-3 px-4",children:t.is_featured?e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.25)",color:s.orangeAccent},children:"⭐ Featured"}):e.jsx("span",{style:{color:s.mutedText},children:"—"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{background:t.active?"rgba(110,231,183,0.10)":"rgba(255,255,255,0.05)",border:"1px solid "+(t.active?"rgba(110,231,183,0.25)":"rgba(255,255,255,0.12)"),color:t.active?s.greenAccent:s.mutedText},children:t.active?"Active":"Inactive"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>(e=>{b(e),f({title:e.title,credits:e.credits,price_inr:e.price_inr,discount_inr:e.discount_inr,is_featured:e.is_featured,active:e.active}),p(!0)})(t),"aria-label":`Edit ${t.title}`,className:"rounded-lg flex items-center justify-center transition-all hover:opacity-80",style:{width:32,height:32,background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer"},children:e.jsx(he,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{if(window.confirm(`Delete "${t}"? This cannot be undone.`)){u(e);try{const{error:t}=await h.from("credit_packs").delete().eq("id",e);if(t)throw t;N("Pack deleted"),a(t=>t.filter(t=>t.id!==e))}catch(s){N((null==s?void 0:s.message)||"Failed to delete pack","error")}finally{u(null)}}})(t.id,t.title),disabled:d===t.id,"aria-label":`Delete ${t.title}`,className:"rounded-lg flex items-center justify-center transition-all hover:opacity-80 disabled:opacity-40",style:{width:32,height:32,background:"rgba(248,113,113,0.10)",border:"1px solid rgba(248,113,113,0.25)",color:s.redAccent,cursor:d===t.id?"not-allowed":"pointer"},children:d===t.id?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ge,{className:"h-3.5 w-3.5"})})]})})]},t.id))})]})})})]})]})},pr={code:"",discount_percentage:0,discount_value:null,max_discount_inr:null,valid_from:St(new Date,"yyyy-MM-dd"),valid_until:St(new Date(Date.now()+2592e6),"yyyy-MM-dd"),usage_limit:null},mr=e=>{const t=new Date;return e.is_active?t<new Date(e.valid_from)?{label:"Scheduled",color:"#fbbf24",bg:"rgba(251,191,36,0.10)",border:"rgba(251,191,36,0.25)"}:t>new Date(e.valid_until)?{label:"Expired",color:"#f87171",bg:"rgba(248,113,113,0.10)",border:"rgba(248,113,113,0.25)"}:e.usage_limit&&e.times_used>=e.usage_limit?{label:"Limit Reached",color:"#f87171",bg:"rgba(248,113,113,0.10)",border:"rgba(248,113,113,0.25)"}:{label:"Active",color:"#6ee7b7",bg:"rgba(110,231,183,0.10)",border:"rgba(110,231,183,0.25)"}:{label:"Paused",color:"#93c5fd",bg:"rgba(147,197,253,0.10)",border:"rgba(147,197,253,0.25)"}},hr=({p:t})=>
1e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),gr=({children:t,htmlFor:s,p:r})=>e.jsx("label",{htmlFor:s,style:{display:"block",fontSize:12,fontWeight:700,color:r.labelText,letterSpacing:"0.06em",textTransform:"uppercase",marginBottom:6},children:t}),br=({id:t,type:s="text",value:r,onChange:a,placeholder:l,p:n,disabled:o})=>e.jsx("input",{id:t,type:s,value:r??"",onChange:e=>a(e.target.value),placeholder:l,disabled:o,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${n.inputBorder}`,background:o?"rgba(255,255,255,0.02)":n.inputBg,color:o?n.mutedText:n.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s",opacity:o?.5:1},onFocus:e=>!o&&(e.target.style.borderColor=n.inputFocusBorder),onBlur:e=>e.target.style.borderColor=n.inputBorder}),yr=({message:t,type:s,p:r})=>e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-3 text-sm font-medium",role:"alert",style:{background:"error"===s?"rgba(248,113,113,0.12)":"rgba(110,231,183,0.12)",border:"1px solid "+("error"===s?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)"),color:"error"===s?r.redAccent:r.greenAccent},children:["error"===s?e.jsx(le,{className:"h-4 w-4 flex-shrink-0"}):e.jsx(be,{className:"h-4 w-4 flex-shrink-0"}),t]}),fr=({form:t,setForm:s,onSubmit:r,onClose:a,saving:l,p:n})=>{const o=t.discount_percentage>0,i=!!t.discount_value;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{background:n.modalOverlay,backdropFilter:"blur(4px)"},onClick:e=>e.target===e.currentTarget&&a(),children:e.jsxs("div",{className:"w-full max-w-md rounded-3xl overflow-hidden max-h-[90vh] overflow-y-auto",style:{background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${n.cardBorder}`,boxShadow:"0 32px 64px rgba(0,0,0,0.5)"},children:[e.jsxs("div",{className:"px-6 pt-6 pb-5 flex items-center justify-between sticky top-0",style:{borderBottom:`1px solid ${n.divider}`,background:"rgba(21,0,43,0.95)",backdropFilter:"blur(12px)"},children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em] mb-0.5",style:{color:n.accentText},children:"Promo Codes"}),e.jsx("h3",{className:"text-lg font-bold",style:{fontFamily:"'Roboto Slab', serif",color:n.headlineColor},children:"Create Code"})]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-xl p-1.5 transition-opacity hover:opacity-70",style:{background:n.stepLockedBg,border:`1px solid ${n.stepLockedBorder}`,color:n.bodyText,cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-code",p:n,children:"Code (exactly 8 characters)"}),e.jsx(br,{id:"promo-code",value:t.code,onChange:e=>s(t=>({...t,code:e.toUpperCase()})),placeholder:"SAVE2025",p:n}),e.jsxs("p",{className:"text-xs mt-1.5",style:{color:8===t.code.length?n.greenAccent:n.mutedText},children:[t.code.length,"/8 characters ",8===t.code.length?"✓":""]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-pct",p:n,children:"Discount %"}),e.jsx(br,{id:"promo-pct",type:"number",value:t.discount_percentage||"",onChange:e=>s(t=>({...t,discount_percentage:parseInt(e)||0,discount_value:null})),placeholder:"e.g. 10",p:n,disabled:i})]}),e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-flat",p:n,children:"Flat Value (₹)"}),e.jsx(br,{id:"promo-flat",type:"number",value:t.discount_value??"",onChange:e=>s(t=>({...t,discount_value:e?parseFloat(e):null,discount_percentage:0})),placeholder:"e.g. 100",p:n,disabled:o})]})]}),e.jsx("div",{className:"rounded-xl px-4 py-3 text-xs",style:{background:n.statCardBg,border:`1px solid ${n.statCardBorder}`,color:n.mutedText},children:t.discount_value?`Flat ₹${t.discount_value} off on any order`:t.discount_percentage>0?`${t.discount_percentage}% off on orders`:"Enter either a percentage or a flat value"}),o&&e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-cap",p:n,children:"Max Discount Cap (₹, optional)"}),e.jsx(br,{id:"promo-cap",type:"number",value:t.max_discount_inr??"",onChange:e=>s(t=>({...t,max_discount_inr:e?parseFloat(e):null})),placeholder:"Leave empty for no cap",p:n}),t.max_discount_inr&&t.discount_percentage>0&&e.jsxs("p",{className:"text-xs mt-1.5",style:{color:n.mutedText},children:["Caps at ₹",t.max_discount_inr," for orders above ₹",Math.round(100*t.max_discount_inr/t.discount_percentage)]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-from",p:n,children:"Valid From"}),e.jsx(br,{id:"promo-from",type:"date",value:t.valid_from,onChange:e=>s(t=>({...t,valid_from:e})),p:n})]}),e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-until",p:n,children:"Valid Until"}),e.jsx(br,{id:"promo-until",type:"date",value:t.valid_until,onCh
1ange:e=>s(t=>({...t,valid_until:e})),p:n})]})]}),e.jsxs("div",{children:[e.jsx(gr,{htmlFor:"promo-limit",p:n,children:"Usage Limit (optional)"}),e.jsx(br,{id:"promo-limit",type:"number",value:t.usage_limit??"",onChange:e=>s(t=>({...t,usage_limit:e?parseInt(e):null})),placeholder:"Leave empty for unlimited",p:n})]}),e.jsxs("button",{type:"button",onClick:r,disabled:l||8!==t.code.length,className:"w-full flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-40 mt-2",style:{height:46,background:n.btnPrimaryBg,color:"#fff",border:"none",cursor:l||8!==t.code.length?"not-allowed":"pointer",fontFamily:"inherit"},children:[l?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(be,{className:"h-4 w-4"}),l?"Creating…":"Create Code"]})]})]})})},vr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(!1),[x,p]=c.useState(null),[g,b]=c.useState(pr),[y,f]=c.useState(null),v=(e,t="success")=>{f({message:e,type:t}),setTimeout(()=>f(null),4e3)},w=c.useCallback(async()=>{try{n(!0);const{data:e,error:t}=await h.from("promotional_codes").select("*").order("created_at",{ascending:!1});if(t)throw t;a(e||[])}catch(e){v((null==e?void 0:e.message)||"Failed to load promo codes","error")}finally{n(!1)}},[]);c.useEffect(()=>{w()},[w]);return l?e.jsxs("div",{className:"w-full flex items-center justify-center py-20",style:{background:s.sectionBg},children:[e.jsx(hr,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading promo codes…"})]})]}):e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(hr,{p:s}),o&&e.jsx(fr,{form:g,setForm:b,onSubmit:async()=>{if(8===g.code.length)if(g.discount_percentage<=0&&!g.discount_value)v("Enter either a percentage or a flat value","error");else{u(!0);try{const e=g.discount_value?100:g.discount_percentage,t=g.discount_value||g.max_discount_inr,{error:s}=await h.from("promotional_codes").insert({code:g.code.toUpperCase(),discount_percentage:e,max_discount_inr:t,valid_from:new Date(g.valid_from).toISOString(),valid_until:new Date(g.valid_until+" 23:59:59").toISOString(),usage_limit:g.usage_limit,is_active:!0});if(s)throw s;v(`Code ${g.code} created successfully`),i(!1),b(pr),w()}catch(e){v((null==e?void 0:e.message)||"Failed to create promo code","error")}finally{u(!1)}}else v("Code must be exactly 8 characters","error")},onClose:()=>i(!1),saving:d,p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-3",children:r.length>0&&e.jsx(e.Fragment,{children:[{label:"Total",count:r.length,accent:s.purpleAccent},{label:"Active",count:r.filter(e=>"Active"===mr(e).label).length,accent:s.greenAccent},{label:"Expired",count:r.filter(e=>"Expired"===mr(e).label).length,accent:s.redAccent},{label:"Paused",count:r.filter(e=>!e.is_active).length,accent:s.blueAccent}].map(({label:t,count:r,accent:a})=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 rounded-full text-sm",style:{background:`${a}12`,border:`1px solid ${a}25`},children:[e.jsx("span",{className:"font-bold",style:{color:a},children:r}),e.jsx("span",{style:{color:s.mutedText},children:t})]},t))})}),e.jsxs("button",{type:"button",onClick:()=>{b(pr),i(!0)},className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold transition-all hover:opacity-90",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(xe,{className:"h-4 w-4"})," Create Code"]})]}),y&&e.jsx(yr,{message:y.message,type:y.type,p:s}),0===r.length?e.jsxs("div",{className:"rounded-2xl p-12 text-center",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(fe,{className:"h-10 w-10 mx-auto mb-3",style:{color:s.mutedText}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"No promo codes yet"}),e.jsx("p",{className:"text-sm mt-1",style:{color:s.mutedText},children:"Create your first code to start offering discounts"}),e.jsxs("button",{type:"button",onClick:()=>{b(pr),i(!0)},className:"mt-5 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold transition-all hover:opacity-90 mx-auto",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(xe,{className:"h-4 w-4"})," Create First Code"]}
1)]}):e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:700},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Code","Discount","Valid Period","Usage","Status","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:r.map((t,l)=>{const n=mr(t);return e.jsxs("tr",{style:{borderBottom:l<r.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"font-mono font-bold tracking-widest",style:{color:s.headlineColor},children:t.code})}),e.jsxs("td",{className:"py-3 px-4",children:[e.jsxs("span",{className:"font-semibold",style:{color:s.purpleAccent},children:[t.discount_percentage,"%"]}),t.max_discount_inr&&e.jsxs("span",{className:"text-xs ml-1.5",style:{color:s.mutedText},children:["max ₹",t.max_discount_inr]})]}),e.jsxs("td",{className:"py-3 px-4 text-xs",style:{color:s.mutedText},children:[St(new Date(t.valid_from),"MMM dd, yyyy")," –"," ",St(new Date(t.valid_until),"MMM dd, yyyy")]}),e.jsxs("td",{className:"py-3 px-4",children:[e.jsxs("span",{className:"font-medium",style:{color:s.bodyText},children:[t.times_used,t.usage_limit?` / ${t.usage_limit}`:""]}),t.usage_limit&&e.jsx("div",{className:"mt-1 h-1 rounded-full overflow-hidden",style:{width:60,background:s.progressBg},children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,t.times_used/t.usage_limit*100)}%`,background:s.progressFill}})})]}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{color:n.color,background:n.bg,border:`1px solid ${n.border}`},children:n.label})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{p(e);try{const{error:s}=await h.from("promotional_codes").update({is_active:!t}).eq("id",e);if(s)throw s;a(s=>s.map(s=>s.id===e?{...s,is_active:!t}:s)),v("Code "+(t?"paused":"activated"))}catch(s){v((null==s?void 0:s.message)||"Failed to update status","error")}finally{p(null)}})(t.id,t.is_active),disabled:x===t.id,title:t.is_active?"Pause":"Activate",className:"rounded-lg flex items-center justify-center transition-all hover:opacity-80 disabled:opacity-40",style:{width:32,height:32,background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer"},children:x===t.id?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):t.is_active?e.jsx(ve,{className:"h-3.5 w-3.5"}):e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{const s=window.prompt("Modify:\n1 = Start Date\n2 = End Date\n\nEnter 1 or 2:");if(!s||!["1","2"].includes(s))return;const r="1"===s,a=St(r?new Date(t.valid_from):new Date(t.valid_until),"yyyy-MM-dd"),l=window.prompt(`Enter new ${r?"start":"end"} date (YYYY-MM-DD):\nCurrent: ${a}`);if(null==l?void 0:l.trim())try{const t=r?"valid_from":"valid_until",s=r?new Date(l).toISOString():new Date(l+" 23:59:59").toISOString(),{error:a}=await h.from("promotional_codes").update({[t]:s}).eq("id",e);if(a)throw a;v((r?"Start":"End")+" date updated"),w()}catch(n){v((null==n?void 0:n.message)||"Failed to update date","error")}})(t.id,t),title:"Modify Dates",className:"rounded-lg flex items-center justify-center transition-all hover:opacity-80",style:{width:32,height:32,background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer"},children:e.jsx(we,{className:"h-3.5 w-3.5"})})]})})]},t.id)})})]})})})]})]})},jr=[{type:"transactions",title:"Credit Transactions",description:"All credit grant, deduction, and purchase records with timestamps and user details",icon:Ne,accentColor:"#a78bfa",accentBg:"rgba(139,92,246,0.12)",accentBorder:"rgba(139,92,246,0.28)"},{type:"orders",title:"Orders",description:"Complete order history including payment status, amounts, and user references",icon:ke,accentColor:"#34d399",accentBg:"rgba(52,211,153,0.12)",accentBorder:"rgba(52,211,153,0.28)"},{type:"referrals",title:"Referrals",description:"All referral relationships, reward statuses, and conversion tracking data",icon:ce,accentColor:"#60a5fa",accentBg:"rgba(96,165,250,0.12)",accentBorder:"rgba(96,165,250,0.28)"}],wr=({p:t})=>
1e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),Nr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState({transactions:!1,orders:!1,referrals:!1}),l=Object.values(r).some(Boolean);return e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:s.sectionBg,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsx(wr,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 lg:px-8 py-8 space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:jr.map(t=>{const n=t.icon,o=r[t.type];return e.jsxs("div",{className:"rounded-2xl overflow-hidden flex flex-col",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`,transition:"border-color 0.2s"},onMouseEnter:e=>e.currentTarget.style.borderColor=t.accentBorder,onMouseLeave:e=>e.currentTarget.style.borderColor=s.cardBorder,children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${s.divider}`,background:t.accentBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:36,height:36,background:t.accentBg,border:`1px solid ${t.accentBorder}`},children:e.jsx(n,{className:"h-5 w-5",style:{color:t.accentColor}})}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.10em]",style:{color:s.headlineColor},children:t.title})]}),e.jsxs("div",{className:"p-6 flex flex-col flex-1 gap-4",children:[e.jsx("p",{className:"text-sm leading-relaxed flex-1",style:{color:s.mutedText},children:t.description}),e.jsxs("button",{type:"button",onClick:()=>(async e=>{if(!r[e]){a(t=>({...t,[e]:!0}));try{const{data:t,error:s}=await h.functions.invoke("admin-export-ledger",{body:{export_type:e}});if(s)throw s;if(!(null==t?void 0:t.csv))throw new Error("No CSV data returned");const r=new Blob([t.csv],{type:"text/csv;charset=utf-8;"}),a=URL.createObjectURL(r),l=document.createElement("a");l.href=a,l.download=`${e}-${(new Date).toISOString().split("T")[0]}.csv`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a),w.success(`${e} export downloaded successfully`)}catch(t){w.error((null==t?void 0:t.message)||`Failed to export ${e}`)}finally{a(t=>({...t,[e]:!1}))}}})(t.type),disabled:o||l,className:"flex items-center justify-center gap-2 w-full rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{height:42,background:o?t.accentBg:`linear-gradient(135deg, ${t.accentColor}33, ${t.accentColor}22)`,border:`1.5px solid ${t.accentBorder}`,color:t.accentColor,cursor:o||l?"not-allowed":"pointer",fontFamily:"inherit"},"aria-label":`Export ${t.title} as CSV`,children:[o?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(se,{className:"h-4 w-4"}),o?"Exporting...":`Export ${t.title}`]})]})]},t.type)})}),e.jsxs("div",{className:"rounded-xl px-5 py-4 flex items-start gap-3",style:{background:"rgba(167,139,250,0.07)",border:`1px solid ${s.cardBorder}`},children:[e.jsx(Ne,{className:"h-4 w-4 mt-0.5 flex-shrink-0",style:{color:s.accentText}}),e.jsx("p",{className:"text-xs leading-relaxed",style:{color:s.mutedText},children:"Exports are generated in real-time and include all records up to the current moment. Files are downloaded directly to your device in UTF-8 encoded CSV format, compatible with Excel, Google Sheets, and all major data tools."})]})]})]})},kr=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),_r=({id:t,type:s="text",value:r,onChange:a,onKeyDown:l,placeholder:n,p:o,autoFocus:i,disabled:d})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),onKeyDown:l,placeholder:n,autoFocus:i,disabled:d,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${o.inputBorder}`,background:o.inputBg,color:o.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s, opacity 0.2s",o
1pacity:d?.5:1},onFocus:e=>!d&&(e.target.style.borderColor=o.inputFocusBorder),onBlur:e=>e.target.style.borderColor=o.inputBorder}),Cr=({id:t,value:s,onChange:r,placeholder:a,p:l})=>e.jsx("textarea",{id:t,value:s,onChange:e=>r(e.target.value),placeholder:a,rows:3,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:l.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s",resize:"vertical"},onFocus:e=>e.target.style.borderColor=l.inputFocusBorder,onBlur:e=>e.target.style.borderColor=l.inputBorder}),Br=({message:t,type:s,p:r})=>e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-3 text-sm font-medium",role:"alert",style:{background:"error"===s?"rgba(248,113,113,0.12)":"rgba(110,231,183,0.12)",border:"1px solid "+("error"===s?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)"),color:"error"===s?r.redAccent:r.greenAccent},children:["error"===s?e.jsx(le,{className:"h-4 w-4 flex-shrink-0"}):e.jsx(be,{className:"h-4 w-4 flex-shrink-0"}),t]}),Tr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState(""),[l,n]=c.useState(null),[o,i]=c.useState(""),[d,u]=c.useState(""),[x,p]=c.useState(!1),[g,b]=c.useState(!1),[y,f]=c.useState(null),v=(e,t="success")=>{f({message:e,type:t}),setTimeout(()=>f(null),4500)},w=c.useCallback(async()=>{const e=r.trim().toLowerCase();if(e){p(!0),n(null);try{const{data:t,error:s}=await h.from("profiles").select("*").eq("email",e).maybeSingle();if(s)throw s;t?(n(t),v(`Found: ${t.full_name||t.email}`)):v("No user found with this email","error")}catch(t){v((null==t?void 0:t.message)||"Failed to search user","error")}finally{p(!1)}}else v("Please enter an email address","error")},[r]),N=c.useCallback(async()=>{if(!(null==l?void 0:l.user_id))return;const{data:e}=await h.from("profiles").select("*").eq("user_id",l.user_id).maybeSingle();e&&n(e)},[l]),k=async e=>{const t=parseInt(o);if(l&&t&&!(t<=0)&&d.trim()){b(!0);try{const s="grant"===e?"admin-grant-credits":"admin-deduct-credits",r="grant"===e?"credits_to_grant":"credits_to_deduct",{error:a}=await h.functions.invoke(s,{body:{target_user_id:l.user_id,[r]:t,reason:d.trim()}});if(a)throw a;v(`${t} credits ${"grant"===e?"granted to":"deducted from"} ${l.email}`),i(""),u(""),await N()}catch(s){v((null==s?void 0:s.message)||`Failed to ${e} credits`,"error")}finally{b(!1)}}else v("Please fill all fields with valid values","error")},_=l?l.credits>20?s.greenAccent:l.credits>5?s.orangeAccent:s.redAccent:s.headlineColor,C=!!l&&!!o&&parseInt(o)>0&&!!d.trim();return e.jsxs("div",{className:"min-h-screen w-full transition-colors duration-300",style:{background:s.sectionBg,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsx(kr,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 lg:px-8 py-8 space-y-6",children:[y&&e.jsx(Br,{message:y.message,type:y.type,p:s}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(_e,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Find User"})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"search-email",className:"text-xs font-bold uppercase tracking-wide block mb-2",style:{color:s.labelText},children:"Email Address"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx("div",{className:"flex-1",children:e.jsx(_r,{id:"search-email",type:"email",value:r,onChange:a,onKeyDown:e=>"Enter"===e.key&&!x&&w(),placeholder:"[email protected]",p:s})}),e.jsxs("button",{type:"button",onClick:w,disabled:x||!r.trim(),className:"flex items-center justify-center gap-2 px-6 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0",style:{height:42,background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:x?"not-allowed":"pointer",fontFamily:"inherit",minWidth:120},children:[x?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(G,{className:"h-4 w-4"}),"Search"]})]})]}),l&&e.jsx("div",{className:"rounded-xl p-5",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"rounded-full flex items-center justify-center flex-shrink-0",style:{width:48,height:48,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(_e,{className:"h-5 w-5",style:{color:s.accentText}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold truncate",style:{color:s.headlineColor},children:l.full_name||"Unnamed User"}),e.jsx("p",{className:"text-xs truncate mt-0.5",style:{color:s.mutedText},children:l.email}),l.years_of_experience&&e.jsx("span",{className:"inline-block text-xs font-semibold px-2 py-0.5 rounded-full mt-1",style:{background:s.badgeBg,border:`1px solid ${s.badgeBorder}`,color:s.accentText},children:l.years_of_experience})]}),e.jsxs("div",{className:"text-right flex-shrink-0 flex flex-col items-end gap-1",children:[e.jsx("p",{className:"text-3xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:_},children:l.credits??0}),e.jsx("p",{className:"text-xs",style:{color:s.mutedText},children:"credits"}),e.jsxs("button",{type:"button",onClick:N,className:"flex items-center gap-1 text-xs transition-all hover:opacity-80 mt-1",style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-3 w-3"}),"Refresh"]})]})]})})]})]}),l&&e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:s.
1cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(Ce,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Adjust Credits"}),e.jsxs("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:["For: ",e.jsx("span",{style:{color:s.accentText},children:l.email})]})]})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"credit-amount",className:"text-xs font-bold uppercase tracking-wide block mb-2",style:{color:s.labelText},children:"Amount"}),e.jsx(_r,{id:"credit-amount",type:"number",value:o,onChange:i,placeholder:"e.g. 5",p:s,disabled:g})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"credit-reason",className:"text-xs font-bold uppercase tracking-wide block mb-2",style:{color:s.labelText},children:"Reason"}),e.jsx(Cr,{id:"credit-reason",value:d,onChange:u,placeholder:"e.g. Compensation for failed session, promotional bonus…",p:s})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>k("grant"),disabled:!C||g,className:"flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",style:{height:46,background:C?"linear-gradient(135deg, #059669, #047857)":s.stepLockedBg,border:C?"none":`1px solid ${s.stepLockedBorder}`,color:C?"#fff":s.mutedText,cursor:!C||g?"not-allowed":"pointer",fontFamily:"inherit"},children:[g?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(xe,{className:"h-4 w-4"}),"Grant Credits"]}),e.jsxs("button",{type:"button",onClick:()=>k("deduct"),disabled:!C||g,className:"flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",style:{height:46,background:"rgba(248,113,113,0.12)",border:"1px solid "+(C?"rgba(248,113,113,0.35)":"rgba(248,113,113,0.12)"),color:C?s.redAccent:s.mutedText,cursor:!C||g?"not-allowed":"pointer",fontFamily:"inherit"},children:[g?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(Be,{className:"h-4 w-4"}),"Deduct Credits"]})]})]})]})]})]})},Sr=[10,25,50],$r={created:{label:"CREATED",color:"#fbbf24",bg:"rgba(251,191,36,0.10)",border:"rgba(251,191,36,0.25)"},paid:{label:"PAID",color:"#6ee7b7",bg:"rgba(110,231,183,0.10)",border:"rgba(110,231,183,0.25)"},failed:{label:"FAILED",color:"#f87171",bg:"rgba(248,113,113,0.10)",border:"rgba(248,113,113,0.25)"},refunded:{label:"REFUNDED",color:"#93c5fd",bg:"rgba(147,197,253,0.10)",border:"rgba(147,197,253,0.25)"}},Fr=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),Ar=({value:t,onChange:s,onKeyDown:r,placeholder:a,p:l})=>e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:l.mutedText}}),e.jsx("input",{value:t,onChange:e=>s(e.target.value),onKeyDown:r,placeholder:a,style:{width:"100%",padding:"9px 14px 9px 36px",borderRadius:10,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:l.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=l.inputFocusBorder,onBlur:e=>e.target.style.borderColor=l.inputBorder})]}),Rr=({value:t,onChange:s,options:r,p:a,minWidth:l=140})=>e.jsx("select",{value:t,onChange:e=>s(e.target.value),style:{padding:"9px 12px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",cursor:"pointer",minWidth:l,transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder,children:r.map(t=>e.jsx("option",{value:t.value,style:{background:"#1e0a3c"},children:t.label},t.value))}),Er=({title:t,value:s,sub:r,icon:a,iconAccent:l,p:n})=>e.jsx("div",{className:"rounded-2xl p-5",style:{background:n.statCardBg,border:`1px solid ${n.statCardBorder}`},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide mb-2",style:{color:n.mutedText},children:t}),e.jsx("p",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:n.headlineColor},children:s}),r&&e.jsx("p",{className:"text-xs mt-1",style:{color:n.mutedText},children:r})]}),e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:36,height:36,background:`${l}15`,border:`1px solid ${l}25`},children:a})]})}),Lr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(null),[d,u]=c.useState(null),[x,p]=c.useState(""),[g,b]=c.useState("all"),[y,f]=c.useState("all"),[v,w]=c.useState(1),[N,k]=c.useState(10),[_,C]=c.useState({totalRevenue:0,todayRevenue:0,pendingOrders:0,failedOrders:0}),B=c.useCallback(async()=>{n(!0),i(null);try{const{data:e,error:t}=await h.from("orders").select("*, profiles(email, full_name), credit_packs!fk_orders_pack(title, credits, price_inr)").order("created_at",{ascending:!1});if(t)throw t;const s=e||[];a(s);const r=new Date,l=new Date(r.getFullYear(),r.getMonth(),r.getDate()),n=s.filter(e=>"paid"===e.status);C({totalRevenue:n.reduce((e,t)=>
1e+(Number(t.amount_inr)||0),0),todayRevenue:n.filter(e=>new Date(e.created_at)>=l).reduce((e,t)=>e+(Number(t.amount_inr)||0),0),pendingOrders:s.filter(e=>"created"===e.status).length,failedOrders:s.filter(e=>"failed"===e.status).length})}catch(e){i((null==e?void 0:e.message)||"Failed to fetch orders")}finally{n(!1)}},[]);c.useEffect(()=>{B()},[B]),c.useEffect(()=>{w(1)},[x,g,y]);const T=r.filter(e=>{var t;const s=!x.trim()||((null==(t=e.profiles)?void 0:t.email)??"").toLowerCase().includes(x.toLowerCase()),r="all"===g||e.status===g;let a=!0;if("all"!==y){const t=new Date(e.created_at),s=new Date;"today"===y?a=t>=new Date(s.getFullYear(),s.getMonth(),s.getDate()):"week"===y?a=t>=new Date(s.getTime()-6048e5):"month"===y&&(a=t>=new Date(s.getTime()-2592e6))}return s&&r&&a}),S=Math.max(1,Math.ceil(T.length/N)),$=T.slice((v-1)*N,v*N);return l?e.jsxs("div",{className:"min-h-screen flex items-center justify-center",style:{background:s.sectionBg},children:[e.jsx(Fr,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading orders…"})]})]}):o?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-6",style:{background:s.sectionBg},children:[e.jsx(Fr,{p:s}),e.jsxs("div",{className:"relative z-10 rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:s.redAccent}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"Failed to load orders"}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:o}),e.jsxs("button",{type:"button",onClick:B,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})]}):e.jsxs("div",{className:"min-h-screen transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(Fr,{p:s}),e.jsxs("div",{className:"relative z-10 max-w-7xl mx-auto px-4 sm:px-6 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em] mb-1",style:{color:s.accentText},children:"Admin Console"}),e.jsx("h2",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:s.headlineColor},children:"Order Management"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:"View and manage all platform orders"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>(e=>{const t=[["Order ID","User","Email","Pack","Credits","Amount","Status","Promo","Referral","Payment","Date"],...e.map(e=>{var t,s,r,a;return[e.id,(null==(t=e.profiles)?void 0:t.full_name)??"N/A",(null==(s=e.profiles)?void 0:s.email)??"N/A",(null==(r=e.credit_packs)?void 0:r.title)??"N/A",(null==(a=e.credit_packs)?void 0:a.credits)??0,e.amount_inr,e.status,e.promo_code_used??"N/A",e.referral_code_used??"N/A",e.payment_method??"N/A",St(new Date(e.created_at),"yyyy-MM-dd HH:mm")]})].map(e=>e.join(",")).join("\n"),s=new Blob([t],{type:"text/csv"}),r=URL.createObjectURL(s),a=document.createElement("a");a.href=r,a.download=`orders-${St(new Date,"yyyy-MM-dd")}.csv`,a.click(),URL.revokeObjectURL(r)})(T),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export"})]}),e.jsx("button",{type:"button",onClick:B,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:e.jsx(re,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[{title:"Total Revenue",value:`₹${_.totalRevenue.toLocaleStr
1ing()}`,icon:e.jsx(Te,{className:"h-4 w-4",style:{color:s.greenAccent}}),iconAccent:s.greenAccent},{title:"Today Revenue",value:`₹${_.todayRevenue.toLocaleString()}`,icon:e.jsx(ke,{className:"h-4 w-4",style:{color:s.blueAccent}}),iconAccent:s.blueAccent},{title:"Pending",value:String(_.pendingOrders),icon:e.jsx(Se,{className:"h-4 w-4",style:{color:s.orangeAccent}}),iconAccent:s.orangeAccent},{title:"Failed",value:String(_.failedOrders),icon:e.jsx(le,{className:"h-4 w-4",style:{color:s.redAccent}}),iconAccent:s.redAccent}].map(t=>e.jsx(Er,{...t,p:s},t.title))}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(Ar,{value:x,onChange:p,placeholder:"Search by email…",p:s,onKeyDown:e=>"Enter"===e.key&&B()}),e.jsx(Rr,{value:g,onChange:e=>b(e),p:s,options:[{value:"all",label:"All Status"},{value:"created",label:"Created"},{value:"paid",label:"Paid"},{value:"failed",label:"Failed"},{value:"refunded",label:"Refunded"}]}),e.jsx(Rr,{value:y,onChange:e=>f(e),p:s,options:[{value:"all",label:"All Time"},{value:"today",label:"Today"},{value:"week",label:"Last 7 Days"},{value:"month",label:"Last 30 Days"}]})]}),e.jsxs("p",{className:"text-xs",style:{color:s.mutedText},children:["Showing ",$.length," of ",T.length," orders"]}),e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:1e3},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Order","User","Pack","Credits","Amount","Promo","Referral","Status","Date","Action"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:0===$.length?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"text-center py-12 text-sm",style:{color:s.mutedText},children:"No orders found"})}):$.map((t,r)=>{var a,l,n,o;const i=$r[t.status]??$r.created;return e.jsxs("tr",{style:{borderBottom:r<$.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4 font-mono text-xs",style:{color:s.mutedText},children:t.id.slice(0,8)}),e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("p",{className:"text-sm font-medium truncate max-w-[120px]",style:{color:s.bodyText},children:(null==(a=t.profiles)?void 0:a.full_name)??"—"}),e.jsx("p",{className:"text-xs truncate max-w-[120px]",style:{color:s.mutedText},children:(null==(l=t.profiles)?void 0:l.email)??"N/A"})]}),e.jsx("td",{className:"py-3 px-4 text-sm",style:{color:s.mutedText},children:(null==(n=t.credit_packs)?void 0:n.title)??"N/A"}),e.jsx("td",{className:"py-3 px-4 text-sm",style:{color:s.mutedText},children:(null==(o=t.credit_packs)?void 0:o.credits)??0}),e.jsxs("td",{className:"py-3 px-4 text-sm font-semibold",style:{color:s.bodyText},children:["₹",t.amount_inr]}),e.jsx("td",{className:"py-3 px-4",children:t.promo_code_used?e.jsx("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full",style:{background:s.badgeBg,border:`1px solid ${s.badgeBorder}`,color:s.accentText},children:t.promo_code_used}):e.jsx("span",{style:{color:s.mutedText},children:"—"})}),e.jsx("td",{className:"py-3 px-4",children:t.referral_code_used?e.jsx("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full",style:{background:"rgba(147,197,253,0.10)",border:"1px solid rgba(147,197,253,0.25)",color:s.blueAccent},children:t.referral_code_used}):e.jsx("span",{style:{color:s.mutedText},children:"—"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{color:i.color,background:i.bg,border:`1px solid ${i.border}`},children:i.label})}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:s.mutedText},children:St(new Date(t.created_at),"MMM dd, yyyy")}),e.jsx("td",{className:"py-3 px-4",children:"paid"===t.status&&e.jsxs("button",{type:"button",onClick:()=>(async e=>{const t=window.prompt("Enter refund reason:");if(null==t?void 0:t.trim()){u(e);try{const{error:s}=await h.functions.invoke("admin-initiate-refund",{body:{order_id:e,reason:t.trim()}});if(s)throw s;B()}catch(s){}finally{u(null)}}})(t.id),disabled:d===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all hover:opacity-80 disabled:opacity-50",style:{background:"rgba(248,113,113,0.10)",border:"1px solid rgba(248,113,113,0.25)",color:s.redAccent,cursor:d===t.id?"not-allowed":"pointer",fontFamily:"inherit"},children:[d===t.id?e.jsx(K,{className:"h-3 w-3 animate-spin"}):e.jsx(Z,{className:"h-3 w-3"}),"Refund"]})})]},t.id)})})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:"Rows per page:"}),e.jsx(Rr,{value:String(N),onChange:e=>{k(Number(e)),w(1)},p:s,minWidth:80,options:Sr.map(e=>({value:String(e),label:String(e)}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:["Page ",v," of ",S]}),[{icon:ne,dir:-1,disabled:v<=1},{icon:oe,dir:1,disabled:v>=S}].map(({icon:t,dir:r,disabled:a})=>e.jsx("button",{type:"button",disabled:a,onClick:()=>w(e=>e+r),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:a?"not-allowed":"pointer"},children:e.jsx(t,{className:"h-4 w-4"})},r))]})]})]})]})},Dr=({value:t,onChange:s,onKeyDown:r,placeholder:a,p:l})=>e.jsx("input",{type:"text",value:t,onChange:e=>s(e.target.value),onKeyDown:r,placeholder:a,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:l.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=l.inputFocusBorder,onBlur:e=>e.target.style.borderColor=l.inputBorder}),Mr=({onClick:t,disabled:s,children:r,p:a,variant:l="primary"})=>e.jsx("button",{type:"button",onClick:t,disabled:s,style:{width:38,height:38,borderRadius:10,border:"outline"===l?`1.5px solid ${a.btnOutlineBorder}`:"none",background:"outline"===l?"transparent":a.btnPrimaryBg,color:"outline"===l?a.btnOutlineText:"#fff",display:"flex",alignItems:"center",justifyContent:"center",cursor:s?"not-allowed":"pointer",opacity:s?.5:1,flexShrink:0,transition:"opacity 0.2s",fontFamily:"inherit"},children:r}),Ir=({variant:t,p:s,children:r})=>{const a={success:{bg:s.successBg,border:s.successBorder,color:s.greenAccent},pending:{bg:s.stepLockedBg,border:s.stepLockedBorder,color:s.mutedText},frozen:{bg:s.errorBg,border:s.errorBorder,color:s.redAccent},active:{bg:s.badgeBg,border:s.badgeBorder,color:s.accentText}}[t];return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 10px",borderRadius:999,fontSize:11,fontWeight:600,background:a.bg,border:`1px solid ${a.border}`,color:a.color},children:r})},Pr=({frozen:t,onClick:s,p:r})=>e.jsx("button",{type:"button",onClick:s,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 12px",borderRadius:8,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:"inherit",border:"none",background:t?r.btnPrimaryBg:r.errorBg,color:t?"#fff":r.redAccent,transition:"opacity 0.2s",whiteSpace:"nowrap"},onMouseEnter:e=>e.currentTarget.style.opacity="0.8",onMouseLeave:e=>e.currentTarget.style.opacity="1",children:t?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-3.5 w-3.5"})," Unfreeze"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-3.5 w-3.5"})," Freeze"]})}),Ur=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(""),d=async()=>{n(!0);try{const{data:e,error:t}=await h.from("profiles").select("user_id, full_name, email, referral_frozen, referrer_user_id, referral_signup_completed, first_purchase_completed, created_at").not("referrer_user_id","is",null).order("created_at",{ascending:!1});if(t)throw t;if(!e||0===e.length)return a([]),void n(!1);const s=[...new Set(e.map(e=>
1e.referrer_user_id).filter(Boolean))],{data:r,error:l}=await h.from("profiles").select("user_id, full_name, email, referral_frozen, referral_code").in("user_id",s),i=new Map((null==r?void 0:r.map(e=>[e.user_id,e]))||[]),d=e.map(e=>{const t=i.get(e.referrer_user_id);return{id:e.user_id,referrer_user_id:e.referrer_user_id,referee_user_id:e.user_id,referral_code:(null==t?void 0:t.referral_code)||"N/A",created_at:e.created_at,signup_reward_granted:e.referral_signup_completed||!1,first_purchase_reward_granted:e.first_purchase_completed||!1,referrer:t||null,referee:{user_id:e.user_id,full_name:e.full_name,email:e.email,referral_frozen:e.referral_frozen}}});let c=d;o&&(c=d.filter(e=>{var t,s,r,a,l;return(null==(s=null==(t=e.referrer)?void 0:t.email)?void 0:s.toLowerCase().includes(o.toLowerCase()))||(null==(a=null==(r=e.referee)?void 0:r.email)?void 0:a.toLowerCase().includes(o.toLowerCase()))||(null==(l=e.referral_code)?void 0:l.toLowerCase().includes(o.toLowerCase()))})),a(c)}catch(e){w.error(`Failed to fetch referrals: ${e.message||"Unknown error"}`)}finally{n(!1)}};c.useEffect(()=>{d()},[]);const u={padding:"10px 16px",textAlign:"left",fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:s.tableHeaderText,background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`,whiteSpace:"nowrap"},x={padding:"12px 16px",fontSize:13,color:s.bodyText,borderBottom:`1px solid ${s.tableBorder}`,verticalAlign:"middle"};return e.jsxs("div",{className:"rounded-2xl overflow-hidden w-full",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs("div",{className:"px-6 py-4",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Completed Referrals"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:"View and manage all referral relationships. Freeze referrers if abuse is detected."})]}),e.jsxs("div",{className:"px-6 py-4 flex gap-2",style:{borderBottom:`1px solid ${s.divider}`},children:[e.jsx(Dr,{value:o,onChange:i,onKeyDown:e=>"Enter"===e.key&&d(),placeholder:"Search by email or code...",p:s}),e.jsx(Mr,{onClick:d,disabled:l,p:s,variant:"primary",children:l?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(G,{className:"h-4 w-4"})}),e.jsx(Mr,{onClick:d,disabled:l,p:s,variant:"outline",children:e.jsx(re,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:900},children:[e.jsx("thead",{children:e.jsx("tr",{children:["Referral Code","Referrer","Referee","Signup Reward","First Purchase Reward","Status","Date","Actions"].map(t=>e.jsx("th",{style:u,children:t},t))})}),e.jsx("tbody",{children:l?e.jsx("tr",{children:e.jsx("td",{colSpan:8,style:{...x,textAlign:"center",padding:"32px"},children:e.jsx(K,{className:"h-6 w-6 animate-spin mx-auto",style:{color:s.accentText}})})}):0===r.length?e.jsx("tr",{children:e.jsx("td",{colSpan:8,style:{...x,textAlign:"center",padding:"32px",color:s.mutedText},children:"No referrals found"})}):r.map((t,r)=>{var a,l,n,o,i,c,u;return e.jsxs("tr",{style:{background:r%2==0?"transparent":s.infoRowBg},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background=r%2==0?"transparent":s.infoRowBg,children:[e.jsx("td",{style:{...x,fontFamily:"monospace",color:s.accentText},children:t.referral_code}),e.jsxs("td",{style:x,children:[e.jsx("div",{className:"font-medium text-sm",style:{color:s.headlineColor},children:null==(a=t.referrer)?void 0:a.full_name}),e.jsx("div",{className:"text-xs",style:{color:s.mutedText},children:null==(l=t.referrer)?void 0:l.email})]}),e.jsxs("td",{style:x,children:[e.jsx("div",{className:"font-medium text-sm",style:{color:s.headlineColor},children:null==(n=t.referee)?void 0:n.full_name}),e.jsx("div",{className:"text-xs",style:{color:s.mutedText},children:null==(o=t.referee)?void 0:o.email})]}),e.jsx("td",{style:x,children:e.jsx(Ir,{variant:t.signup_reward_granted?"success":"pending",p:s,children:t.signup_reward_granted?"Granted":"Pending"})}),e.jsx("td",{style:x,children:e.jsx(Ir,{variant:t.first_purchase_reward_granted?"success":"pending",p:s,children:t.first_purchase_reward_granted?"Granted":"Pending"})}),e.jsx("td",{style:x,children:e.jsx(Ir,{variant:(null==(i=t.referrer)?void 0:i.referral_frozen)?"frozen":"active",p:s,children:(null==(c=t.referrer)?void 0:c.referral_frozen)?"Frozen":"Active"})}),e.jsx("td",{style:x,children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{style:x,children:e.jsx(Pr,{frozen:null==(u=t.referrer)?void 0:u.referral_frozen,onClick:()=>{var e;return(async(e,t)=>{try{const{error:s}=await h.from("profiles").update({referral_frozen:!t}).eq("user_id",e);if(s)throw s;w.success(`Referrer ${t?"unfrozen":"frozen"}
1 successfully`),d()}catch(s){w.error("Failed to update referrer status")}})(t.referrer_user_id,null==(e=t.referrer)?void 0:e.referral_frozen)},p:s})})]},t.id)})})]})})]})},Or=({value:t,onChange:s,onKeyDown:r,placeholder:a,p:l})=>e.jsx("input",{type:"text",value:t,onChange:e=>s(e.target.value),onKeyDown:r,placeholder:a,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:l.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=l.inputFocusBorder,onBlur:e=>e.target.style.borderColor=l.inputBorder}),zr=({onClick:t,disabled:s,children:r,p:a,variant:l="primary"})=>e.jsx("button",{type:"button",onClick:t,disabled:s,style:{width:38,height:38,borderRadius:10,border:"outline"===l?`1.5px solid ${a.btnOutlineBorder}`:"none",background:"outline"===l?"transparent":a.btnPrimaryBg,color:"outline"===l?a.btnOutlineText:"#fff",display:"flex",alignItems:"center",justifyContent:"center",cursor:s?"not-allowed":"pointer",opacity:s?.5:1,flexShrink:0,transition:"opacity 0.2s",fontFamily:"inherit"},children:r}),Hr=({success:t,p:s,children:r})=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 10px",borderRadius:999,fontSize:11,fontWeight:600,background:t?s.successBg:s.errorBg,border:`1px solid ${t?s.successBorder:s.errorBorder}`,color:t?s.greenAccent:s.redAccent},children:r}),qr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(""),d=async()=>{n(!0);try{const{data:e,error:t}=await h.from("profiles").select("user_id, email, full_name, created_at, referrer_user_id, referral_signup_completed").not("referrer_user_id","is",null).order("created_at",{ascending:!1});if(t)throw t;if(!e||0===e.length)return a([]),void n(!1);const s=[...new Set(e.map(e=>e.referrer_user_id).filter(Boolean))],{data:r,error:l}=await h.from("profiles").select("user_id, email, full_name, referral_code").in("user_id",s),i=new Map((null==r?void 0:r.map(e=>[e.user_id,e]))||[]),d=e.map(e=>({...e,referrer:i.get(e.referrer_user_id)||null}));let c=d;o&&(c=d.filter(e=>{var t,s,r,a,l;return(null==(t=e.email)?void 0:t.toLowerCase().includes(o.toLowerCase()))||(null==(r=null==(s=e.referrer)?void 0:s.email)?void 0:r.toLowerCase().includes(o.toLowerCase()))||(null==(l=null==(a=e.referrer)?void 0:a.referral_code)?void 0:l.toLowerCase().includes(o.toLowerCase()))})),a(c)}catch(e){w.error(`Failed to fetch signup logs: ${e.message||"Unknown error"}`)}finally{n(!1)}};c.useEffect(()=>{d()},[]);const u={padding:"10px 16px",textAlign:"left",fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:s.tableHeaderText,background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`,whiteSpace:"nowrap"},x={padding:"12px 16px",fontSize:13,color:s.bodyText,borderBottom:`1px solid ${s.tableBorder}`,verticalAlign:"middle"};return e.jsxs("div",{className:"rounded-2xl overflow-hidden w-full",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs("div",{className:"px-6 py-4",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Recent Signup Logs"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:"View all users who signed up with a referral code. Check if rewards were granted correctly."})]}),e.jsxs("div",{className:"px-6 py-4 flex gap-2",style:{borderBottom:`1px solid ${s.divider}`},children:[e.jsx(Or,{value:o,onChange:i,onKeyDown:e=>"Enter"===e.key&&d(),placeholder:"Search by referee or referrer email...",p:s}),e.jsx(zr,{onClick:d,disabled:l,p:s,variant:"primary",children:l?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(G,{className:"h-4 w-4"})}),e.jsx(zr,{onClick:d,disabled:l,p:s,variant:"outline",children:e.jsx(re,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:600},children:[e.jsx("thead",{children:e.jsx("tr",{children:["Referee (New User)","Referrer","Referral Code","Signup Date","Reward Status"].map(t=>e.jsx("th",{style:u,children:t},t))})}),e.jsx("tbody",{children:l?e.jsx("tr",{children:e.jsx("td",{colSpan:5,style:{...x,textAlign:"center",padding:"32px"},children:e.jsx(K,{className:"h-6 w-6 animate-spin mx-auto",style:{color:s.accentText}})})}):0===r.length?e.jsx("tr",{children:e.jsx("td",{colSpan:5,style:{...x,textAlign:"center",padding:"32px",color:s.mutedText},children:"No signup logs found"})}):r.map((t,r)=>{var a,l,n;return e.jsxs("tr",{style:{background:r%2==0?"transparent":s.infoRowBg},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background=r%2==0?"transparent":s.infoRowBg,children:[e.jsxs("td",{style:x,children:[e.jsx("div",{className:"font-medium text-sm",style:{color:s.headlineColor},children:t.full_name}),e.jsx("div",{className:"text-xs",style:{color:s.mutedText},children:t.email})]}),e.jsxs("td",{style:x,children:[e.jsx("div",{className:"font-medium text-sm",style:{color:s.headlineColor},children:(null==(a=t.referrer)?void 0:a.full_name)||"N/A"}),e.jsx("div",{className:"text-xs",style:{color:s.mutedText},children:(null==(l=t.referrer)?void 0:l.email)||"N/A"})]}),e.jsx("td",{style:{...x,fontFamily:"monospace",color:s.accentText}
1,children:(null==(n=t.referrer)?void 0:n.referral_code)||"N/A"}),e.jsx("td",{style:x,children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{style:x,children:e.jsx(Hr,{success:!!t.referral_signup_completed,p:s,children:t.referral_signup_completed?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-3 w-3"})," Granted"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{className:"h-3 w-3"})," Pending/Failed"]})})})]},t.user_id)})})]})})]})},Wr=({id:t,type:s="email",value:r,onChange:a,onKeyDown:l,placeholder:n,p:o,disabled:i})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),onKeyDown:l,placeholder:n,disabled:i,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${o.inputBorder}`,background:o.inputBg,color:o.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s, opacity 0.2s",opacity:i?.5:1},onFocus:e=>!i&&(e.target.style.borderColor=o.inputFocusBorder),onBlur:e=>e.target.style.borderColor=o.inputBorder}),Vr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState(""),[l,n]=c.useState(""),[o,i]=c.useState(!1),[d,u]=c.useState(null),x=async()=>{const e=r.trim().toLowerCase(),t=l.trim().toLowerCase();if(e&&t)if(e!==t){i(!0),u(null);try{const{data:s,error:r}=await h.functions.invoke("admin-fix-referral",{body:{referee_email:e,referrer_email:t}});if(r)throw r;if(null==s?void 0:s.error)throw new Error(s.error);u({success:!0,message:(null==s?void 0:s.message)||"Referral fixed successfully",creditsGranted:null==s?void 0:s.credits_granted}),w.success("Referral fixed successfully!"),a(""),n("")}catch(s){u({success:!1,message:(null==s?void 0:s.message)||"Failed to fix referral"}),w.error("Failed to fix referral")}finally{i(!1)}}else w.error("Referee and referrer cannot be the same user");else w.error("Please enter both email addresses")},p=r.trim()&&l.trim()&&!o;return e.jsxs("div",{className:"w-full space-y-6",style:{fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(Ae,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Fix Referral Link"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:"Manually process a referral and grant all applicable rewards"})]})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"referee-email",className:"text-xs font-bold uppercase tracking-wide block",style:{color:s.labelText},children:"Referee Email"}),e.jsx("p",{className:"text-[11px]",style:{color:s.mutedText},children:"The new user who was referred"}),e.jsx(Wr,{id:"referee-email",value:r,onChange:a,onKeyDown:e=>"Enter"===e.key&&p&&x(),placeholder:"[email protected]",p:s,disabled:o})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"referrer-email",className:"text-xs font-bold uppercase tracking-wide block",style:{color:s.labelText},children:"Referrer Email"}),e.jsx("p",{className:"text-[11px]",style:{color:s.mutedText},children:"The existing user who made the referral"}),e.jsx(Wr,{id:"referrer-email",value:l,onChange:n,onKeyDown:e=>"Enter"===e.key&&p&&x(),placeholder:"[email protected]",p:s,disabled:o})]})]}),e.jsxs("div",{className:"rounded-xl px-4 py-3 flex items-start gap-3",style:{background:"rgba(167,139,250,0.07)",border:`1px solid ${s.cardBorder}`},children:[e.jsx(Ae,{className:"h-4 w-4 mt-0.5 flex-shrink-0",style:{color:s.accentText}}),e.jsx("p",{className:"text-xs leading-relaxed",style:{color:s.mutedText},children:"This tool will create the referral relationship and process all pending rewards according to the current referral policy settings. Only use this for cases where automatic processing genuinely failed."})]}),e.jsxs("button",{type:"button",onClick:x,disabled:!p,className:"w-full flex items-center justify-center gap-2 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{height:46,background:p?s.btnPrimaryBg:s.stepLockedBg,border:p?"none":`1px solid ${s.stepLockedBorder}`,color:p?"#fff":s.mutedText,cursor:p?"pointer":"not-allowed",fontFamily:"inherit"},children:[o?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(Ae,{className:"h-4 w-4"}),o?"Processing Referral...":"Fix Referral & Grant Credits"]})]})]}),d&&e.jsxs("div",{className:"rounded-2xl px-5 py-4 flex items-start gap-3 relative",style:{background:d.success?"rgba(52,211,153,0.08)":"rgba(248,113,113,0.08)",border:"1px solid "+(d.success?"rgba(52,211,153,0.25)":"rgba(248,113,113,0.25)")},children:[d.success?e.jsx(be,{className:"h-5 w-5 flex-shrink-0 mt-0.5",style:{color:s.greenAccent}}):e.jsx(Fe,{className:"h-5 w-5 flex-shrink-0 mt-0.5",style:{color:s.redAccent}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:d.success?s.greenAccent:s.redAccent},children:d.success?"Referral Fixed Successfully":"Fix Failed"}),e.jsx("p",{className:"text-xs mt-1",style:{color:s.mutedText},children:d.message}),d.success&&void 0!==d.creditsGranted&&e.jsxs("p",{className:"text-xs mt-1 font-semibold",style:{color:s.greenAccent},children:["Credits granted: ",d.creditsGranted]})]}),e.jsx("button",{type:"button",onClick:()=>u(null),className:"flex-shrink-0",style:{color:s.mutedText,cursor:"pointer",background:"none",border:"none"},"aria-label":"Dismiss",children:e.jsx(ye,{className:"h-4 w-4"})})]})]})},Gr=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx(Vr,{}),e.jsx(qr,{}),e.jsx(Ur,{})]}),Kr=({p:t})=>
1e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),Yr=({id:t,type:s="text",value:r,onChange:a,onKeyDown:l,placeholder:n,p:o,autoFocus:i})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),onKeyDown:l,placeholder:n,autoFocus:i,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${o.inputBorder}`,background:o.inputBg,color:o.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=o.inputFocusBorder,onBlur:e=>e.target.style.borderColor=o.inputBorder}),Jr=({message:t,type:s,p:r})=>e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-4 py-3 text-sm font-medium",role:"alert",style:{background:"error"===s?"rgba(248,113,113,0.12)":"rgba(110,231,183,0.12)",border:"1px solid "+("error"===s?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)"),color:"error"===s?r.redAccent:r.greenAccent},children:["error"===s?e.jsx(le,{className:"h-4 w-4 flex-shrink-0"}):e.jsx(be,{className:"h-4 w-4 flex-shrink-0"}),t]}),Qr=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(""),[x,p]=c.useState(null),g=(e,t="success")=>{p({message:e,type:t}),setTimeout(()=>p(null),4e3)},b=c.useCallback(async()=>{n(!0);try{const{data:e,error:t}=await h.from("user_roles").select("*").eq("role","admin").order("created_at",{ascending:!1});if(t)throw t;if(!e||0===e.length)return void a([]);const s=e.map(e=>e.user_id),{data:r,error:l}=await h.from("profiles").select("email, full_name, user_id").in("user_id",s);if(l)throw l;a(e.map(e=>({...e,profiles:(null==r?void 0:r.find(t=>t.user_id===e.user_id))??null})))}catch(e){g((null==e?void 0:e.message)||"Failed to fetch admin users","error")}finally{n(!1)}},[]);c.useEffect(()=>{b()},[b]);const y=async()=>{const e=d.trim().toLowerCase();if(e){i(!0);try{const{data:t,error:s}=await h.functions.invoke("admin-manage-roles",{body:{action:"grant_admin",target_email:e}});if(s)throw s;if(null==t?void 0:t.error)throw new Error(t.error);g(`Admin role granted to ${e}`),u(""),await b()}catch(t){g((null==t?void 0:t.message)||"Failed to grant admin role","error")}finally{i(!1)}}else g("Please enter an email address","error")};return e.jsxs("div",{className:"min-h-screen w-full transition-colors duration-300",style:{background:s.sectionBg,fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsx(Kr,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 lg:px-8 py-8 space-y-6",children:[x&&e.jsx(Jr,{message:x.message,type:x.type,p:s}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(X,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Grant Admin Access"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:"Add admin role to a user by email address"})]})]}),e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"admin-email",className:"text-xs font-bold uppercase tracking-wide block mb-2",style:{color:s.labelText},children:"User Email"}),e.jsx(Yr,{id:"admin-email",type:"email",value:d,onChange:u,onKeyDown:e=>"Enter"===e.key&&!o&&y(),placeholder:"[email protected]",p:s})]}),e.jsxs("button",{type:"button",onClick:y,disabled:o||!d.trim(),className:"flex items-center justify-center gap-2 px-6 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0 mt-auto",style:{height:42,background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:o?"not-allowed":"pointer",fontFamily:"inherit",minWidth:150},children:[o?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(Re,{className:"h-4 w-4"}),"Grant Admin"]})]})})]}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:s.
1cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between",style:{borderBottom:`1px solid ${s.divider}`,background:s.tableHeaderBg},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`},children:e.jsx(X,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:s.tableHeaderText},children:"Current Admin Users"}),e.jsxs("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:[r.length," admin",1!==r.length?"s":""," with platform access"]})]})]}),e.jsxs("button",{type:"button",onClick:b,disabled:l,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 disabled:opacity-50",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:l?"not-allowed":"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4 "+(l?"animate-spin":"")}),"Refresh"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:560},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Name","Email","Role","Granted","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-6 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:l?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-16",children:e.jsx(K,{className:"h-6 w-6 animate-spin mx-auto",style:{color:s.accentText}})})}):0===r.length?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-16 text-sm",style:{color:s.mutedText},children:"No admin users found"})}):r.map((t,a)=>{var l,n;return e.jsxs("tr",{style:{borderBottom:a<r.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3.5 px-6 font-medium",style:{color:s.bodyText},children:(null==(l=t.profiles)?void 0:l.full_name)||"—"}),e.jsx("td",{className:"py-3.5 px-6 text-sm",style:{color:s.mutedText},children:(null==(n=t.profiles)?void 0:n.email)||"—"}),e.jsx("td",{className:"py-3.5 px-6",children:e.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold px-2.5 py-0.5 rounded-full w-fit",style:{background:s.badgeBg,border:`1px solid ${s.badgeBorder}`,color:s.accentText},children:[e.jsx(X,{className:"h-3 w-3"}),"ADMIN"]})}),e.jsx("td",{className:"py-3.5 px-6 text-sm",style:{color:s.mutedText},children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{className:"py-3.5 px-6",children:e.jsxs("button",{type:"button",onClick:()=>{var e;return(async e=>{if(e&&window.confirm(`Revoke admin access for ${e}?`)){i(!0);try{const{data:t,error:s}=await h.functions.invoke("admin-manage-roles",{body:{action:"revoke_admin",target_email:e}});if(s)throw s;if(null==t?void 0:t.error)throw new Error(t.error);g(`Admin role revoked from ${e}`),await b()}catch(t){g((null==t?void 0:t.message)||"Failed to revoke admin role","error")}finally{i(!1)}}})(null==(e=t.profiles)?void 0:e.email)},disabled:o,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed",style:{background:"rgba(248,113,113,0.10)",border:"1px solid rgba(248,113,113,0.25)",color:s.redAccent,cursor:o?"not-allowed":"pointer",fontFamily:"inherit"},children:[e.jsx(Ee,{className:"h-3.5 w-3.5"}),"Revoke"]})})]},t.id)})})]})})]})]})]})},Xr=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),Zr=({value:t,onChange:s,placeholder:r,p:a})=>e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:a.mutedText}}),e.jsx("input",{value:t,onChange:e=>s(e.target.value),placeholder:r,style:{width:"100%",padding:"9px 14px 9px 36px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder})]}),ea=({value:t,onChange:s,options:r,p:a,minWidth:l=140})=>e.jsx("select",{value:t,onChange:e=>s(e.target.value),style:{padding:"9px 12px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",cursor:"pointer",minWidth:l,transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder,children:r.map(t=>e.jsx("option",{value:t.value,style:{background:"#1e0a3c"},children:t.label},t.value))}),ta=({title:t,value:s,icon:r,iconAccent:a,p:l})=>e.jsx("div",{className:"rounded-2xl p-5 transition-all duration-200",style:{background:l.statCardBg,border:`1px solid ${l.statCardBorder}`},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide mb-2",style:{color:l.mutedText},children:t}),e.jsx("p",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:l.headlineColor},children:s})]}),e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:36,height:36,background:`${a}15`,border:`1px solid ${a}25`}
1,children:r})]})}),sa=({status:t,p:s})=>{const r={success:{label:"✓ Success",color:s.greenAccent,bg:"rgba(110,231,183,0.10)",border:"rgba(110,231,183,0.25)"},failure:{label:"✗ Failure",color:s.redAccent,bg:"rgba(248,113,113,0.10)",border:"rgba(248,113,113,0.25)"},eval_failed:{label:"✗ Eval Fail",color:s.redAccent,bg:"rgba(248,113,113,0.10)",border:"rgba(248,113,113,0.25)"},cancelled:{label:"⊘ Cancelled",color:s.mutedText,bg:"rgba(255,255,255,0.05)",border:"rgba(255,255,255,0.12)"},in_progress:{label:"⏳ In Prog",color:s.orangeAccent,bg:"rgba(251,191,36,0.10)",border:"rgba(251,191,36,0.25)"},conn_failed:{label:"⊗ Conn Fail",color:s.orangeAccent,bg:"rgba(251,191,36,0.10)",border:"rgba(251,191,36,0.25)"},pending:{label:"· Pending",color:s.blueAccent,bg:"rgba(147,197,253,0.10)",border:"rgba(147,197,253,0.25)"}},a=r[t]??r.pending;return e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full whitespace-nowrap",style:{color:a.color,background:a.bg,border:`1px solid ${a.border}`},children:a.label})},ra=[10,25,50],aa=()=>{const t=u(),{resolvedTheme:s}=m(),r="light"===s?j.light:j.dark,[a,l]=c.useState([]),[n,o]=c.useState(!0),[i,d]=c.useState(null),[x,p]=c.useState(null),[g,b]=c.useState(!1),[y,f]=c.useState(""),[v,w]=c.useState("all"),[N,k]=c.useState("all"),[_,C]=c.useState(1),[B,T]=c.useState(10),[S,$]=c.useState({totalInterviews:0,completedCount:0,evaluationSuccessRate:0,avgScore:0,cancelledCount:0}),F=c.useCallback(async()=>{try{o(!0),d(null);const{data:e,error:t}=await h.from("interviews").select("id, interview_type, duration_minutes, status, completed_at, user_id, company_name, role_title").neq("status","setup").order("completed_at",{ascending:!1,nullsFirst:!1}).limit(500);if(t)throw t;if(!(null==e?void 0:e.length))return l([]),void $({totalInterviews:0,completedCount:0,evaluationSuccessRate:0,avgScore:0,cancelledCount:0});const s=[...new Set(e.map(e=>e.user_id).filter(Boolean))],r=e.map(e=>e.id),[{data:a},{data:n},{data:i},{data:c}]=await Promise.all([h.from("profiles").select("user_id, full_name, email").in("user_id",s),h.from("technical_interview_scores").select("interview_id, overall_technical_score").in("interview_id",r),h.from("behavioral_interview_scores").select("interview_id, overall_behavioral_score").in("interview_id",r),h.from("overall_interview_scores").select("interview_id, overall_overall_score").in("interview_id",r)]),u=e.map(e=>{const t=null==a?void 0:a.find(t=>t.user_id===e.user_id),s=null==n?void 0:n.find(t=>t.interview_id===e.id),r=null==i?void 0:i.find(t=>t.interview_id===e.id),l=null==c?void 0:c.find(t=>t.interview_id===e.id);let o="pending";return"cancelled"===e.status?o="cancelled":"evaluation_failed"===e.status?o="eval_failed":"connection_failed"===e.status?o="conn_failed":"in_progress"===e.status?o="in_progress":"completed"===e.status&&(o=null!=(null==s?void 0:s.overall_technical_score)||null!=(null==r?void 0:r.overall_behavioral_score)||null!=(null==l?void 0:l.overall_overall_score)?"success":"failure"),{interview_id:e.id,user_name:(null==t?void 0:t.full_name)||"Unknown",user_email:(null==t?void 0:t.email)||"N/A",interview_type:e.interview_type,duration_minutes:e.duration_minutes||0,interview_status:e.status,evaluation_status:o,completed_at:e.completed_at||"",technical_score:(null==s?void 0:s.overall_technical_score)??null,behavioral_score:(null==r?void 0:r.overall_behavioral_score)??null,overall_score:(null==l?void 0:l.overall_overall_score)??null,company_name:e.company_name||"N/A",role_title:e.role_title||"N/A"}});l(u);const x=u.filter(e=>"completed"===e.interview_status),p=u.filter(e=>"success"===e.evaluation_status).length,m=u.map(e=>e.technical_score??e.behavioral_score??e.overall_score).filter(e=>null!==e);$({totalInterviews:u.length,completedCount:x.length,evaluationSuccessRate:x.length>0?Math.round(p/x.length*100):0,avgScore:m.length>0?Math.round(m.reduce((e,t)=>e+t,0)/m.length):0,cancelledCount:u.filter(e=>"cancelled"===e.interview_status).length})}catch(e){d((null==e?void 0:e.message)||"Failed to load evaluations")}finally{o(!1)}},[]);c.useEffect(()=>{F()},[F]),c.useEffect(()=>{C(1)},[y,v,N]);const A=e=>{const t=[["User","Email","Interview ID","Type","Company","Role","Duration","Interview Status","Eval Status","Score","Completed At"],...e.map(e=>[e.user_name,e.user_email,e.interview_id,e.interview_type,e.company_name,e.role_title,e.duration_minutes,e.interview_status,e.evaluation_status,e.technical_score??e.behavioral_score??e.overall_score??"N/A",e.completed_at?St(new Date(e.completed_at),"yyyy-MM-dd HH:mm"):"N/A"])].map(e=>e.join(",")).join("\n"),s=new Blob([t],{type:"text/csv"}),r=URL.createObjectURL(s),a=document.createElement("a");a.href=r,a.download=`evaluations-${St(new Date,"yyyy-MM-dd")}.csv`,a.click(),URL.revokeObjectURL(r)},R=a.filter(e=>{const t=y.toLowerCase(),s=e.user_name.toLowerCase().includes(t)||e.user_email.toLowerCase().includes(t)||e.interview_id.toLowerCase().includes(t)||e.company_name.toLowerCase().includes(t)||e.role_title.toLowerCase().includes(t),r="all"===v||e.interview_type===v,a="all"===N||e.evaluation_status===N||e.interview_status===N;return s&&r&&a}),E=Math.max(1,Math.ceil(R.length/B)),L=R.slice((_-1)*B,_*B),D=R.filter(e=>"failure"===e.evaluation_status||"eval_failed"===e.evaluation_status).length;return n?e.jsxs("div",{className:"w-full flex items-center justify-center py-20",style:{background:r.sectionBg},children:[e.jsx(Xr,{p:r}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:r.accentText}}),e.jsx("p",{className:"text-sm",style:{color:r.mutedText},children:"Loading evaluations…"})]})]}):i?e.jsxs("div",{className:"w-full flex items-center justify-center p-6",style:{background:r.sectionBg},children:[e.jsx(Xr,{p:r}),e.jsxs("div",{className:"relative z-10 rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:r.cardBg,border:`1px solid ${r.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:r.redAccent}}),e.jsx("p",{className:"font-semibold",style:{color:r.headlineColor},children:"Failed to load evaluations"}),e.jsx("p",{className:"text-sm",style:{color:r.mutedText},children:i}),e.jsxs("button",{type:"button",onClick:F,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:r.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})]}):e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:r.sectionBg},children:[e.jsx(Xr,{p:r}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 py-8 space-y-6",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("button",{type:"button",onClick:F,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:r.stepLockedBg,border:`1px solid ${r.stepLockedBorder}`,color:r.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Refresh"]})}
1),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-4",children:[{title:"Total",value:S.totalInterviews,icon:e.jsx(Le,{className:"h-4 w-4",style:{color:r.purpleAccent}}),iconAccent:r.purpleAccent},{title:"Completed",value:S.completedCount,icon:e.jsx(be,{className:"h-4 w-4",style:{color:r.greenAccent}}),iconAccent:r.greenAccent},{title:"Eval Success",value:`${S.evaluationSuccessRate}%`,icon:e.jsx(be,{className:"h-4 w-4",style:{color:r.blueAccent}}),iconAccent:r.blueAccent},{title:"Avg Score",value:S.avgScore,icon:e.jsx(Se,{className:"h-4 w-4",style:{color:r.orangeAccent}}),iconAccent:r.orangeAccent},{title:"Cancelled",value:S.cancelledCount,icon:e.jsx(De,{className:"h-4 w-4",style:{color:r.redAccent}}),iconAccent:r.redAccent}].map(t=>e.jsx(ta,{...t,p:r},t.title))}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(Zr,{value:y,onChange:f,placeholder:"Search by name, email, company, role or ID…",p:r}),e.jsx(ea,{value:v,onChange:w,p:r,options:[{value:"all",label:"All Types"},{value:"technical",label:"Technical"},{value:"behavioral",label:"Behavioral"},{value:"overall",label:"360° Interview"}]}),e.jsx(ea,{value:N,onChange:k,p:r,minWidth:160,options:[{value:"all",label:"All Status"},{value:"success",label:"Eval Success"},{value:"failure",label:"Eval Failure"},{value:"cancelled",label:"Cancelled"},{value:"in_progress",label:"In Progress"},{value:"eval_failed",label:"Eval Failed"}]}),D>0&&e.jsxs("button",{type:"button",onClick:async()=>{const e=R.filter(e=>"failure"===e.evaluation_status||"eval_failed"===e.evaluation_status).slice(0,10);e.length&&window.confirm(`Regenerate ${e.length} failed evaluations?`)&&(b(!0),await Promise.allSettled(e.map(e=>h.functions.invoke("regenerate-evaluations",{body:{interview_id:e.interview_id,interview_type:e.interview_type}}))),b(!1),setTimeout(()=>F(),5e3))},disabled:g,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80 disabled:opacity-50",style:{background:"rgba(248,113,113,0.15)",border:"1px solid rgba(248,113,113,0.30)",color:r.redAccent,cursor:g?"not-allowed":"pointer",fontFamily:"inherit"},children:[g?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(re,{className:"h-4 w-4"}),"Regen Failed (",Math.min(D,10),")"]}),e.jsxs("button",{type:"button",onClick:()=>A(R),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:r.stepLockedBg,border:`1px solid ${r.stepLockedBorder}`,color:r.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export"})]}),D>0&&e.jsxs("button",{type:"button",onClick:()=>A(R.filter(e=>"failure"===e.evaluation_status||"eval_failed"===e.evaluation_status)),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:r.stepLockedBg,border:`1px solid ${r.stepLockedBorder}`,color:r.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export Failed"})]})]}),e.jsxs("p",{className:"text-xs",style:{color:r.mutedText},children:["Showing ",L.length," of ",R.length," evaluations"]}),e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${r.cardBorder}`,background:r.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:1100},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:r.tableHeaderBg,borderBottom:`1px solid ${r.tableBorder}`},children:["User","Company","Role","Type","Min","Status","Score","Date","Interview ID","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:r.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:0===L.length?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"text-center py-12 text-sm",style:{color:r.mutedText},children:"No evaluations found"})}):L.map((s,a)=>{var l,n;return e.jsxs("tr",{style:{borderBottom:a<L.length-1?`1px solid ${r.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=r.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("p",{className:"font-medium text-sm truncate max-w-[130px]",style:{color:r.bodyText},children:s.user_name}),e.jsx("p",{className:"text-xs truncate max-w-[130px]",style:{color:r.mutedText},children:s.user_email})]}),e.jsx("td",{className:"py-3 px-4 text-sm truncate max-w-[100px]",style:{color:r.mutedText},children:s.company_name}),e.jsx("td",{className:"py-3 px-4 text-sm truncate max-w-[100px]",style:{color:r.mutedText},children:s.role_title}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full capitalize",style:{background:r.badgeBg,border:`1px solid ${r.badgeBorder}`,color:r.accentText},children:(null==(l=s.interview_type)?void 0:l.substring(0,4))??"N/A"})}),e.jsx("td",{className:"py-3 px-4 text-sm",style:{color:r.mutedText},children:s.duration_minutes}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(sa,{status:s.evaluation_status,p:r})}),e.jsx("td",{className:"py-3 px-4 text-sm font-semibold",style:{color:r.bodyText},children:(null==(n=s.technical_score??s.behavioral_score??s.overall_score)?void 0:n.toFixed(0))??"—"}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:r.mutedText},children:s.completed_at?St(new Date(s.completed_at),"MMM dd"):"—"}),e.jsx("td",{className:"py-3 px-4 font-mono text-xs truncate max-w-[180px]",style:{color:r.mutedText},children:s.interview_id}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("div",{className:"flex gap-2 justify-end",children:[{icon:Me,onClick:()=>(async(e,s)=>{t({technical:`/interview/${e}/technical-feedback`,behavioral:`/interview/${e}/behavioral-feedback`,overall:`/interview/${e}/360-feedback`}[s]??`/interview/${e}/technical-feedback`)})(s.interview_id,s.interview_type),title:"View"},{icon:x===s.interview_id?K:re,onClick:()=>(async(e,t)=>{p(e);try{const{error:s}=await h.functions.invoke("regenerate-evaluations",{body:{interview_id:e,interview_type:t}});if(s)throw s;setTimeout(()=>F(),5e3)}catch(s){}finally{p(null)}})(s.interview_id,s.interview_type),title:"Regenerate",spin:x===s.interview_id}].map(({icon:t,onClick:a,title:l,spin:n})=>e.jsx("button",{type:"button",onClick:a,disabled:x===s.interview_id,title:l,"aria-label":l,className:"rounded-lg flex items-center justify-center transition-all hover:opacity-80 disabled:opacity-40",style:{width:32,height:32,background:r.stepLockedBg,border:`1px solid ${r.stepLockedBorder}`,color:r.bodyText,cursor:"pointer"},children:e.jsx(t,{className:"h-3.5 w-3.5 "+(n?"animate-spin":"")})},l))})})]},s.interview_id)})})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",style:{color:r.mutedText},children:"Rows per page:"}),e.jsx(ea,{value:String(B),onChange:e=>{T(Number(e)),C(1)},p:r,options:ra.map(e=>({value:String(e),label:String(e)})),minWidth:80})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",style:{color:r.mutedText},children:["Page ",_," of ",E]}),[{icon:ne,dir:-1,disabled:_<=1},{icon:oe,dir:1,disabled:_>=E}].map(({icon:t,dir:s,disabled:a})=>e.jsx("button",{type:"button",disabled:a,onClick:()=>C(e=>e+s),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:r.stepLockedBg,border:`1px solid ${r.stepLockedBorder}`,color:r.bodyText,cursor:a?"not-allowed":"pointer"},children:e.jsx(t,{className:"h-4 w-4"})},s))]})]})]})]})}
1,la={dark:{sectionBg:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",cardBg:"rgba(255,255,255,0.04)",cardBorder:"rgba(255,255,255,0.09)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.65)",mutedText:"rgba(255,255,255,0.38)",labelText:"rgba(255,255,255,0.45)",accentText:"#a78bfa",accentBg:"rgba(139,92,246,0.18)",accentBorder:"rgba(139,92,246,0.40)",divider:"rgba(255,255,255,0.07)",progressBg:"rgba(255,255,255,0.10)",progressFill:"rgba(139,92,246,0.70)",successText:"#6ee7b7",successBg:"rgba(16,185,129,0.15)",warnText:"#fcd34d",errorText:"#fca5a5",errorBg:"rgba(239,68,68,0.12)",errorBorder:"rgba(239,68,68,0.35)",tableRowHover:"rgba(255,255,255,0.04)",tableHeaderBg:"rgba(255,255,255,0.06)",tableHeaderText:"rgba(255,255,255,0.50)",badgePaidBg:"rgba(16,185,129,0.15)",badgePaidBorder:"rgba(16,185,129,0.40)",badgePaidText:"#6ee7b7",badgeWarnBg:"rgba(245,158,11,0.15)",badgeWarnBorder:"rgba(245,158,11,0.40)",badgeWarnText:"#fcd34d"},light:{sectionBg:"linear-gradient(160deg, #2D0550 0%, #5B1280 50%, #3D0A6E 100%)",cardBg:"rgba(255,255,255,0.07)",cardBorder:"rgba(255,255,255,0.14)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.80)",mutedText:"rgba(255,255,255,0.50)",labelText:"rgba(255,255,255,0.55)",accentText:"#c4b5fd",accentBg:"rgba(167,139,250,0.20)",accentBorder:"rgba(167,139,250,0.50)",divider:"rgba(255,255,255,0.14)",progressBg:"rgba(255,255,255,0.18)",progressFill:"rgba(167,139,250,0.75)",successText:"#a7f3d0",successBg:"rgba(16,185,129,0.18)",warnText:"#fde68a",errorText:"#fca5a5",errorBg:"rgba(239,68,68,0.14)",errorBorder:"rgba(239,68,68,0.40)",tableRowHover:"rgba(255,255,255,0.07)",tableHeaderBg:"rgba(255,255,255,0.10)",tableHeaderText:"rgba(255,255,255,0.60)",badgePaidBg:"rgba(16,185,129,0.18)",badgePaidBorder:"rgba(16,185,129,0.50)",badgePaidText:"#a7f3d0",badgeWarnBg:"rgba(245,158,11,0.18)",badgeWarnBorder:"rgba(245,158,11,0.45)",badgeWarnText:"#fde68a"}},na=({label:t,value:s,sub:r,accent:a=!1,p:l})=>e.jsxs("div",{className:"rounded-xl p-4 flex flex-col gap-1 transition-all hover:scale-[1.02]",style:{background:a?l.accentBg:l.cardBg,border:`1px solid ${a?l.accentBorder:l.cardBorder}`},children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.12em]",style:{color:l.mutedText},children:t}),e.jsx("span",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:l.headlineColor},children:s}),r&&e.jsx("span",{className:"text-xs",style:{color:l.mutedText},children:r})]}),oa=({title:t,desc:s,children:r,p:a})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:a.cardBg,border:`1px solid ${a.cardBorder}`},children:[e.jsxs("div",{className:"px-5 py-4",style:{borderBottom:`1px solid ${a.divider}`},children:[e.jsx("h3",{className:"text-sm font-bold",style:{fontFamily:"'Roboto Slab',serif",color:a.headlineColor},children:t}),s&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:a.mutedText},children:s})]}),e.jsx("div",{className:"p-5",children:r})]}),ia=({value:t,p:s})=>e.jsx("div",{className:"w-full h-2 rounded-full overflow-hidden",style:{background:s.progressBg},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${Math.min(t,100)}%`,background:s.progressFill}})}),da=({onClick:t,loading:s,p:r})=>e.jsxs("button",{onClick:t,disabled:s,className:"flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs font-semibold transition-all hover:scale-[1.03] disabled:opacity-50",style:{background:r.accentBg,border:`1px solid ${r.accentBorder}`,color:r.accentText},children:[e.jsxs("svg",{className:"w-3.5 h-3.5 "+(s?"animate-spin":""),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M23 4v6h-6M1 20v-6h6"}),e.jsx("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]}),"Refresh"]}),ca=({p:t})=>e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full animate-spin border-2 border-transparent",style:{borderTopColor:t.accentText,borderRightColor:t.accentBorder}}),e.jsx("p",{className:"text-xs",style:{color:t.mutedText},children:"Loading data…"})]})});function ua(){const{resolvedTheme:e}=m();return"light"===e?la.light:la.dark}const xa={totalInterviewTime:0,technicalInterviewTime:0,behavioralInterviewTime:0,overallInterviewTime:0,dailyActiveUsers:0,weeklyActiveUsers:0,monthlyActiveUsers:0,totalTokensConsumed:0,technicalEvaluationFailures:0,behavioralEvaluationFailures:0,overallEvaluationFailures:0,experienceDistribution:{},durationDistribution:{},totalPurchases:0,repeatUsers:0,repeatPercentage:0,totalSignups:0,todaySignups:0,weekSignups:0,monthSignups:0,totalCompletedInterviews:0,interviewsInProgress:0,completionRate:0,totalRevenue:0,monthlyRevenue:0,avgOrderValue:0,conversionRate:0,topCompanies:[],topRoles:[]},pa=({title:t,description:s,p:r})=>e.jsxs("div",{className:"px-6 py-4",style:{borderBottom:`1px solid ${r.divi
1der}`,background:r.tableHeaderBg},children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:r.tableHeaderText},children:t}),s&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:r.mutedText},children:s})]}),ma=({title:t,description:s,children:r,p:a})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:a.cardBg,border:`1px solid ${a.cardBorder}`},children:[e.jsx(pa,{title:t,description:s,p:a}),e.jsx("div",{className:"p-5",children:r})]}),ha=({headers:t,rows:s,p:r})=>e.jsx("div",{className:"overflow-x-auto rounded-xl",style:{border:`1px solid ${r.divider}`},children:e.jsxs("table",{className:"w-full text-sm min-w-[600px]",children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:r.tableHeaderBg,borderBottom:`1px solid ${r.divider}`},children:t.map(t=>e.jsx("th",{className:"text-left py-3 px-4 font-semibold uppercase tracking-wide text-xs",style:{color:r.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:s.map((t,a)=>e.jsx("tr",{style:{borderBottom:a<s.length-1?`1px solid ${r.divider}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=r.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:t.map((t,s)=>e.jsx("td",{className:"py-3 px-4 text-right first:text-left",style:{color:0===s?r.bodyText:r.mutedText},children:t},s))},a))})]})}),ga=()=>{const t=ua(),[s,r]=c.useState(!0),[a,l]=c.useState(null),[n,o]=c.useState(xa),i=e=>{const t=Math.floor(e/60),s=e%60;return t>0?`${t}h ${s}m`:`${s}m`},d=(e,t,s)=>{const r=[s,...e].map(e=>e.join(",")).join("\n"),a=new Blob([r],{type:"text/csv"}),l=window.URL.createObjectURL(a),n=document.createElement("a");n.href=l,n.download=`${t}-${St(new Date,"yyyy-MM-dd")}.csv`,n.click(),window.URL.revokeObjectURL(l)},u=c.useCallback(async()=>{try{r(!0),l(null);const e=new Date,t=new Date(e.getTime()-864e5),s=new Date(e.getTime()-6048e5),a=new Date(e.getTime()-2592e6),[{data:n},{data:i},{data:d},{data:c},{data:u},{data:x},{data:p},{data:m}]=await Promise.all([h.from("interviews").select("*"),h.from("interviews").select("user_id").gte("created_at",t.toISOString()),h.from("interviews").select("user_id").gte("created_at",s.toISOString()),h.from("interviews").select("user_id").gte("created_at",a.toISOString()),h.from("interviews").select("tokens_used").eq("status","completed").not("tokens_used","is",null),h.from("evaluation_status").select("evaluation_type, status").eq("status","failed"),h.from("profiles").select("user_id, years_of_experience, created_at"),h.from("orders").select("user_id, amount_inr, status, created_at")]),g=(null==n?void 0:n.filter(e=>"completed"===e.status))||[],b=(null==n?void 0:n.filter(e=>"in_progress"===e.status))||[],y=g.length+b.length,f=y>0?Math.round(g.length/y*100):0;let v=0,j=0,w=0,N=0;const k={"5 min":{completedInterviews:0,technicalInterviews:0,behavioralInterviews:0,overallInterviews:0,uniqueUsers:0},"15 min":{completedInterviews:0,technicalInterviews:0,behavioralInterviews:0,overallInterviews:0,uniqueUsers:0},"30 min":{completedInterviews:0,technicalInterviews:0,behavioralInterviews:0,overallInterviews:0,uniqueUsers:0}},_={"5 min":new Set,"15 min":new Set,"30 min":new Set},C={},B={};g.forEach(e=>{const t=e.duration_minutes||0;v+=t,"technical"===e.interview_type?j+=t:"behavioral"===e.interview_type?w+=t:"overall"===e.interview_type&&(N+=t);const s=t<=5?"5 min":t<=15?"15 min":"30 min";k[s].completedInterviews+=1,_[s].add(e.user_id),"technical"===e.interview_type?k[s].technicalInterviews+=1:"behavioral"===e.interview_type?k[s].behavioralInterviews+=1:"overall"===e.interview_type&&(k[s].overallInterviews+=1),e.company_name&&(C[e.company_name.trim()]=(C[e.company_name.trim()]||0)+1),e.role_title&&(B[e.role_title.trim()]=(B[e.role_title.trim()]||0)+1)}),Object.entries(_).forEach(([e,t])=>{k[e].uniqueUsers=t.size});const T=Object.entries(C).sort((e,t)=>t[1]-e[1]).slice(0,10).map(([e,t])=>({name:e,count:t})),S=Object.entries(B).sort((e,t)=>t[1]-e[1]).slice(0,10).map(([e,t])=>({title:e,count:t})),$=(null==p?void 0:p.length)||0,F=(null==p?void 0:p.filter(e=>new Date(e.created_at)>=t).length)||0,A=(null==p?void 0:p.filter(e=>new Date(e.created_at)>=s).length)||0,R=(null==p?void 0:p.filter(e=>new Date(e.created_at)>=a).length)||0,E={};
1null==p||p.forEach(e=>{E[e.user_id]=e.years_of_experience||"Not specified"});const L={};null==p||p.forEach(e=>{const t=e.years_of_experience||"Not specified";L[t]||(L[t]={totalUsers:0,uniqueUsersWithInterviews:0,totalInterviews:0,technicalInterviews:0,behavioralInterviews:0,overallInterviews:0,totalTime:0,technicalTime:0,behavioralTime:0,overallTime:0}),L[t].totalUsers+=1});const D={};g.forEach(e=>{const t=E[e.user_id]||"Not specified";if(D[t]||(D[t]=new Set),D[t].add(e.user_id),L[t]){L[t].totalInterviews+=1;const s=e.duration_minutes||0;L[t].totalTime+=s,"technical"===e.interview_type?(L[t].technicalInterviews+=1,L[t].technicalTime+=s):"behavioral"===e.interview_type?(L[t].behavioralInterviews+=1,L[t].behavioralTime+=s):"overall"===e.interview_type&&(L[t].overallInterviews+=1,L[t].overallTime+=s)}}),Object.entries(D).forEach(([e,t])=>{L[e]&&(L[e].uniqueUsersWithInterviews=t.size)});const M=(null==m?void 0:m.filter(e=>"paid"===e.status))||[],I=M.length,P=new Set(M.map(e=>e.user_id)).size,U=Math.max(0,I-P),O=P>0?Math.round(U/P*100):0,z=M.reduce((e,t)=>e+(Number(t.amount_inr)||0),0),H=M.filter(e=>new Date(e.created_at)>=a).reduce((e,t)=>e+(Number(t.amount_inr)||0),0),q=I>0?Math.round(z/I):0,W=$>0?Math.round(P/$*100):0;o({totalInterviewTime:v,technicalInterviewTime:j,behavioralInterviewTime:w,overallInterviewTime:N,dailyActiveUsers:new Set(null==i?void 0:i.map(e=>e.user_id)).size,weeklyActiveUsers:new Set(null==d?void 0:d.map(e=>e.user_id)).size,monthlyActiveUsers:new Set(null==c?void 0:c.map(e=>e.user_id)).size,totalTokensConsumed:(null==u?void 0:u.reduce((e,t)=>e+(t.tokens_used||0),0))||0,technicalEvaluationFailures:(null==x?void 0:x.filter(e=>"technical"===e.evaluation_type).length)||0,behavioralEvaluationFailures:(null==x?void 0:x.filter(e=>"behavioral"===e.evaluation_type).length)||0,overallEvaluationFailures:(null==x?void 0:x.filter(e=>"overall"===e.evaluation_type).length)||0,experienceDistribution:L,durationDistribution:k,totalPurchases:I,repeatUsers:U,repeatPercentage:O,totalSignups:$,todaySignups:F,weekSignups:A,monthSignups:R,totalCompletedInterviews:g.length,interviewsInProgress:b.length,completionRate:f,totalRevenue:z,monthlyRevenue:H,avgOrderValue:q,conversionRate:W,topCompanies:T,topRoles:S})}catch(e){l((null==e?void 0:e.message)||"Failed to load analytics")}finally{r(!1)}},[]);if(c.useEffect(()=>{u()},[u]),s)return e.jsx(ca,{p:t});if(a)return e.jsx("div",{className:"flex items-center justify-center p-6 min-h-[300px]",children:e.jsxs("div",{className:"rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:t.errorText}}),e.jsx("p",{className:"font-semibold",style:{color:t.headlineColor},children:"Failed to load analytics"}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:a}),e.jsxs("button",{type:"button",onClick:u,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:t.accentBg,color:t.accentText,border:`1px solid ${t.accentBorder}`,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})});const x=n;return e.jsxs("div",{className:"space-y-6 px-4 sm:px-6 py-6",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsx("h2",{className:"text-xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:"Platform Analytics"}),e.jsx(da,{onClick:u,loading:s,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Signups",value:x.totalSignups,accent:!0,p:t}),e.jsx(na,{label:"Today Signups",value:x.todaySignups,p:t}),e.jsx(na,{label:"Week Signups",value:x.weekSignups,p:t}),e.jsx(na,{label:"Month Signups",value:x.monthSignups,p:t})]}),e.jsxs(ma,{title:"Interview Funnel",description:"Completion metrics",p:t,children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4",children:[e.jsx(na,{label:"Completed",value:e.jsx("span",{style:{color:t.successText},children:x.totalCompletedInterviews}),p:t}),e.jsx(na,{label:"In Progress",value:e.jsx("span",{style:{color:t.warnText},children:x.interviewsInProgress}),p:t}),e.jsx(na,{label:"Completion Rate",value:e.jsxs("span",{style:{color:t.accentText},children:[x.completionRate,"%"]}),p:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-xs",style:{color:t.mutedText},children:[e.jsx("span",{children:"Completion Rate"}),e.jsxs("span",{style:{color:t.bodyText},children:[x.completionRate,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full overflow-hidden",style:{background:t.divider},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${x.completionRate}%`,background:"linear-gradient(to right,rgba(139,92,246,0.80),rgba(167,139,250,1))"}})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Revenue",value:`₹${x.totalRevenue.toLocaleStr
1ing()}`,accent:!0,p:t}),e.jsx(na,{label:"Monthly Revenue",value:`₹${x.monthlyRevenue.toLocaleString()}`,p:t}),e.jsx(na,{label:"Avg Order Value",value:`₹${x.avgOrderValue}`,p:t}),e.jsx(na,{label:"Conversion Rate",value:`${x.conversionRate}%`,p:t})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[{title:"Top Companies",icon:e.jsx(Ie,{className:"h-4 w-4",style:{color:t.accentText}}),items:x.topCompanies.map(e=>({name:e.name,count:e.count}))},{title:"Top Role Titles",icon:e.jsx(Pe,{className:"h-4 w-4",style:{color:t.accentText}}),items:x.topRoles.map(e=>({name:e.title,count:e.count}))}].map(({title:s,icon:r,items:a})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-2",style:{borderBottom:`1px solid ${t.divider}`,background:t.tableHeaderBg},children:[r,e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:t.tableHeaderText},children:s})]}),e.jsx("div",{className:"p-5 space-y-1",children:0===a.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):a.map((s,r)=>e.jsxs("div",{className:"flex justify-between items-center py-2 text-sm",style:{borderBottom:r<a.length-1?`1px solid ${t.divider}`:"none"},children:[e.jsx("span",{className:"truncate max-w-[200px]",style:{color:t.bodyText},children:s.name}),e.jsx("span",{className:"font-semibold flex-shrink-0",style:{color:t.accentText},children:s.count})]},r))})]},s))}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Interview Time",value:i(x.totalInterviewTime),p:t}),e.jsx(na,{label:"Technical Time",value:i(x.technicalInterviewTime),p:t}),e.jsx(na,{label:"Behavioral Time",value:i(x.behavioralInterviewTime),p:t}),e.jsx(na,{label:"360° Interview Time",value:i(x.overallInterviewTime),p:t})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(na,{label:"Daily Active Users",value:x.dailyActiveUsers,p:t}),e.jsx(na,{label:"Weekly Active Users",value:x.weeklyActiveUsers,p:t}),e.jsx(na,{label:"Monthly Active Users",value:x.monthlyActiveUsers,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Tokens",value:x.totalTokensConsumed.toLocaleString(),p:t}),e.jsx(na,{label:"Technical Eval Failures",value:e.jsx("span",{style:{color:t.errorText},children:x.technicalEvaluationFailures}),p:t}),e.jsx(na,{label:"Behavioral Eval Failures",value:e.jsx("span",{style:{color:t.errorText},children:x.behavioralEvaluationFailures}),p:t}),e.jsx(na,{label:"360° Eval Failures",value:e.jsx("span",{style:{color:t.errorText},children:x.overallEvaluationFailures}),p:t})]}),e.jsxs(ma,{title:"Interview Duration Distribution",description:"Metrics by selected interview duration",p:t,children:[e.jsx(ha,{p:t,headers:["Duration","Completed","Technical","Behavioral","360°","Unique Users"],rows:Object.entries(x.durationDistribution).map(([e,t])=>[e,t.completedInterviews,t.technicalInterviews,t.behavioralInterviews,t.overallInterviews,t.uniqueUsers])}),e.jsxs("button",{type:"button",onClick:()=>d(Object.entries(x.durationDistribution).map(([e,t])=>[e,t.completedInterviews,t.technicalInterviews,t.behavioralInterviews,t.overallInterviews,t.uniqueUsers]),"duration-distribution",["Duration","Completed","Technical","Behavioral","360°","Unique Users"]),className:"mt-4 flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-semibold transition-opacity hover:opacity-80",style:{background:t.accentBg,border:`1px solid ${t.accentBorder}`,color:t.accentText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-3 w-3"})," Export Duration Stats"]})]}),e.jsxs(ma,{title:"Years of Experience Distribution",description:"User and interview metrics by experience level",p:t,children:[e.jsx(ha,{p:t,headers:["Experience","Total Users","Unique Users","Total Interviews","Technical","Behavioral","360°","Total Time"],rows:Object.entries(x.experienceDistribution).map(([e,t])=>[e,t.totalUsers,t.uniqueUsersWithInterviews,t.totalInterviews,t.technicalInterviews,t.behavioralInterviews,t.overallInterviews,i(t.totalTime)])}),e.jsxs("button",{type:"button",onClick:()=>d(Object.entries(x.experienceDistribution).map(([e,t])=>[e,t.totalUsers,t.uniqueUsersWithInterviews,t.totalInterviews,t.technicalInterviews,t.behavioralInterviews,t.overallInterviews,t.totalTime]),"experience-distribution",["Experience","Total Users","Unique Users","Total Interviews","Technical","Behavioral","3
160°","Total Time (min)"]),className:"mt-4 flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-semibold transition-opacity hover:opacity-80",style:{background:t.accentBg,border:`1px solid ${t.accentBorder}`,color:t.accentText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-3 w-3"})," Export Distribution"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(na,{label:"Total Purchases",value:x.totalPurchases,accent:!0,p:t}),e.jsx(na,{label:"Repeat Users",value:x.repeatUsers,p:t}),e.jsx(na,{label:"Repeat Purchase %",value:`${x.repeatPercentage}%`,p:t})]})]})},ba=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),ya=({value:t,onChange:s,placeholder:r,p:a})=>e.jsxs("div",{className:"relative flex-1",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:a.mutedText}}),e.jsx("input",{value:t,onChange:e=>s(e.target.value),placeholder:r,style:{width:"100%",padding:"9px 14px 9px 36px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder})]}),fa=({value:t,onChange:s,options:r,p:a})=>e.jsx("select",{value:t,onChange:e=>s(e.target.value),style:{padding:"9px 12px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",cursor:"pointer",minWidth:120},children:r.map(t=>e.jsx("option",{value:t.value,style:{background:"#1e0a3c"},children:t.label},t.value))}),va=[10,25,50],ja=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(null),[d,u]=c.useState(null),[x,p]=c.useState(""),[g,b]=c.useState("all"),[y,f]=c.useState(1),[v,w]=c.useState(10),N=c.useCallback(async()=>{try{n(!0),i(null);const{data:e,error:t}=await h.from("newsletter_subscriptions").select("*").order("subscribed_at",{ascending:!1});if(t)throw t;a(e||[])}catch(e){i((null==e?void 0:e.message)||"Failed to load subscribers")}finally{n(!1)}},[]);c.useEffect(()=>{N()},[N]),c.useEffect(()=>{f(1)},[x,g]);const k=r.filter(e=>{const t=e.email.toLowerCase().includes(x.toLowerCase()),s="all"===g||("active"===g?e.is_active:!e.is_active);return t&&s}),_=Math.max(1,Math.ceil(k.length/v)),C=k.slice((y-1)*v,y*v),B=r.filter(e=>e.is_active).length,T=r.filter(e=>!e.is_active).length;return l?e.jsxs("div",{className:"min-h-screen flex items-center justify-center",style:{background:s.sectionBg},children:[e.jsx(ba,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading subscribers…"})]})]}):o?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-6",style:{background:s.sectionBg},children:[e.jsx(ba,{p:s}),e.jsxs("div",{className:"relative z-10 rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:s.redAccent}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"Failed to load"}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:o}),e.jsxs("button",{type:"button",onClick:N,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})]}):e.jsxs("div",{className:"min-h-screen transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(ba,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:s.headlineColor},children:"Newsletter Subscribers"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{const e=[["Email","Status","Subscribed Date"],...k.map(e=>[e.email,e.is_active?"Active":"Inactive",St(new Date(e.subscribed_at),"yyyy-MM-dd HH:mm:ss")])].map(e=>e.join(",")).join("\n"),t=new Blob([e],{type:"text/csv"}),s=window.URL.createObjectURL(t),r=document.createElement("a");r.href=s,r.download=`newsletter-subscribers-${St(new Date,"yyyy-MM-dd")}.csv`,r.click(),window.URL.revokeObjectURL(s)},className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export CSV"})]}),e.jsx("button",{type:"button",onClick:N,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:e.jsx(re,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:[{label:"Total",value:r.length,accent:s.purpleAccent,filter:"all"},{label:"Active",value:B,accent:s.greenAccent,filter:"active"},{label:"Inactive",value:T,accent:s.mutedText,filter:"inactive"}].map(({label:t,value:r,accent:a,filter:l})=>e.jsxs("button",{type:"button",onClick:()=>b(g===l?"all":l),className:"rounded-2xl p-5 text-left transition-all duration-200 hover:scale-[1.01]",style:{background:g===l?`${a}10`:s.statCardBg,border:`1.5px solid ${g===l?`${a}30`:s.statCardBorder}`,cursor:"pointer"},children:[e.jsx("p",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:a},children:r}),e.jsx("p",{className:"text-xs mt-1",style:{color:s.mutedText},children:t})]},t))}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx(ya,{value:x,onChange:p,placeholder:"Search by email…",p:s}),e.jsx(fa,{value:g,onChange:e=>b(e),p:s,options:[{value:"all",label:"All Status"},{value:"active",label:"Active"},{value:"inactive",label:"Inactive"}]})]}),e.jsxs("p",{className:"text-xs",style:{color:s.mutedText},children:["Showing ",C.length," of ",k.length," subscribers"]}
1),e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:500},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Email","Status","Subscribed Date","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:0===C.length?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"text-center py-12",style:{color:s.mutedText},children:"No subscribers found"})}):C.map((t,r)=>e.jsxs("tr",{style:{borderBottom:r<C.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4 font-medium",style:{color:s.bodyText},children:t.email}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{color:t.is_active?s.greenAccent:s.mutedText,background:t.is_active?"rgba(110,231,183,0.10)":"rgba(255,255,255,0.05)",border:"1px solid "+(t.is_active?"rgba(110,231,183,0.25)":"rgba(255,255,255,0.12)")},children:t.is_active?"Active":"Inactive"})}),e.jsx("td",{className:"py-3 px-4 text-sm",style:{color:s.mutedText},children:St(new Date(t.subscribed_at),"MMM dd, yyyy HH:mm")}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{u(e);try{const{error:s}=await h.from("newsletter_subscriptions").update({is_active:!t}).eq("id",e);if(s)throw s;a(s=>s.map(s=>s.id===e?{...s,is_active:!t}:s))}catch(s){}finally{u(null)}})(t.id,t.is_active),disabled:d===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all hover:opacity-80 disabled:opacity-50",style:{background:t.is_active?"rgba(248,113,113,0.10)":"rgba(110,231,183,0.10)",border:"1px solid "+(t.is_active?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)"),color:t.is_active?s.redAccent:s.greenAccent,cursor:d===t.id?"not-allowed":"pointer",fontFamily:"inherit"},children:d===t.id?e.jsx(K,{className:"h-3 w-3 animate-spin"}):t.is_active?e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"h-3 w-3"})," Deactivate"]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"h-3 w-3"})," Activate"]})})})]},t.id))})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:"Rows per page:"}),e.jsx(fa,{value:String(v),onChange:e=>{w(Number(e)),f(1)},p:s,options:va.map(e=>({value:String(e),label:String(e)}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:["Page ",y," of ",_]}),[{icon:ne,dir:-1,disabled:y<=1},{icon:oe,dir:1,disabled:y>=_}].map(({icon:t,dir:r,disabled:a})=>e.jsx("button",{type:"button",disabled:a,onClick:()=>f(e=>e+r),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:a?"not-allowed":"pointer"},children:e.jsx(t,{className:"h-4 w-4"})},r))]})]})]})]})},wa=[10,25,50],Na=({p:t})=>e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),ka=({value:t,onChange:s,placeholder:r,p:a})=>e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:a.mutedText}}),e.jsx("input",{value:t,onChange:e=>s(e.target.value),placeholder:r,style:{width:"100%",padding:"9px 14px 9px 36px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder})]}),_a=({value:t,onChange:s,options:r,p:a,minWidth:l=160})=>e.jsx("select",{value:t,onChange:e=>s(e.target.value),style:{padding:"9px 12px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",cursor:"pointer",minWidth:l,transition:"border-color 0.2s"},onFocus:e=>e.target.style.borderColor=a.inputFocusBorder,onBlur:e=>e.target.style.borderColor=a.inputBorder,children:r.map(t=>e.jsx("option",{value:t.value,style:{background:"#1e0a3c"},children:t.label},t.value))}),Ca=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(null),[d,u]=c.useState(null),[x,p]=c.useState(new Set),[g,b]=c.useState(""),[y,f]=c.useState("all"),[v,w]=c.useState("all"),[N,k]=c.useState(1),[_,C]=c.useState(10),B=c.useCallback(async()=>{n(!0),i(null);try{const[{data:e,error:t},{data:s},{data:r}]=await Promise.all([h.from("profiles").select("*").order("created_at",{ascending:!1}),h.from("interviews").select("user_id, completed_at").eq("status","completed"),h.from("orders").select("user_id, amount_inr").eq("status","paid")]);if(t)throw t;const l={},n={},o={};
1null==s||s.forEach(e=>{l[e.user_id]=(l[e.user_id]||0)+1,(!n[e.user_id]||e.completed_at>n[e.user_id])&&(n[e.user_id]=e.completed_at)}),null==r||r.forEach(e=>{o[e.user_id]=(o[e.user_id]||0)+Number(e.amount_inr)}),a((e||[]).map(e=>({...e,is_blocked:e.is_blocked??!1,total_interviews:l[e.user_id]||0,last_interview_date:n[e.user_id]||null,total_spent:o[e.user_id]||0})))}catch(e){i((null==e?void 0:e.message)||"Failed to load users")}finally{n(!1)}},[]);c.useEffect(()=>{B()},[B]),c.useEffect(()=>{k(1)},[g,y,v]);const T=(e,t="users-marketing")=>{const s=[["Name","Email","Phone","Experience","Designation","Company","Location","Credits","Status","Interviews","Last Active","Total Spent","Referral Code","LinkedIn","Joined"],...e.map(e=>[e.full_name,e.email,e.mobile_number,e.years_of_experience||"N/A",e.current_designation||"N/A",e.current_company||"N/A",`${e.city||""} ${e.country||""}`.trim(),e.credits,e.is_blocked?"Blocked":"Active",e.total_interviews||0,e.last_interview_date?St(new Date(e.last_interview_date),"yyyy-MM-dd"):"Never",e.total_spent||0,e.referral_code||"N/A",e.linkedin_profile||"N/A",St(new Date(e.created_at),"yyyy-MM-dd")])].map(e=>e.join(",")).join("\n"),r=new Blob([s],{type:"text/csv"}),a=URL.createObjectURL(r),l=document.createElement("a");l.href=a,l.download=`${t}-${St(new Date,"yyyy-MM-dd")}.csv`,l.click(),URL.revokeObjectURL(a)},S=r.filter(e=>{var t,s,r,a;const l=g.toLowerCase();return((null==(t=e.full_name)?void 0:t.toLowerCase().includes(l))||(null==(s=e.email)?void 0:s.toLowerCase().includes(l))||(null==(r=e.mobile_number)?void 0:r.includes(l))||(null==(a=e.referral_code)?void 0:a.toLowerCase().includes(l)))&&("all"===y||e.years_of_experience===y)&&("all"===v||e.country===v)}),$=Math.max(1,Math.ceil(S.length/_)),F=S.slice((N-1)*_,N*_),A=[...new Set(r.map(e=>e.years_of_experience).filter(Boolean))],R=[...new Set(r.map(e=>e.country).filter(Boolean))];return l?e.jsxs("div",{className:"min-h-screen flex items-center justify-center",style:{background:s.sectionBg},children:[e.jsx(Na,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading users…"})]})]}):o?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-6",style:{background:s.sectionBg},children:[e.jsx(Na,{p:s}),e.jsxs("div",{className:"relative z-10 rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:s.redAccent}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"Failed to load users"}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:o}),e.jsxs("button",{type:"button",onClick:B,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})]}):e.jsxs("div",{className:"min-h-screen transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(Na,{p:s}),e.jsxs("div",{className:"relative z-10 max-w-[1400px] mx-auto px-4 sm:px-6 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em] mb-1",style:{color:s.accentText},children:"Admin Console"}),e.jsx("h2",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:s.headlineColor},children:"All Users"}),e.jsxs("p",{className:"text-xs mt-0.5",style:{color:s.mutedText},children:[r.length.toLocaleString()," registered users"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[x.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>{const e=S.filter(e=>x.has(e.id));e.length&&(window.location.href=`mailto:?bcc=${e.map(e=>e.email).join(",")}`)},className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(ee,{className:"h-4 w-4"}),"Email (",x.size,")"]}),e.jsxs("button",{type:"button",onClick:()=>T(S.filter(e=>x.has(e.id)),"selected-users"),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"})," Export Selected"]})]}),e.jsxs("button",{type:"button",onClick:()=>T(S),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Export All"})]}),e.jsx("button",{type:"button",onClick:B,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:e.jsx(re,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(ka,{value:g,onChange:b,placeholder:"Search by name, email, phone, or referral code…",p:s}),e.jsx(_a,{value:y,onChange:f,p:s,options:[{value:"all",label:"All Experience"},...A.map(e=>({value:e,label:e}))]}
1),e.jsx(_a,{value:v,onChange:w,p:s,minWidth:140,options:[{value:"all",label:"All Countries"},...R.map(e=>({value:e,label:e}))]})]}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs",style:{color:s.mutedText},children:x.size>0?`${x.size} selected`:`Showing ${F.length} of ${S.length} users`})}),e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:1400},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:[e.jsx("th",{className:"py-3 px-4 w-10",children:e.jsx("input",{type:"checkbox",checked:x.size===F.length&&F.length>0,onChange:()=>{x.size===F.length?p(new Set):p(new Set(F.map(e=>e.id)))},style:{accentColor:"#8b5cf6",cursor:"pointer"}})}),["Name","Email","Phone","Experience","Interviews","Last Active","Spent","Credits","Referral","LinkedIn","Status","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))]})}),e.jsx("tbody",{children:0===F.length?e.jsx("tr",{children:e.jsx("td",{colSpan:13,className:"text-center py-12 text-sm",style:{color:s.mutedText},children:"No users found"})}):F.map((t,r)=>e.jsxs("tr",{style:{borderBottom:r<F.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsx("input",{type:"checkbox",checked:x.has(t.id),onChange:()=>{return e=t.id,void p(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s});var e},style:{accentColor:"#8b5cf6",cursor:"pointer"}})}),e.jsx("td",{className:"py-3 px-4 font-medium truncate max-w-[120px]",style:{color:s.bodyText},children:t.full_name}),e.jsx("td",{className:"py-3 px-4 text-xs truncate max-w-[150px]",style:{color:s.mutedText},children:t.email}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:s.mutedText},children:t.mobile_number}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:s.mutedText},children:t.years_of_experience||"N/A"}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{background:(t.total_interviews||0)>0?s.badgeBg:"rgba(255,255,255,0.05)",border:`1px solid ${(t.total_interviews||0)>0?s.badgeBorder:"rgba(255,255,255,0.10)"}`,color:(t.total_interviews||0)>0?s.accentText:s.mutedText},children:t.total_interviews||0})}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:s.mutedText},children:t.last_interview_date?St(new Date(t.last_interview_date),"MMM dd"):"Never"}),e.jsxs("td",{className:"py-3 px-4 text-sm font-semibold",style:{color:(t.total_spent||0)>0?s.greenAccent:s.mutedText},children:["₹",(t.total_spent||0).toLocaleString()]}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{background:t.credits>0?"rgba(110,231,183,0.10)":"rgba(255,255,255,0.05)",border:"1px solid "+(t.credits>0?"rgba(110,231,183,0.25)":"rgba(255,255,255,0.10)"),color:t.credits>0?s.greenAccent:s.mutedText},children:t.credits})}),e.jsx("td",{className:"py-3 px-4 font-mono text-xs",style:{color:s.mutedText},children:t.referral_code||"—"}),e.jsx("td",{className:"py-3 px-4",children:t.linkedin_profile?e.jsx("a",{href:t.linkedin_profile,target:"_blank",rel:"noopener noreferrer",className:"transition-opacity hover:opacity-70",style:{color:s.blueAccent},children:e.jsx(Oe,{className:"h-4 w-4"})}):e.jsx("span",{style:{color:s.mutedText},children:"—"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{color:t.is_blocked?s.redAccent:s.greenAccent,background:t.is_blocked?"rgba(248,113,113,0.10)":"rgba(110,231,183,0.10)",border:"1px solid "+(t.is_blocked?"rgba(248,113,113,0.25)":"rgba(110,231,183,0.25)")},children:t.is_blocked?"Blocked":"Active"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{u(e);try{const{data:s,error:r}=await h.functions.invoke("admin-block-user",{body:{target_user_id:e,block:!t}});if(r)throw r;if(!s.success)throw new Error(s.error);a(s=>s.map(s=>s.user_id===e?{...s,is_blocked:!t}:s))}catch(s){}finally{u(null)}})(t.user_id,t.is_blocked??!1),disabled:d===t.user_id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all hover:opacity-80 disabled:opacity-40",style:{background:t.is_blocked?"rgba(110,231,183,0.10)":"rgba(248,113,113,0.10)",border:"1px solid "+(t.is_blocked?"rgba(110,231,183,0.25)":"rgba(248,113,113,0.25)"),color:t.is_blocked?s.greenAccent:s.redAccent,cursor:d===t.user_id?"not-allowed":"pointer",fontFamily:"inherit",whiteSpace:"nowrap"},children:d===t.user_id?e.jsx(K,{className:"h-3 w-3 animate-spin"}):t.is_blocked?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-3 w-3"}),"Unblock"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-3 w-3"}),"Block"]})})})]},t.id))})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:"Rows per page:"}),e.jsx(_a,{value:String(_),onChange:e=>{C(Number(e)),k(1)},p:s,minWidth:80,options:wa.map(e=>({value:String(e),label:String(e)}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:["Page ",N," of ",$]}),[{icon:ne,dir:-1,disabled:N<=1},{icon:oe,dir:1,disabled:N>=$}].map(({icon:t,dir:r,disabled:a})=>e.jsx("button",{type:"button",disabled:a,onClick:()=>k(e=>e+r),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:a?"not-allowed":"pointer"},children:e.jsx(t,{className:"h-4 w-4"})},r))]})]})]})]})},Ba={title:"",slug:"",description:"",content:"",category:"Technical Interviews",read_time:5,keywords:"",author:"SmartMentor.ai Team",published:!1,publish_date:(new Date).toISOString().split("T")[0]},Ta=["Technical Interviews","Behavioral Interviews","Career Growth","Success Stories"],Sa=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),$a=({label:t,required:s,children:r})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-widest text-white/50",children:[t,s&&e.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),r]}),Fa=(e,t=!1)=>({background:e.inputBg,border:`1.5px solid ${t?e.inputFocusBorder:e.inputBorder}`,borderRadius:10,color:e.headlineColor,padding:"10px 14px",fontSize:14,fontFamily:"inherit",width:"100%",outline:"none",transition:"border-color 0.2s, box-shadow 0.2s",boxShadow:t?"0 0 0 3px rgba(139,92,246,0.14)":"none"}),Aa=({open:t,onClose:s,onSave:r,editingPost:a,saving:l,p:n})=>{const[o,i]=c.useState(Ba),[d,u]=c.useState(null),[x,p]=c.useState(null),[m,h]=c.useState(null);c.useEffect(()=>{a?(i({title:a.title,slug:a.slug,description:a.description,content:a.content,category:a.category,read_time:a.read_time,keywords:a.keywords.join(", "),author:a.author,published:a.published,publish_date:a.publish_date?new Date(a.publish_date).toISOString().split("T")[0]:(new Date).toISOString().split("T")[0]}),p(a.image_url),u(null)):(i(Ba),u(null),p(null))},[a,t]);const j=(e,t)=>i(s=>({...s,[e]:t}));return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center p-0 sm:p-4",role:"dialog","aria-modal":"true","aria-label":a?"Edit blog post":"Create blog post",children:[e.jsx("div",{className:"absolute inset-0 transition-opacity",style:{background:"rgba(0,0,0,0.70)",backdropFilter:"blur(4px)"},onClick:s,"aria-hidden":!0}),e.jsxs("div",{className:"relative z-10 w-full sm:max-w-3xl max-h-[95vh] sm:max-h-[88vh] flex flex-col rounded-t-3xl sm:rounded-3xl overflow-hidden",style:{background:n.sectionBg,border:`1px solid ${n.cardBorder}`,boxShadow:"0 24px 80px rgba(0,0,0,0.60)"},children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-5 sm:px-7 py-4 border-b",style:{background:n.tableHeaderBg??"rgba(21,0,43,0.97)",borderColor:n.divider},children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.18em]",style:{color:n.accentText},children:"Blog Manager"}),e.jsx("h2",{className:"text-lg font-bold",style:{color:n.headlineColor,fontFamily:"'Roboto Slab', serif"},children:a?"Edit Post":"Create New Post"})]}),e.jsx("button",{onClick:s,className:"p-2 rounded-xl transition-all hover:opacity-80",style:{background:n.tileBg??"rgba(255,255,255,0.06)",border:`1px solid ${n.cardBorder}`,color:n.mutedText,cursor:"pointer"},"aria-label":"Close editor",children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 sm:px-7 py-5 space-y-5",style:{scrollbarWidth:"thin",scrollbarColor:`${n.cardBorder} transparent`},children:[e.jsx($a,{label:"Title",required:!0,children:e.jsx("input",{value:o.title,onChange:e=>{j("title",e.target.value),a||j("slug",Sa(e.target.value))},onFocus:()=>h("title"),onBlur:()=>h(null),placeholder:"Enter blog post title",style:Fa(n,"title"===m)})}),e.jsx($a,{label:"Slug",children:e.jsx("input",{value:o.slug,onChange:e=>j("slug",e.target.value),onFocus:()=>h("slug"),onBlur:()=>h(null),placeholder:"auto-generated-from-title",style:Fa(n,"slug"===m)})}),e.jsx($a,{label:"Description",required:!0,children:e.jsx("textarea",{value:o.description,onChange:e=>j("description",e.target.value),onFocus:()=>h("desc"),onBlur:()=>h(null),placeholder:"Brief description for SEO and post preview",rows:3,style:{...Fa(n,"desc"===m),resize:"vertical"}})}),e.jsx($a,{label:"Content (HTML supported)",required:!0,children:e.jsx("textarea",{value:o.content,onChange:e=>j("content",e.target.value),onFocus:()=>h("content"),onBlur:()=>h(null),placeholder:"Write your blog content here (HTML tags are supported)",rows:10,style:{...Fa(n,"content"===m),resize:"vertical",fontFamily:"monospace"}})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx($a,{label:"Category",children:e.jsxs(g,{value:o.category,onValueChange:e=>j("category",e),children:[e.jsx(b,{style:{background:n.inputBg,border:`1.5px solid ${n.inputBorder}`,borderRadius:10,color:n.headlineColor,height:42},children:e.jsx(y,{})}),e.jsx(f,{style:{background:n.sectionBg,border:`1px solid ${n.cardBorder}`},children:Ta.map(t=>e.jsx(v,{value:t,style:{color:n.bodyText},children:t},t))})]})}),e.jsx($a,{label:"Read Time (minutes)",children:e.jsx("input",{type:"number",min:1,max:60,value:o.read_time,onChange:e=>j("read_time",parseInt(e.target.value)||5),onFocus:()=>h("rt"),onBlur:()=>h(null),style:Fa(n,"rt"===m)})})]}),e.jsx($a,{label:"Publish Date",children:e.jsx("input",{type:"date",value:o.publish_date,onChange:e=>j("publish_date",e.target.value),onFocus:()=>h("date"),onBlur:()=>h(null),style:{...Fa(n,"date"===m),colorScheme:"dark"}})}),e.jsx($a,{label:"Keywords (comma-separated)",children:e.jsx("input",{value:o.keywords,onChange:e=>j("keywords",e.target.value),onFocus:()=>
1h("kw"),onBlur:()=>h(null),placeholder:"interview, career, tips",style:Fa(n,"kw"===m)})}),e.jsx($a,{label:"Author",children:e.jsx("input",{value:o.author,onChange:e=>j("author",e.target.value),onFocus:()=>h("author"),onBlur:()=>h(null),style:Fa(n,"author"===m)})}),e.jsxs($a,{label:"Header Image (max 2MB)",children:[e.jsx("input",{type:"file",accept:"image/*",onChange:e=>{var t;const s=null==(t=e.target.files)?void 0:t[0];s&&(s.size>2097152?w.error("Image must be less than 2MB"):(u(s),p(URL.createObjectURL(s))))},className:"w-full text-sm",style:{color:n.bodyText}}),x&&e.jsxs("div",{className:"mt-3 relative inline-block",children:[e.jsx("img",{src:x,alt:"Preview",className:"max-h-40 rounded-xl object-cover",style:{border:`1px solid ${n.cardBorder}`}}),e.jsx("button",{type:"button",onClick:()=>{p(null),u(null)},className:"absolute -top-2 -right-2 w-5 h-5 rounded-full flex items-center justify-center",style:{background:"#ef4444",border:"none",cursor:"pointer"},"aria-label":"Remove image",children:e.jsx(ye,{className:"h-3 w-3 text-white"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx(Ft,{id:"published",checked:o.published,onCheckedChange:e=>j("published",e)}),e.jsx(N,{htmlFor:"published",className:"text-sm font-medium cursor-pointer",style:{color:o.published?n.accentText:n.bodyText},children:o.published?"Published — visible to readers":"Draft — not visible"})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-end gap-3 px-5 sm:px-7 py-4 border-t",style:{background:n.tableHeaderBg??"rgba(21,0,43,0.97)",borderColor:n.divider},children:[e.jsx("button",{type:"button",onClick:s,className:"px-5 py-2.5 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:"transparent",border:`1px solid ${n.cardBorder}`,color:n.mutedText,cursor:"pointer",fontFamily:"inherit"},children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>r(o,d),disabled:l,className:"flex items-center gap-2 px-6 py-2.5 rounded-xl text-sm font-bold transition-all hover:opacity-90 active:scale-[0.97]",style:{background:l?"rgba(255,255,255,0.08)":n.btnPrimaryBg,color:l?"rgba(255,255,255,0.35)":"#fff",border:"none",cursor:l?"not-allowed":"pointer",fontFamily:"'Roboto Slab', serif",boxShadow:l?"none":"0 4px 16px rgba(124,58,237,0.30)"},children:[l&&e.jsx(K,{className:"h-4 w-4 animate-spin"}),a?"Update Post":"Create Post"]})]})]})]}):null},Ra=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(null),[x,p]=c.useState(!1),[N,k]=c.useState(""),[_,C]=c.useState("all");c.useEffect(()=>{B()},[]);const B=async()=>{try{const{data:e,error:t}=await h.from("blog_posts").select("*").order("publish_date",{ascending:!1});if(t)throw t;a(e||[])}catch(e){w.error("Failed to load blog posts")}finally{n(!1)}},T=r.filter(e=>{const t=!N||e.title.toLowerCase().includes(N.toLowerCase())||e.description.toLowerCase().includes(N.toLowerCase())||e.category.toLowerCase().includes(N.toLowerCase()),s="all"===_||"published"===_&&e.published||"draft"===_&&!e.published;return t&&s});return l?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-4",children:[e.jsx(K,{className:"h-8 w-8 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading posts…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:s.mutedText}}),e.jsx("input",{value:N,onChange:e=>k(e.target.value),placeholder:"Search posts…",style:{background:s.inputBg,border:`1.5px solid ${s.inputBorder}`,borderRadius:10,color:s.headlineColor,padding:"9px 14px 9px 38px",fontSize:14,fontFamily:"inherit",width:"100%",outline:"none"}})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 flex-shrink-0",style:{color:s.mutedText}}),e.jsxs(g,{value:_,onValueChange:e=>C(e),children:[e.jsx(b,{className:"w-[140px]",style:{background:s.inputBg,border:`1.5px solid ${s.inputBorder}`,borderRadius:10,color:s.headlineColor,height:40},children:e.jsx(y,{})}),e.jsxs(f,{style:{background:s.sectionBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(v,{value:"all",style:{color:s.bodyText},children:"All Posts"}),e.jsx(v,{value:"published",style:{color:s.bodyText},children:"Published"}),e.jsx(v,{value:"draft",style:{color:s.bodyText},children:"Drafts"})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{u(null),p(!0)},className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all hover:opacity-90 active:scale-[0.97] whitespace-nowrap",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"'Roboto Slab', serif",boxShadow:"0 4px 16px rgba(124,58,237,0.28)"},children:[e.jsx(xe,{className:"h-4 w-4"}),"New Post"]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",style:{color:s.mutedText},children:[e.jsxs("span",{children:[r.length," total"]}),e.jsx("span",{style:{color:s.divider},children:"·"}),e.jsxs("span",{style:{color:s.successText??"#6ee7b7"},children:[r.filter(e=>e.published).length," published"]}),e.jsx("span",{style:{color:s.divider},children:"·"}),e.jsxs("span",{children:[r.filter(e=>!e.published).length," drafts"]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:s.divider},children:"·"}),e.jsxs("span",{style:{color:s.accentText},children:[T.length," results"]})]})]}),0===T.length?e.jsxs("div",{className:"rounded-2xl flex flex-col items-center justify-center py-16 gap-4 text-center",style:{background:s.
1cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx("div",{className:"h-14 w-14 rounded-2xl flex items-center justify-center",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`},children:e.jsx(Q,{className:"h-6 w-6",style:{color:s.mutedText}})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:N?"No matching posts":"No blog posts yet"}),e.jsx("p",{className:"text-sm mt-1",style:{color:s.mutedText},children:N?"Try a different search term":"Click 'New Post' to create your first article"})]})]}):e.jsx("div",{className:"space-y-3",children:T.map(t=>e.jsx("div",{className:"rounded-2xl transition-all duration-200 hover:scale-[1.003]",style:{background:s.cardBg,border:`1px solid ${t.published?s.cardBorder:`${s.cardBorder}`}`,opacity:t.published?1:.8},children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4 px-5 py-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:t.published?s.greenAccent??"#6ee7b7":s.mutedText},"aria-label":t.published?"Published":"Draft"}),e.jsx("h3",{className:"font-semibold text-sm truncate",style:{color:s.headlineColor,fontFamily:"'Roboto Slab', serif"},title:t.title,children:t.title})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",style:{color:s.mutedText},children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold",style:{background:s.badgeBg,color:s.badgeText??s.accentText,border:`1px solid ${s.badgeBorder}`},children:t.category}),e.jsxs("span",{children:[t.read_time," min read"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),t.publish_date?new Date(t.publish_date).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}):"No date"]})]}),e.jsx("p",{className:"text-xs mt-1.5 line-clamp-1",style:{color:s.mutedText},children:t.description})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>(async e=>{try{const{error:t}=await h.from("blog_posts").update({published:!e.published}).eq("id",e.id);if(t)throw t;w.success("Post "+(e.published?"unpublished":"published")),B()}catch{w.error("Failed to update status")}})(t),title:t.published?"Unpublish":"Publish",className:"p-2 rounded-xl transition-all hover:opacity-80 active:scale-[0.95]",style:{background:t.published?"rgba(110,231,183,0.12)":s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${t.published?"rgba(110,231,183,0.30)":s.cardBorder}`,cursor:"pointer"},"aria-label":t.published?"Unpublish post":"Publish post",children:t.published?e.jsx(Me,{className:"h-4 w-4",style:{color:s.greenAccent??"#6ee7b7"}}):e.jsx(He,{className:"h-4 w-4",style:{color:s.mutedText}})}),e.jsx("button",{type:"button",onClick:()=>(e=>{u(e),p(!0)})(t),title:"Edit post",className:"p-2 rounded-xl transition-all hover:opacity-80 active:scale-[0.95]",style:{background:s.tileBg??"rgba(255,255,255,0.05)",border:`1px solid ${s.cardBorder}`,cursor:"pointer"},"aria-label":"Edit post",children:e.jsx(qe,{className:"h-4 w-4",style:{color:s.accentText}})}),e.jsx("button",{type:"button",onClick:()=>(async e=>{if(window.confirm("Delete this blog post? This cannot be undone."))try{const{error:t}=await h.from("blog_posts").delete().eq("id",e);if(t)throw t;w.success("Blog post deleted"),B()}catch(t){w.error("Failed to delete blog post")}})(t.id),title:"Delete post",className:"p-2 rounded-xl transition-all hover:opacity-80 active:scale-[0.95]",style:{background:"rgba(239,68,68,0.10)",border:"1px solid rgba(239,68,68,0.25)",cursor:"pointer"},"aria-label":"Delete post",children:e.jsx(ge,{className:"h-4 w-4",style:{color:"#f87171"}})})]})]})},t.id))})]}),e.jsx(Aa,{open:x,onClose:()=>{p(!1),u(null)},onSave:async(e,t)=>{if(e.title&&e.description&&e.content){i(!0);try{let s=(null==d?void 0:d.image_url)||null;t&&(s=await(async e=>{const t=e.name.split(".").pop(),s=`${Date.now()}-${Math.random().toString(36).substring(7)}.${t}`,{error:r}=await h.storage.from("blog-images").upload(s,e,{cacheControl:"3600",upsert:!1});if(r)throw r;const{data:a}=h.storage.from("blog-images").getPublicUrl(s);return a.publicUrl})(t));const r=e.slug||Sa(e.title),a=e.keywords.split(",").map(e=>e.trim()).filter(e=>e.length>0),l=new Date(e.publish_date+"T00:00:00Z").toISOString(),n={title:e.title,slug:r,description:e.description,content:e.content,category:e.category,read_time:e.read_time,keywords:a,author:e.author,image_url:s,published:e.published,publish_date:l,updated_at:(new Date).toISOString()};if(d){const{error:e}=await h.from("blog_posts").update(n).eq("id",d.id);if(e)throw e;w.success("Blog post updated")}else{const{error:e}=await h.from("blog_posts").insert([n]);if(e)throw e;w.success("Blog post created")}B(),p(!1),u(null)}catch(s){w.error(s.message||"Failed to save blog post")}finally{i(!1)}}else w.error("Please fill in all required fields")},editingPost:d,saving:o,p:s})]})},Ea=({id:t,type:s="text",value:r,onChange:a,onKeyDown:l,placeholder:n,p:o,disabled:i})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),onKeyDown:l,placeholder:n,disabled:i,style:{width:"100%",padding:"10px 14px",borderRadius:10,border:`1.5px solid ${o.inputBorder}`,background:i?"rgba(255,255,255,0.03)":o.inputBg,color:o.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)",transition:"border-color 0.2s, opacity 0.2s",o
1pacity:i?.5:1},onFocus:e=>!i&&(e.target.style.borderColor=o.inputFocusBorder),onBlur:e=>e.target.style.borderColor=o.inputBorder}),La=({children:t,p:s,style:r})=>e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`,...r},children:t}),Da=({icon:t,title:s,description:r,p:a,danger:l})=>e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${a.divider}`,background:l?"rgba(248,113,113,0.06)":a.tableHeaderBg},children:[t&&e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:l?"rgba(248,113,113,0.15)":a.badgeBg,border:`1px solid ${l?"rgba(248,113,113,0.30)":a.badgeBorder}`},children:e.jsx(t,{className:"h-4 w-4",style:{color:l?a.redAccent:a.accentText}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:l?a.redAccent:a.tableHeaderText},children:s}),r&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:a.mutedText},children:r})]})]}),Ma=({icon:t,label:s,value:r,mono:a,p:l})=>e.jsxs("div",{className:"flex items-center gap-3 py-2.5",style:{borderBottom:`1px solid ${l.divider}`},children:[e.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0",style:{width:28,height:28,background:l.badgeBg,border:`1px solid ${l.badgeBorder}`},children:e.jsx(t,{className:"h-3.5 w-3.5",style:{color:l.accentText}})}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wide flex-shrink-0",style:{color:l.labelText,width:100},children:s}),e.jsx("span",{className:"text-sm flex-1 truncate "+(a?"font-mono text-xs":"font-medium"),style:{color:l.bodyText},children:r})]}),Ia=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState(""),[l,n]=c.useState(null),[o,i]=c.useState(!1),[d,u]=c.useState(!1),[x,p]=c.useState(""),[g,b]=c.useState(!1),y=async()=>{const e=r.trim().toLowerCase();if(e){i(!0),n(null),p("");try{const{data:t,error:s}=await h.from("profiles").select("id, user_id, email, full_name, credits, created_at").eq("email",e).maybeSingle();if(s)throw s;if(!t)return void w.error("No user found with this email");const[r,a]=await Promise.all([h.from("interviews").select("id",{count:"exact",head:!0}).eq("user_id",t.user_id),h.from("orders").select("id",{count:"exact",head:!0}).eq("user_id",t.user_id)]);n({...t,interviews_count:r.count??0,orders_count:a.count??0}),w.success("User found")}catch(t){w.error((null==t?void 0:t.message)||"Failed to search for user")}finally{i(!1)}}else w.error("Please enter an email address")},f=!!l&&x.toLowerCase()===l.email.toLowerCase()&&!d;return e.jsxs("div",{className:"w-full space-y-6 px-4 sm:px-6 lg:px-8 py-6",style:{fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs(La,{p:s,children:[e.jsx(Da,{icon:ae,title:"User Deletion",description:"Permanently delete a user account and all associated data. This action cannot be undone.",p:s,danger:!0}),e.jsxs("div",{className:"p-6",children:[e.jsx("label",{htmlFor:"search-email",className:"text-xs font-bold uppercase tracking-wide block mb-2",style:{color:s.labelText},children:"User Email Address"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx("div",{className:"flex-1",children:e.jsx(Ea,{id:"search-email",type:"email",value:r,onChange:a,onKeyDown:e=>"Enter"===e.key&&!o&&y(),placeholder:"[email protected]",p:s,disabled:d})}),e.jsxs("button",{type:"button",onClick:y,disabled:o||d,className:"flex items-center justify-center gap-2 px-5 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-50 flex-shrink-0",style:{height:42,background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:o||d?"not-allowed":"pointer",fontFamily:"inherit",minWidth:120},children:[o?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(G,{className:"h-4 w-4"}),"Search"]})]})]})]}),l&&e.jsxs(La,{p:s,style:{border:"1px solid rgba(248,113,113,0.25)"},children:[e.jsx(Da,{icon:_e,title:"User Found",description:"Review all data before proceeding with deletion",p:s}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{border:`1px solid ${s.tableBorder}`},children:[e.jsx(Ma,{icon:_e,label:"Name",value:l.full_name||"—",p:s}),e.jsx(Ma,{icon:ee,label:"Email",value:l.email,p:s}),e.jsx(Ma,{icon:We,label:"Credits",value:e.jsx("span",{style:{color:s.accentText,fontWeight:700},children:l.credits}),p:s}),e.jsx(Ma,{icon:Q,label:"Interviews",value:l.interviews_count??0,p:s}),e.jsx(Ma,{icon:Q,label:"Orders",value:l.orders_count??0,p:s}),e.jsx(Ma,{icon:_e,label:"Profile ID",value:l.id,mono:!0,p:s}),e.jsx(Ma,{icon:_e,label:"User ID",value:l.user_id,mono:!0,p:s}),e.jsxs("div",{className:"flex items-center gap-3 py-2.5",children:[e.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0",style:{width:28,height:28,background:s.badgeBg,border:`1px solid ${s.badgeBorder}`}
1,children:e.jsx(Q,{className:"h-3.5 w-3.5",style:{color:s.accentText}})}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wide flex-shrink-0",style:{color:s.labelText,width:100},children:"Member Since"}),e.jsx("span",{className:"text-sm font-medium",style:{color:s.bodyText},children:new Date(l.created_at).toLocaleDateString()})]})]}),e.jsxs("div",{className:"rounded-xl p-4 space-y-2",style:{background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.22)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4 flex-shrink-0",style:{color:s.redAccent}}),e.jsx("p",{className:"text-sm font-semibold",style:{color:s.redAccent},children:"This will permanently delete:"})]}),e.jsxs("ul",{className:"ml-6 space-y-1 text-sm",style:{color:s.mutedText,listStyle:"disc"},children:[e.jsx("li",{children:"Authentication account (auth.users)"}),e.jsx("li",{children:"Profile & all personal data"}),e.jsxs("li",{children:[l.interviews_count," interview(s) and transcripts"]}),e.jsxs("li",{children:[l.orders_count," order(s) and transaction history"]}),e.jsx("li",{children:"All referral records and credits"}),e.jsx("li",{children:"Any admin roles assigned to this user"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:"confirm-email",className:"text-xs font-bold uppercase tracking-wide block",style:{color:s.redAccent},children:['Type "',l.email,'" to confirm deletion']}),e.jsx(Ea,{id:"confirm-email",type:"email",value:x,onChange:p,onKeyDown:e=>"Enter"===e.key&&f&&b(!0),placeholder:"Type email to confirm...",p:s})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>{n(null),a(""),p("")},className:"flex-1 flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl font-semibold text-sm transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(ye,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(At,{open:g,onOpenChange:b,children:[e.jsx(Rt,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:!f,className:"flex-1 flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl font-semibold text-sm transition-all hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",style:{background:f?"linear-gradient(135deg, #dc2626, #b91c1c)":"rgba(248,113,113,0.15)",border:"1px solid "+(f?"rgba(220,38,38,0.5)":"rgba(248,113,113,0.25)"),color:"#fff",cursor:f?"pointer":"not-allowed",fontFamily:"inherit"},children:[d?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(ge,{className:"h-4 w-4"}),"Delete Permanently"]})}),e.jsxs(Et,{style:{background:s.cardBg,border:"1px solid rgba(248,113,113,0.30)",borderRadius:16,fontFamily:"inherit"},children:[e.jsxs(Lt,{children:[e.jsxs(Dt,{className:"flex items-center gap-2",style:{color:s.redAccent,fontFamily:"'Roboto Slab', serif"},children:[e.jsx(Fe,{className:"h-5 w-5"})," Final Confirmation"]}),e.jsxs(Mt,{style:{color:s.mutedText},children:["You are about to permanently delete"," ",e.jsx("strong",{style:{color:s.bodyText},children:null==l?void 0:l.email}),".",e.jsx("br",{}),e.jsx("br",{}),"All data from auth, profiles, interviews, orders, referrals, and roles will be deleted."," ",e.jsx("strong",{style:{color:s.redAccent},children:"This cannot be undone."})]})]}),e.jsxs(It,{children:[e.jsx(Pt,{style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,borderRadius:10},children:"Cancel"}),e.jsx(Ut,{onClick:async()=>{if(l)if(x.toLowerCase()===l.email.toLowerCase()){u(!0),b(!1);try{const{data:e,error:t}=await h.functions.invoke("admin-delete-user",{body:{target_id:l.id,target_user_id:l.user_id,target_email:l.email}});if(t)throw t;if(!(null==e?void 0:e.success))throw new Error((null==e?void 0:e.error)||"Deletion failed");w.success(`${l.email} permanently deleted`),n(null),a(""),p("")}catch(e){w.error((null==e?void 0:e.message)||"Failed to delete user")}finally{u(!1)}}else w.error("Email confirmation does not match")},style:{background:"linear-gradient(135deg, #dc2626, #b91c1c)",color:"#fff",border:"none",borderRadius:10},children:"Yes, Delete Permanently"})]})]})]})]})]})]})]})},Pa=({score:t,p:s})=>{const r=t>=9,a=t>=7&&t<=8;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-bold",style:{background:r?s.badgePaidBg:a?s.badgeWarnBg:s.errorBg,border:`1px solid ${r?s.badgePaidBorder:a?s.badgeWarnBorder:s.errorBorder}`,color:r?s.badgePaidText:a?s.badgeWarnText:s.errorText},children:[r?e.jsx(Ve,{className:"w-2.5 h-2.5"}):a?e.jsx(me,{className:"w-2.5 h-2.5"}):e.jsx(Ge,{className:"w-2.5 h-2.5"}),r?"Promoter":a?"Passive":"Detractor"," (",t,")"]})},Ua=()=>{const t=ua(),[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState(1),[i,d]=c.useState({totalResponses:0,avgNPS:0,promoters:0,passives:0,detractors:0,npsScore:0}
1),[u,x]=c.useState([]),[p,m]=c.useState([]),[g,b]=c.useState([]);c.useEffect(()=>{y()},[]);const y=async()=>{try{l(!0);const{data:e,error:t}=await h.from("user_feedback").select("*").order("created_at",{ascending:!1});if(t)throw t;const s=[...new Set((null==e?void 0:e.map(e=>e.user_id))||[])],{data:a}=await h.from("profiles").select("user_id, full_name, email").in("user_id",s),n=new Map((null==a?void 0:a.map(e=>[e.user_id,e]))||[]),o=(null==e?void 0:e.map(e=>{var t,s;return{...e,user_name:(null==(t=n.get(e.user_id))?void 0:t.full_name)||"Unknown",user_email:(null==(s=n.get(e.user_id))?void 0:s.email)||"N/A"}}))||[];r(o);const i=o.map(e=>e.nps_score).filter(e=>null!==e),c=i.length>0?Math.round(i.reduce((e,t)=>e+t,0)/i.length*10)/10:0,u=i.filter(e=>e>=9).length,p=i.filter(e=>e>=7&&e<=8).length,g=i.filter(e=>e<=6).length,y=i.length>0?Math.round((u-g)/i.length*100):0;d({totalResponses:o.length,avgNPS:c,promoters:u,passives:p,detractors:g,npsScore:y});const f=o.length||1,v={};o.forEach(e=>(e.valuable_features||[]).forEach(e=>{v[e]=(v[e]||0)+1})),x(Object.entries(v).map(([e,t])=>({feature:e,count:t,percentage:Math.round(t/f*100)})).sort((e,t)=>t.count-e.count));const j={};o.forEach(e=>{j[e.overall_satisfaction]=(j[e.overall_satisfaction]||0)+1}),m(Object.entries(j).map(([e,t])=>({rating:e,count:t,percentage:Math.round(t/f*100)})).sort((e,t)=>t.count-e.count));const w={};o.forEach(e=>{w[e.ease_of_use]=(w[e.ease_of_use]||0)+1}),b(Object.entries(w).map(([e,t])=>({rating:e,count:t,percentage:Math.round(t/f*100)})).sort((e,t)=>t.count-e.count))}catch(e){w.error("Failed to load feedback data")}finally{l(!1)}};if(a)return e.jsx(ca,{p:t});const f=Math.ceil(s.length/10),v=s.slice(10*(n-1),10*n),j=i.npsScore>=0?t.successText:t.errorText;return e.jsxs("div",{className:"space-y-6",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsx("h2",{className:"text-xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:"User Feedback Analytics"}),e.jsx(da,{onClick:y,loading:a,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(na,{label:"Total Responses",value:i.totalResponses,accent:!0,p:t}),e.jsx(na,{label:"Avg NPS",value:i.avgNPS,p:t}),e.jsx(na,{label:"NPS Score",value:e.jsxs("span",{style:{color:j},children:[i.npsScore>0?"+":"",i.npsScore]}),p:t}),e.jsx(na,{label:"Promoters",value:e.jsx("span",{style:{color:t.successText},children:i.promoters}),p:t}),e.jsx(na,{label:"Passives",value:e.jsx("span",{style:{color:t.warnText},children:i.passives}),p:t}),e.jsx(na,{label:"Detractors",value:e.jsx("span",{style:{color:t.errorText},children:i.detractors}),p:t})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[e.jsx(oa,{title:"Most Valuable Features",desc:"Features users find most helpful",p:t,children:0===u.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):e.jsx("div",{className:"space-y-3",children:u.slice(0,6).map((s,r)=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"truncate max-w-[180px]",style:{color:t.bodyText},children:s.feature}),e.jsxs("span",{className:"font-semibold flex-shrink-0",style:{color:t.headlineColor},children:[s.count," (",s.percentage,"%)"]})]}),e.jsx(ia,{value:s.percentage,p:t})]},r))})}),e.jsx(oa,{title:"Overall Satisfaction",desc:"User satisfaction ratings distribution",p:t,children:0===p.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):e.jsx("div",{className:"space-y-3",children:p.map((s,r)=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{style:{color:t.bodyText},children:s.rating}),e.jsxs("span",{className:"font-semibold",style:{color:t.headlineColor},children:[s.count," (",s.percentage,"%)"]})]}),e.jsx(ia,{value:s.percentage,p:t})]},r))})})]}),e.jsx(oa,{title:"Ease of Use Ratings",desc:"How easy users find the platform to navigate",p:t,children:0===g.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:g.map((s,r)=>e.jsxs("div",{className:"text-center p-4 rounded-xl",style:{background:t.accentBg,border:`1px solid ${t.accentBorder}`},children:[e.jsx("div",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:s.count}),e.jsx("p",{className:"text-xs mt-1",style:{color:t.bodyText},children:s.rating}),e.jsxs("p",{className:"text-[10px]",style:{color:t.mutedText},children:[s.percentage,"%"]})]},r))})}),e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-xs",style:{color:t.mutedText},children:["Showing ",v.length," of ",s.length," responses"]}),e.jsxs("button",{onClick:()=>
1{const e=[["User","Email","NPS Score","Satisfaction","Ease of Use","Accuracy","Continue Likelihood","Additional Feedback","Date"],...s.map(e=>[e.user_name,e.user_email,e.nps_score,e.overall_satisfaction,e.ease_of_use,e.question_accuracy,e.continue_likelihood,e.additional_feedback||"N/A",St(new Date(e.created_at),"yyyy-MM-dd HH:mm")])].map(e=>e.map(e=>`"${e}"`).join(",")).join("\n"),t=new Blob([e],{type:"text/csv"}),r=window.URL.createObjectURL(t),a=document.createElement("a");a.href=r,a.download=`user-feedback-${St(new Date,"yyyy-MM-dd")}.csv`,a.click(),window.URL.revokeObjectURL(r),w.success("Feedback exported successfully")},className:"flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs font-semibold transition-all hover:scale-[1.03]",style:{background:t.accentBg,border:`1px solid ${t.accentBorder}`,color:t.accentText},children:[e.jsx(se,{className:"w-3.5 h-3.5"})," Export CSV"]})]}),e.jsx("div",{className:"rounded-xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[700px] text-sm",style:{borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"rgba(139,92,246,0.12)",borderBottom:`1px solid ${t.divider}`},children:["User","NPS","Satisfaction","Ease of Use","Continue?","Additional Feedback","Date"].map(s=>e.jsx("th",{className:"px-4 py-3 text-left text-[10px] font-bold uppercase tracking-[0.10em]",style:{color:t.mutedText},children:s},s))})}),e.jsx("tbody",{children:0===v.length?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-10 text-center text-sm",style:{color:t.mutedText},children:"No feedback received yet"})}):v.map((s,r)=>e.jsxs("tr",{style:{background:r%2==0?"transparent":t.cardBg,borderBottom:`1px solid ${t.divider}`},onMouseEnter:e=>e.currentTarget.style.background=t.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background=r%2==0?"transparent":t.cardBg,children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-medium truncate max-w-[110px]",style:{color:t.headlineColor},children:s.user_name}),e.jsx("div",{className:"text-[10px] truncate max-w-[110px]",style:{color:t.mutedText},children:s.user_email})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(Pa,{score:s.nps_score,p:t})}),e.jsx("td",{className:"px-4 py-3 text-xs",style:{color:t.bodyText},children:s.overall_satisfaction}),e.jsx("td",{className:"px-4 py-3 text-xs",style:{color:t.bodyText},children:s.ease_of_use}),e.jsx("td",{className:"px-4 py-3 text-xs",style:{color:t.bodyText},children:s.continue_likelihood}),e.jsx("td",{className:"px-4 py-3 max-w-[180px]",children:e.jsx("p",{className:"text-xs truncate",style:{color:t.mutedText},title:s.additional_feedback||"",children:s.additional_feedback||"—"})}),e.jsx("td",{className:"px-4 py-3 text-xs whitespace-nowrap",style:{color:t.mutedText},children:St(new Date(s.created_at),"MMM dd, yyyy")})]},s.id))})]})})}),f>1&&e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("p",{className:"text-xs",style:{color:t.mutedText},children:["Page ",n," of ",f]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>o(e=>Math.max(1,e-1)),disabled:1===n,className:"px-3 py-1.5 rounded-lg text-xs font-medium disabled:opacity-40",style:{background:"rgba(255,255,255,0.06)",border:`1px solid ${t.cardBorder}`,color:t.bodyText},children:"← Prev"}),e.jsx("button",{onClick:()=>o(e=>Math.min(f,e+1)),disabled:n===f,className:"px-3 py-1.5 rounded-lg text-xs font-medium disabled:opacity-40",style:{background:"rgba(255,255,255,0.06)",border:`1px solid ${t.cardBorder}`,color:t.bodyText},children:"Next →"})]})]})]})},Oa={pending:{label:"New",textColor:"#fbbf24",bgOpacity:"rgba(251,191,36,0.10)",borderOpacity:"rgba(251,191,36,0.25)"},in_progress:{label:"To Respond",textColor:"#60a5fa",bgOpacity:"rgba(96,165,250,0.10)",borderOpacity:"rgba(96,165,250,0.25)"},responded:{label:"Responded",textColor:"#6ee7b7",bgOpacity:"rgba(110,231,183,0.10)",borderOpacity:"rgba(110,231,183,0.25)"}},za=({status:t})=>{const s=Oa[t]??{label:t,textColor:"rgba(255,255,255,0.5)",bgOpacity:"rgba(255,255,255,0.07)",borderOpacity:"rgba(255,255,255,0.12)"};return e.jsx("span",{className:"text-xs font-semibold px-2.5 py-0.5 rounded-full",style:{color:s.textColor,background:s.bgOpacity,border:`1px solid ${s.borderOpacity}`},children:s.label})},Ha=({p:t})=>
1e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${t.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${t.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),qa=({value:t,onChange:s,placeholder:r,icon:a,p:l})=>e.jsxs("div",{className:"relative flex-1",children:[e.jsx(a,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 pointer-events-none",style:{color:l.mutedText}}),e.jsx("input",{value:t,onChange:e=>s(e.target.value),placeholder:r,style:{width:"100%",padding:"9px 14px 9px 36px",borderRadius:10,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:l.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",backdropFilter:"blur(6px)"},onFocus:e=>e.target.style.borderColor=l.inputFocusBorder,onBlur:e=>e.target.style.borderColor=l.inputBorder})]}),Wa=({value:t,onChange:s,options:r,p:a})=>e.jsx("select",{value:t,onChange:e=>s(e.target.value),style:{padding:"9px 12px",borderRadius:10,border:`1.5px solid ${a.inputBorder}`,background:a.inputBg,color:a.headlineColor,fontSize:14,fontFamily:"inherit",outline:"none",cursor:"pointer",minWidth:140},children:r.map(t=>e.jsx("option",{value:t.value,style:{background:"#1e0a3c"},children:t.label},t.value))}),Va=({icon:t,onClick:s,title:r,disabled:a,variant:l="default",p:n})=>e.jsx("button",{type:"button",onClick:s,disabled:a,title:r,"aria-label":r,style:{width:36,height:36,borderRadius:9,border:`1.5px solid ${n.stepLockedBorder}`,background:"success"===l?"rgba(110,231,183,0.12)":n.stepLockedBg,color:"success"===l?n.greenAccent:n.bodyText,cursor:a?"not-allowed":"pointer",opacity:a?.5:1,display:"flex",alignItems:"center",justifyContent:"center",transition:"opacity 0.2s",flexShrink:0},children:e.jsx(t,{className:"h-3.5 w-3.5 "+("spin"===l?"animate-spin":"")})}),Ga=[10,25,50],Ka=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(null),[d,u]=c.useState(null),[x,p]=c.useState(""),[g,b]=c.useState("all"),[y,f]=c.useState("all"),[v,w]=c.useState(1),[N,k]=c.useState(10),_=c.useCallback(async()=>{try{n(!0),i(null);const{data:e,error:t}=await h.from("contact_submissions").select("*").order("created_at",{ascending:!1});if(t)throw t;a(e||[])}catch(e){i((null==e?void 0:e.message)||"Failed to load contact submissions")}finally{n(!1)}},[]);c.useEffect(()=>{_()},[_]),c.useEffect(()=>{w(1)},[x,g,y]);const C=async(e,t)=>{u(e);try{const{error:s}=await h.from("contact_submissions").update({status:t,updated_at:(new Date).toISOString()}).eq("id",e);if(s)throw s;a(s=>s.map(s=>s.id===e?{...s,status:t}:s))}catch(s){}finally{u(null)}},B=r.filter(e=>{const t=x.toLowerCase(),s=e.email.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.description.toLowerCase().includes(t),r="all"===g||e.status===g,a="all"===y||(e.inquiry_type??"")===y;return s&&r&&a}),T=Math.max(1,Math.ceil(B.length/N)),S=B.slice((v-1)*N,v*N);return l?e.jsxs("div",{className:"min-h-screen flex items-center justify-center",style:{background:s.sectionBg},children:[e.jsx(Ha,{p:s}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-4",children:[e.jsx(K,{className:"h-10 w-10 animate-spin",style:{color:s.accentText}}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:"Loading submissions…"})]})]}):o?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-6",style:{background:s.sectionBg},children:[e.jsx(Ha,{p:s}),e.jsxs("div",{className:"relative z-10 rounded-2xl p-8 max-w-md w-full text-center space-y-4",style:{background:s.cardBg,border:`1px solid ${s.cardBorder}`},children:[e.jsx(le,{className:"h-10 w-10 mx-auto",style:{color:s.redAccent}}),e.jsx("p",{className:"font-semibold",style:{color:s.headlineColor},children:"Failed to load"}),e.jsx("p",{className:"text-sm",style:{color:s.mutedText},children:o}),e.jsxs("button",{type:"button",onClick:_,className:"px-5 py-2.5 rounded-xl text-sm font-semibold mx-auto flex items-center gap-2 transition-opacity hover:opacity-80",style:{background:s.btnPrimaryBg,color:"#fff",border:"none",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Retry"]})]})]}):e.jsxs("div",{className:"min-h-screen transition-colors duration-300",style:{background:s.sectionBg},children:[e.jsx(Ha,{p:s}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-6 py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:s.headlineColor},children:"Contact Submissions"}),e.jsxs("button",{type:"button",onClick:_,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-80",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{className:"h-4 w-4"})," Refresh"]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:[{status:"pending",label:"New"},{status:"in_progress",label:"To Respond"},{status:"responded",label:"Responded"}].map(({status:t,label:a})=>{const l=Oa[t],n=r.filter(e=>e.status===t).length;return e.jsxs("button",{type:"button",onClick:()=>b(g===t?"all":t),className:"rounded-2xl p-5 text-left transition-all duration-200 hover:scale-[1.01]",style:{background:g===t?l.bgOpacity:s.statCardBg,border:`1.5px solid ${g===t?l.borderOpacity:s.statCardBorder}`,cursor:"pointer"},children:[e.jsx("p",{className:"text-2xl font-bold",style:{fontFamily:"'Roboto Slab', serif",color:l.textColor},children:n}),e.jsx("p",{className:"text-xs mt-1",style:{color:s.mutedText},children:a})]},t)})}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[e.jsx(qa,{value:x,onChange:p,placeholder:"Search by email, subject, or message…",icon:G,p:s}),e.jsx(Wa,{value:g,onChange:e=>b(e),p:s,options:[{value:"all",label:"All Status"},{value:"pending",label:"New"},{value:"in_progress",label:"To Respond"},{value:"responded",label:"Responded"}]}),e.jsx(Wa,{value:y,onChange:e=>f(e),p:s,options:[{value:"all",label:"All Types"},{value:"job_seeker",label:"Job Seeker"},{value:"college",label:"College"},{value:"corporate",label:"Corporate"},{value:"other",label:"Any Other"}]})]}),e.jsxs("p",{className:"text-xs",style:{color:s.mutedText},children:["Showing ",S.length," of ",B.length," submissions"]}),e.jsx("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${s.cardBorder}
1`,background:s.cardBg},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",style:{minWidth:900},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:s.tableHeaderBg,borderBottom:`1px solid ${s.tableBorder}`},children:["Date","Contact","Type","Subject","Message","Status","Actions"].map(t=>e.jsx("th",{className:"text-left py-3 px-4 text-xs font-bold uppercase tracking-wide",style:{color:s.tableHeaderText},children:t},t))})}),e.jsx("tbody",{children:0===S.length?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"text-center py-12",style:{color:s.mutedText},children:"No submissions found"})}):S.map((t,r)=>e.jsxs("tr",{style:{borderBottom:r<S.length-1?`1px solid ${s.tableBorder}`:"none",transition:"background 0.15s"},onMouseEnter:e=>e.currentTarget.style.background=s.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-3 px-4 text-xs whitespace-nowrap",style:{color:s.mutedText},children:St(new Date(t.created_at),"MMM dd, yy HH:mm")}),e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("p",{className:"text-sm font-medium",style:{color:s.bodyText},children:t.email}),e.jsx("p",{className:"text-xs",style:{color:s.mutedText},children:t.phone_number})]}),e.jsx("td",{className:"py-3 px-4 text-xs",style:{color:s.bodyText},children:"job_seeker"===t.inquiry_type?"Job Seeker":"college"===t.inquiry_type?"College":"corporate"===t.inquiry_type?"Corporate":"other"===t.inquiry_type?"Any Other":"—"}),e.jsx("td",{className:"py-3 px-4 font-medium max-w-[160px] truncate",style:{color:s.bodyText},children:t.subject}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("p",{className:"text-sm max-w-[220px] line-clamp-2",style:{color:s.mutedText},children:t.description})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(za,{status:t.status})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Va,{icon:ee,onClick:()=>{return e=t.email,s=t.subject,void(window.location.href=`mailto:${e}?subject=Re: ${encodeURIComponent(s)}`);var e,s},title:"Reply via Email",p:s}),"pending"===t.status&&e.jsx(Va,{icon:d===t.id?K:Se,onClick:()=>C(t.id,"in_progress"),title:"Mark as To Respond",disabled:d===t.id,variant:d===t.id?"spin":"default",p:s}),("pending"===t.status||"in_progress"===t.status)&&e.jsx(Va,{icon:d===t.id?K:be,onClick:()=>C(t.id,"responded"),title:"Mark as Responded",disabled:d===t.id,variant:"success",p:s})]})})]},t.id))})]})})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:"Rows per page:"}),e.jsx(Wa,{value:String(N),onChange:e=>{k(Number(e)),w(1)},p:s,options:Ga.map(e=>({value:String(e),label:String(e)}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:["Page ",v," of ",T]}),e.jsx("button",{type:"button",disabled:v<=1,onClick:()=>w(e=>e-1),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:v<=1?"not-allowed":"pointer"},children:e.jsx(ne,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",disabled:v>=T,onClick:()=>w(e=>e+1),className:"rounded-lg p-1.5 transition-opacity hover:opacity-70 disabled:opacity-30",style:{background:s.stepLockedBg,border:`1px solid ${s.stepLockedBorder}`,color:s.bodyText,cursor:v>=T?"not-allowed":"pointer"},children:e.jsx(oe,{className:"h-4 w-4"})})]})]})]})]})},Ya=()=>{const t=ua(),[s,r]=c.useState(!0),[a,l]=c.useState({dbStatus:"healthy",totalUsers:0,totalInterviews:0,pendingEvaluations:0,failedEvaluations:0,recentErrors:[]});c.useEffect(()=>{n()},[]);const n=async()=>{var e,t;r(!0);try{const[s,r,a]=await Promise.all([h.from("profiles").select("id",{count:"exact",head:!0}),h.from("interviews").select("id",{count:"exact",head:!0}),h.from("evaluation_status").select("status")]),n=(null==(e=a.data)?void 0:e.filter(e=>"pending"===e.status||"processing"===e.status).length)||0,o=(null==(t=a.data)?void 0:t.filter(e=>"failed"===e.status).length)||0,{data:i}=await h.from("evaluation_status").select("evaluation_type").eq("status","failed").order("created_at",{ascending:!1}).limit(50),d={};
1null==i||i.forEach(e=>{d[e.evaluation_type]=(d[e.evaluation_type]||0)+1});const c=Object.entries(d).map(([e,t])=>({type:e,count:t}));l({dbStatus:s.error?"error":"healthy",totalUsers:s.count||0,totalInterviews:r.count||0,pendingEvaluations:n,failedEvaluations:o,recentErrors:c})}catch(s){w.error("Failed to load health data"),l(e=>({...e,dbStatus:"error"}))}finally{r(!1)}};if(s)return e.jsx(ca,{p:t});const o={healthy:{icon:be,color:t.successText,label:"Healthy"},degraded:{icon:Fe,color:t.warnText,label:"Degraded"},error:{icon:De,color:t.errorText,label:"Error"}}[a.dbStatus],i=o.icon,d=a.totalInterviews>0?Math.round((a.totalInterviews-a.failedEvaluations)/a.totalInterviews*100):100;return e.jsxs("div",{className:"space-y-6",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em]",style:{color:t.accentText},children:"Monitoring"}),e.jsx("h2",{className:"text-xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:"System Health"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:t.mutedText},children:"Platform status and monitoring"})]}),e.jsx(da,{onClick:n,loading:s,p:t})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-xl p-4 flex items-center gap-3",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:`${o.color}18`,border:`1px solid ${o.color}40`},children:e.jsx(i,{className:"w-5 h-5",style:{color:o.color}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.12em]",style:{color:t.mutedText},children:"Database"}),e.jsx("p",{className:"text-lg font-bold",style:{fontFamily:"'Roboto Slab',serif",color:o.color},children:o.label})]})]}),e.jsx(na,{label:"Total Users",value:a.totalUsers.toLocaleString(),p:t}),e.jsx(na,{label:"Total Interviews",value:a.totalInterviews.toLocaleString(),p:t})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(na,{label:"Pending Evaluations",value:e.jsx("span",{style:{color:t.warnText},children:a.pendingEvaluations}),sub:"In queue or processing",p:t}),e.jsx(na,{label:"Failed Evaluations",value:e.jsx("span",{style:{color:t.errorText},children:a.failedEvaluations}),sub:"Need attention",p:t}),e.jsx(na,{label:"Eval Completion Rate",value:e.jsxs("span",{style:{color:d>=90?t.successText:t.warnText},children:[d,"%"]}),p:t})]}),e.jsx(oa,{title:"Recent Evaluation Failures",desc:"Breakdown by type (last 50 records)",p:t,children:0===a.recentErrors.length?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"w-4 h-4",style:{color:t.successText}}),e.jsx("span",{className:"text-sm",style:{color:t.successText},children:"No recent failures — all systems normal"})]}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.recentErrors.map((s,r)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold",style:{background:t.errorBg,border:`1px solid ${t.errorBorder}`,color:t.errorText},children:[e.jsx(De,{className:"w-3 h-3"}),s.type,": ",s.count," failures"]},r))})}),e.jsx(oa,{title:"Health Summary",p:t,children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[{label:"Database connectivity",ok:"healthy"===a.dbStatus},{label:"Evaluation queue",ok:a.pendingEvaluations<50},{label:"Error rate",ok:a.recentErrors.reduce((e,t)=>e+t.count,0)<10},{label:"Overall system",ok:"healthy"===a.dbStatus&&a.failedEvaluations<20}].map((s,r)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl",style:{background:s.ok?t.successBg:t.errorBg,border:`1px solid ${s.ok?"rgba(16,185,129,0.30)":t.errorBorder}`},children:[s.ok?e.jsx(be,{className:"w-4 h-4 flex-shrink-0",style:{color:t.successText}}):e.jsx(De,{className:"w-4 h-4 flex-shrink-0",style:{color:t.errorText}}),e.jsx("span",{className:"text-sm",style:{color:s.ok?t.successText:t.errorText},children:s.label})]},r))})})]})},Ja=()=>{const t=ua(),[s,r]=c.useState(!0),[a,l]=c.useState({totalInterviews:0,
1completedCount:0,cancelledCount:0,failedCount:0,avgDuration:0,peakHours:[],countryDistribution:[],scoreDistribution:[],typeBreakdown:[],statusBreakdown:[]});c.useEffect(()=>{n()},[]);const n=async()=>{r(!0);try{const{data:e}=await h.from("interviews").select("*, profiles!interviews_user_id_fkey(country)").neq("status","setup"),{data:t}=await h.from("technical_interview_scores").select("overall_technical_score"),{data:s}=await h.from("behavioral_interview_scores").select("overall_behavioral_score"),{data:r}=await h.from("overall_interview_scores").select("overall_overall_score"),a=(null==e?void 0:e.length)||0,n=(null==e?void 0:e.filter(e=>"completed"===e.status))||[],o=n.length,i=(null==e?void 0:e.filter(e=>"cancelled"===e.status).length)||0,d=(null==e?void 0:e.filter(e=>"evaluation_failed"===e.status||"connection_failed"===e.status).length)||0,c=o>0?Math.round(n.reduce((e,t)=>e+(t.duration_minutes||0),0)/o):0,u={};null==e||e.forEach(e=>{const t=new Date(e.created_at).getHours();u[t]=(u[t]||0)+1});const x=Object.entries(u).map(([e,t])=>({hour:parseInt(e),count:t})).sort((e,t)=>t.count-e.count).slice(0,5),p={};null==e||e.forEach(e=>{var t;const s=(null==(t=e.profiles)?void 0:t.country)||"Unknown";p[s]=(p[s]||0)+1});const m=Object.entries(p).map(([e,t])=>({country:e,count:t})).sort((e,t)=>t.count-e.count).slice(0,10),g=[...(null==t?void 0:t.map(e=>e.overall_technical_score))||[],...(null==s?void 0:s.map(e=>e.overall_behavioral_score))||[],...(null==r?void 0:r.map(e=>e.overall_overall_score))||[]].filter(e=>null!==e),b={"0-20":0,"21-40":0,"41-60":0,"61-80":0,"81-100":0};g.forEach(e=>{e<=20?b["0-20"]++:e<=40?b["21-40"]++:e<=60?b["41-60"]++:e<=80?b["61-80"]++:b["81-100"]++});const y=Object.entries(b).map(([e,t])=>({range:e,count:t})),f=(null==e?void 0:e.filter(e=>"technical"===e.interview_type).length)||0,v=(null==e?void 0:e.filter(e=>"behavioral"===e.interview_type).length)||0,j=(null==e?void 0:e.filter(e=>"overall"===e.interview_type).length)||0,w=[{type:"Technical",count:f,percentage:a>0?Math.round(f/a*100):0},{type:"Behavioral",count:v,percentage:a>0?Math.round(v/a*100):0},{type:"Overall",count:j,percentage:a>0?Math.round(j/a*100):0}],N=[{status:"Completed",count:o},{status:"Cancelled",count:i},{status:"Failed",count:d},{status:"In Progress",count:(null==e?void 0:e.filter(e=>"in_progress"===e.status).length)||0}];l({totalInterviews:a,completedCount:o,cancelledCount:i,failedCount:d,avgDuration:c,peakHours:x,countryDistribution:m,scoreDistribution:y,typeBreakdown:w,statusBreakdown:N})}catch(e){w.error("Failed to load insights")}finally{r(!1)}};if(s)return e.jsx(ca,{p:t});const o=Math.max(...a.peakHours.map(e=>e.count),1);return e.jsxs("div",{className:"space-y-6",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em]",style:{color:t.accentText},children:"Analytics"}),e.jsx("h2",{className:"text-xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:"Interview Insights"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:t.mutedText},children:"Deep analytics on interview patterns"})]}),e.jsx(da,{onClick:n,loading:s,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(na,{label:"Total",value:a.totalInterviews,accent:!0,p:t}),e.jsx(na,{label:"Completed",value:e.jsx("span",{style:{color:t.successText},children:a.completedCount}),p:t}),e.jsx(na,{label:"Cancelled",value:e.jsx("span",{style:{color:t.warnText},children:a.cancelledCount}),p:t}),e.jsx(na,{label:"Failed",value:e.jsx("span",{style:{color:t.errorText},children:a.failedCount}),p:t}),e.jsx(na,{label:"Avg Duration",value:`${a.avgDuration} min`,p:t}),a.typeBreakdown.slice(0,1).map(s=>e.jsx(na,{label:s.type,value:e.jsxs(e.Fragment,{children:[s.count," ",e.jsxs("span",{className:"text-sm font-normal",style:{color:t.mutedText},children:["(",s.percentage,"%)"]})]}),p:t},s.type))]}),e.jsx(oa,{title:"Interview Type Distribution",p:t,children:e.jsx("div",{className:"space-y-3",children:a.typeBreakdown.map(s=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{style:{color:t.bodyText},children:s.type}),e.jsxs("span",{className:"font-semibold",style:{color:t.headlineColor},children:[s.count," ",e.jsxs("span",{style:{color:t.mutedText},children:["(",s.percentage,"%)"]})]})]}),e.jsx(ia,{value:s.percentage,p:t})]},s.type))})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[e.jsx(oa,{title:"Score Distribution",desc:"Scores across all evaluations",p:t,children:e.jsx("div",{className:"space-y-3",children:a.scoreDistribution.map(s=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{style:{color:t.bodyText},children:s.range}),e.jsx("span",{className:"font-semibold",style:{color:t.headlineColor},children:s.count})]}),e.jsx(ia,{value:a.totalInterviews>0?s.count/a.totalInterviews*100:0,p:t})]},s.range))})}),e.jsx(oa,{title:"Top Countries",desc:"Geographic distribution of interviews",p:t,children:0===a.countryDistribution.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):e.jsx("div",{className:"divide-y",style:{borderColor:t.divider},children:a.countryDistribution.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-sm",style:{color:t.bodyText},children:s.country}),e.jsx("span",{className:"text-sm font-bold",style:{color:t.headlineColor},children:s.count})]},r))})})]}),e.jsx(oa,{title:"Peak Usage Hours",desc:"Most active hours (24h format)",p:t,children:e.jsx("div",{className:"grid grid-cols-5 ga
1p-2",children:a.peakHours.map(s=>e.jsxs("div",{className:"flex flex-col items-center gap-1.5 p-3 rounded-xl",style:{background:t.accentBg,border:`1px solid ${t.accentBorder}`},children:[e.jsxs("span",{className:"text-lg font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:[s.hour,":00"]}),e.jsx("div",{className:"w-full h-1.5 rounded-full overflow-hidden",style:{background:t.progressBg},children:e.jsx("div",{className:"h-full rounded-full",style:{width:s.count/o*100+"%",background:t.progressFill}})}),e.jsxs("span",{className:"text-[10px]",style:{color:t.mutedText},children:[s.count," interviews"]})]},s.hour))})})]})},Qa=()=>{const t=ua(),[s,r]=c.useState(!0),[a,l]=c.useState({totalRevenue:0,monthlyRevenue:0,weeklyRevenue:0,todayRevenue:0,avgOrderValue:0,totalOrders:0,uniqueCustomers:0,refundAmount:0,packBreakdown:[],dailyRevenue:[]});c.useEffect(()=>{n()},[]);const n=async()=>{r(!0);try{const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),s=$t(e,7),r=$t(e,30),{data:a}=await h.from("orders").select("*, credit_packs!fk_orders_pack(title)"),n=(null==a?void 0:a.filter(e=>"paid"===e.status))||[],o=(null==a?void 0:a.filter(e=>"refunded"===e.status))||[],i=n.reduce((e,t)=>e+Number(t.amount_inr),0),d=n.filter(e=>new Date(e.created_at)>=r).reduce((e,t)=>e+Number(t.amount_inr),0),c=n.filter(e=>new Date(e.created_at)>=s).reduce((e,t)=>e+Number(t.amount_inr),0),u=n.filter(e=>new Date(e.created_at)>=t).reduce((e,t)=>e+Number(t.amount_inr),0),x=o.reduce((e,t)=>e+Number(t.amount_inr),0),p=new Set(n.map(e=>e.user_id)).size,m=n.length>0?Math.round(i/n.length):0,g={};n.forEach(e=>{var t;const s=(null==(t=e.credit_packs)?void 0:t.title)||"Unknown";g[s]||(g[s]={count:0,revenue:0}),g[s].count++,g[s].revenue+=Number(e.amount_inr)});const b=Object.entries(g).map(([e,t])=>({title:e,...t})).sort((e,t)=>t.revenue-e.revenue),y={};for(let l=6;l>=0;l--)y[St($t(e,l),"MMM dd")]=0;n.filter(e=>new Date(e.created_at)>=s).forEach(e=>{const t=St(new Date(e.created_at),"MMM dd");void 0!==y[t]&&(y[t]+=Number(e.amount_inr))});const f=Object.entries(y).map(([e,t])=>({date:e,amount:t}));l({totalRevenue:i,monthlyRevenue:d,weeklyRevenue:c,todayRevenue:u,avgOrderValue:m,totalOrders:n.length,uniqueCustomers:p,refundAmount:x,packBreakdown:b,dailyRevenue:f})}catch(e){w.error("Failed to load revenue data")}finally{r(!1)}};if(s)return e.jsx(ca,{p:t});const o=Math.max(...a.dailyRevenue.map(e=>e.amount),1);return e.jsxs("div",{className:"space-y-6",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em]",style:{color:t.accentText},children:"Finance"}),e.jsx("h2",{className:"text-xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:t.headlineColor},children:"Revenue Analytics"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:t.mutedText},children:"Financial metrics and trends"})]}),e.jsx(da,{onClick:n,loading:s,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Revenue",value:`₹${a.totalRevenue.toLocaleString()}`,accent:!0,p:t}),e.jsx(na,{label:"Monthly (30d)",value:`₹${a.monthlyRevenue.toLocaleString()}`,p:t}),e.jsx(na,{label:"Weekly (7d)",value:`₹${a.weeklyRevenue.toLocaleString()}`,p:t}),e.jsx(na,{label:"Today",value:`₹${a.todayRevenue.toLocaleString()}`,p:t})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(na,{label:"Total Orders",value:a.totalOrders,p:t}),e.jsx(na,{label:"Unique Customers",value:a.uniqueCustomers,p:t}),e.jsx(na,{label:"Avg Order Value",value:`₹${a.avgOrderValue}`,p:t}),e.jsx(na,{label:"Refunds",value:e.jsxs("span",{style:{color:t.errorText},children:["₹",a.refundAmount.toLocaleString()]}),p:t})]}),e.jsx(oa,{title:"Daily Revenue — Last 7 Days",p:t,children:e.jsx("div",{className:"flex items-end gap-2 h-36",children:a.dailyRevenue.map(s=>e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1",children:[e.jsx("span",{className:"text-[10px]",style:{color:t.mutedText},children:s.amount>0?`₹${(s.amount/1e3).toFixed(1)}k`:""}),e.jsx("div",{className:"w-full rounded-t transition-all duration-500",style:{height:s.amount/o*100+"%",minHeight:s.amount>0?8:2,background:s.amount>0?"linear-gradient(to top,rgba(139,92,246,0.70),rgba(167,139,250,0.90))":"rgba(255,255,255,0.06)"}}),e.jsx("span",{className:"text-[9px]",style:{color:t.mutedText},children:s.date.split(" ")[1]})]},s.date))})}),e.jsx(oa,{title:"Revenue by Credit Pack",desc:"Top performing packs",p:t,children:0===a.packBreakdown.length?e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No data yet"}):e.jsx("div",{className:"space-y-3",children:a.packBreakdown.map((s,r)=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{style:{color:t.bodyText},children:s.title}),e.jsxs("span",{className:"font-semibold",style:{color:t.headlineColor}
1,children:["₹",s.revenue.toLocaleString()," ",e.jsxs("span",{style:{color:t.mutedText},children:["(",s.count," orders)"]})]})]}),e.jsx(ia,{value:a.totalRevenue>0?s.revenue/a.totalRevenue*100:0,p:t})]},r))})})]})},Xa=[{value:"0-1 years",label:"Fresher (0-1 yrs)"},{value:"2-5 years",label:"Early Career (2-5)"},{value:"6-10 years",label:"Mid-Level (6-10)"},{value:"11-15 years",label:"Senior (11-15)"},{value:"16-20 years",label:"Leadership (16-20)"},{value:"20+ years",label:"Executive (20+)"}],Za={Fresher:"0-1 years","Early Career":"2-5 years","Mid-Level":"6-10 years","Senior Professional":"11-15 years","Leadership / Expert":"16-20 years","Executive / C-Suite":"20+ years"},el={experience_levels:[],countries:[],signup_date_from:"",signup_date_to:"",min_credits:"",max_credits:"",has_completed_interview:!1,min_interviews:"",has_purchased:!1,inactive_days:"",email_contains:""},tl=({p:t,style:s,...r})=>e.jsx("input",{...r,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,...s},onFocus:e=>{var s;e.target.style.borderColor=t.inputFocusBorder,null==(s=r.onFocus)||s.call(r,e)},onBlur:e=>{var s;e.target.style.borderColor=t.inputBorder,null==(s=r.onBlur)||s.call(r,e)}}),sl=({p:t,...s})=>e.jsx("textarea",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all resize-none",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,minHeight:70},onFocus:e=>{e.target.style.borderColor=t.inputFocusBorder},onBlur:e=>{e.target.style.borderColor=t.inputBorder}}),rl=({p:t,children:s})=>e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider mb-1.5",style:{color:t.labelText},children:s}),al=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:s}),ll=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:s}),nl=({p:t,style:s,...r})=>e.jsx("input",{...r,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,...s},onFocus:e=>{var s;e.target.style.borderColor=t.inputFocusBorder,null==(s=r.onFocus)||s.call(r,e)},onBlur:e=>{var s;e.target.style.borderColor=t.inputBorder,null==(s=r.onBlur)||s.call(r,e)}}),ol=({p:t,...s})=>e.jsx("textarea",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all resize-none",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,minHeight:72},onFocus:e=>{e.target.style.borderColor=t.inputFocusBorder},onBlur:e=>{e.target.style.borderColor=t.inputBorder}}),il=({p:t,value:s,onChange:r,children:a})=>e.jsx("select",{value:s,onChange:e=>r(e.target.value),className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},children:a}),dl=({p:t,children:s})=>e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider mb-1.5",style:{color:t.labelText},children:s}),cl=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:s}),ul=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:s}),xl=({status:t,p:s})=>{const r={draft:{bg:s.cardBg,border:s.cardBorder,text:s.mutedText},scheduled:{bg:s.infoBg,border:s.infoBorder,text:s.infoText},active:{bg:s.successBg,border:s.successBorder,text:s.successText},paused:{bg:s.warningBg,border:s.warningBorder,text:s.warningText},completed:{bg:s.pillBg,border:s.pillBorder,text:s.pillText}},a=r[t]??r.draft;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold capitalize",style:{background:a.bg,border:`1px solid ${a.border}`,color:a.text},children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:a.text},"aria-hidden":!0}),t]})},pl=({p:t,campaignName:s,setCampaignName:r,campaignDescription:a,setCampaignDescription:l,selectedSegment:n,setSelectedSegment:o,selectedTemplate:i,setSelectedTemplate:d,segments:c,templates:u})=>e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Campaign Name *"}),e.jsx(nl,{p:t,value:s,onChange:e=>r(e.target.value),placeholder:"e.g., Welcome Series — Week 1"})]}),e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Description"}),e.jsx(ol,{p:t,value:a,onChange:e=>l(e.target.value),placeholder:"Campaign description…"})]}),e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Target Segment *"}),e.jsxs(il,{p:t,value:n,onChange:o,children:[e.jsx("option",{value:"",style:{background:"#1a0235"},children:"— Select segment —"}),c.map(t=>e.jsxs("option",{value:t.id,style:{background:"#1a0235"},children:[t.name," (",t.user_count," users)"]},t.id))]})]}),e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Email Template *"}),e.jsxs(il,{p:t,value:i,onChange:d,children:[e.jsx("option",{value:"",style:{background:"#1a0235"},children:"— Select template —"}),u.map(t=>e.jsx("option",{value:t.id,style:{background:"#1a0235"},children:t.name},t.id))]})]})]}),ml=[{variable:"{{full_name}}",description:"User's full name"},{variable:"{{email}}",description:"User's email"},{variable:"{{credits}}",description:"User's credits"},{variable:"{{unsubscribe_link}}",description:"Unsubscribe URL"}],hl='<!DOCTYPE html>\n<html>\n<head>\n  <meta charset="utf-8">\n  <meta name="viewport" content="width=device-width, initial-scale=1.0">\n  <title>{{subject}}</title>\n</head>\n<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">\n  <div style="text-align: center; margin-bottom: 30px;">\n    <img src="https://smartmentorv2.lovable.app/logo.png" alt="SmartMentor" style="height: auto; width: 200px; max-width: 100%;">\n  </div>\n  <h1 style="color: #2563eb; margin-bottom: 20px;">Hello {{full_name}}!</h1>\n  <p>Your content goes here...</p>\n  <div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee; text-align: center; color: #666; font-size: 12px;">\n    <p>SmartMentor.ai - AI-Powered Interview Practice</p>\n    <p><a href="{{unsubscribe_link}}" style="color: #666;">Unsubscribe</a></p>\n  </div>\n</body>\n</html>',gl=({p:t,...s})=>e.jsx("input",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},onFocus:e=>{var r;e.target.style.borderColor=t.inputFocusBorder,null==(r=s.onFocus)||r.call(s,e)},onBlur:e=>{var r;e.target.style.borderColor=t.inputBorder,null==(r=s.onBlur)||r.call(s,e)}}),bl=({p:t,children:s})=>e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider mb-1.5",style:{color:t.labelText},children:s}),yl=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:s}),fl=({p:t,children:s,disabled:r,onClick:a,className:l="",title:n=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,title:n,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:s}),vl=({p:t,templateName:s,setTemplateName:r,templateSubject:a,setTemplateSubject:l,templateHtml:n,setTemplateHtml:o,templateCategory:i,setTemplateCategory:d})=>e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(bl,{p:t,children:"Template Name *"}),e.jsx(gl,{p:t,value:s,onChange:e=>r(e.target.value),placeholder:"e.g., Welcome Email"})]}),e.jsxs("div",{children:[e.jsx(bl,{p:t,children:"Category"}),e.jsx(gl,{p:t,value:i,onChange:e=>d(e.target.value),placeholder:"e.g., onboarding"})]})]}),e.jsxs("div",{children:[e.jsx(bl,{p:t,children:"Email Subject *"}),e.jsx(gl,{p:t,value:a,onChange:e=>l(e.target.value),placeholder:"e.g., Welcome to SmartMentor, {{full_name}}!"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(bl,{p:t,children:"HTML Content *"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:ml.map(s=>e.jsxs(fl,{p:t,onClick:()=>{return e=s.variable,o(n+e);var e},title:s.description,children:[e.jsx(tt,{style:{width:10,height:10},"aria-hidden":!0}),s.variable]},s.variable))})]}),e.jsx("textarea",{value:n,onChange:e=>o(e.target.value),placeholder:"HTML email content…",className:"w-full px-3 py-2.5 rounded-xl text-xs outline-none transition-all font-mono resize-y",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,minHeight:240},onFocus:e=>{e.target.style.borderColor=t.inputFocusBorder},onBlur:e=>{e.target.style.borderColor=t.inputBorder},"aria-label":"HTML template content"})]})]}),jl=[{value:"signup",label:"User Signup"},{value:"purchase",label:"First Purchase"},{value:"inactivity",label:"User Inactivity"},{value:"interview_complete",label:"Interview Completed"},{value:"manual",label:"Manual Trigger"}],wl=({p:t,...s})=>e.jsx("input",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all duration-200",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},onFocus:e=>{var r;e.target.style.borderColor=t.inputFocusBorder,null==(r=s.onFocus)||r.call(s,e)},onBlur:e=>{var r;e.target.style.borderColor=t.inputBorder,null==(r=s.onBlur)||r.call(s,e)}}),Nl=({p:t,...s})=>e.jsx("textarea",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all duration-200 resize-none",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,minHeight:80},onFocus:e=>{e.target.style.borderColor=t.inputFocusBorder},onBlur:e=>{e.target.style.borderColor=t.inputBorder}}),kl=({p:t,children:s,className:r=""})=>e.jsx("p",{className:`text-xs font-semibold uppercase tracking-wider mb-1.5 ${r}`,style:{color:t.labelText},children:s}),_l=({p:t,children:s,disabled:r,onClick:a,className:l="",type:n="button"})=>e.jsx("button",{type:n,onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:s}),Cl=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:s}),Bl=({p:t,children:s,onClick:r,className:a=""})=>e.jsx("button",{type:"button",onClick:r,className:`inline-flex items-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium transition-all hover:opacity-90 active:scale-95 ${a}`,style:{background:"transparent",color:t.mutedText},onMouseEnter:e=>{e.currentTarget.style.background=t.btnGhostHoverBg},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:s}),Tl=({status:t,p:s})=>{const r={draft:{bg:s.cardBg,border:s.cardBorder,text:s.mutedText},active:{bg:s.successBg,border:s.successBorder,text:s.successText},paused:{bg:s.warningBg,border:s.warningBorder,text:s.warningText},archived:{bg:s.dangerBg,border:s.dangerBorder,text:s.dangerText}},a=r[t]??r.draft;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold capitalize",style:{background:a.bg,border:`1px solid ${a.border}`,color:a.text},children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:a.text},"aria-hidden":!0}),t]})},Sl=({step:t,index:s,onUpdate:r,onRemove:a,p:l})=>e.jsxs("div",{className:"rounded-xl p-4 flex items-center gap-3",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`},children:[e.jsx("span",{className:"flex-shrink-0 w-6 h-6 rounded-lg flex items-center justify-center text-[10px] font-bold",style:{background:l.pillBg,border:`1px solid ${l.pillBorder}`,color:l.pillText},children:s+1}),e.jsx("div",{className:"flex-1 flex items-center gap-3 flex-wrap min-w-0",children:"delay"===t.type?e.jsxs(e.Fragment,{children:[e.jsx(Se,{style:{width:14,height:14,color:l.accentText,flexShrink:0},"aria-hidden":!0}),e.jsx("span",{className:"text-sm",style:{color:l.bodyText},children:"Wait"}),e.jsx(wl,{p:l,type:"number",value:t.config.minutes||60,onChange:e=>r(t.id,{minutes:parseInt(e.target.value)||60}),style:{width:72},"aria-label":"Delay minutes"}),e.jsx("span",{className:"text-sm",style:{color:l.mutedText},children:"minutes"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{style:{width:14,height:14,color:l.accentText,flexShrink:0},"aria-hidden":!0}),e.jsx("span",{className:"text-sm",style:{color:l.bodyText},children:"Send Email"}),e.jsx(wl,{p:l,value:t.config.template_id||"",onChange:e=>r(t.id,{template_id:e.target.value}),placeholder:"Template ID",style:{width:160},"aria-label":"Template ID"})]})}),e.jsx("button",{type:"button",onClick:()=>a(t.id),className:"flex-shrink-0 p-1.5 rounded-lg transition-all hover:opacity-80 active:scale-90",style:{background:l.dangerBg,border:`1px solid ${l.dangerBorder}`},"aria-label":`Remove step ${s+1}`,children:e.jsx(ge,{style:{width:13,height:13,color:l.dangerText},"aria-hidden":!0})})]}),$l=({p:t,workflowName:s,setWorkflowName:r,workflowDescription:a,setWorkflowDescription:l,triggerType:n,setTriggerType:o,steps:i,onAddStep:d,onUpdateStep:c,onRemoveStep:u})=>e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(kl,{p:t,children:"Workflow Name *"}),e.jsx(wl,{p:t,value:s,onChange:e=>r(e.target.value),placeholder:"e.g., Welcome Sequence"})]}),e.jsxs("div",{children:[e.jsx(kl,{p:t,children:"Description"}),e.jsx(Nl,{p:t,value:a,onChange:e=>l(e.target.value),placeholder:"What does this workflow do?"})]}),e.jsxs("div",{children:[e.jsx(kl,{p:t,children:"Trigger Type"}),e.jsx("select",{value:n,onChange:e=>o(e.target.value),className:"w-full px-3 py-2 rounded-xl text-sm outline-none",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},children:jl.map(t=>e.jsx("option",{value:t.value,style:{background:"#1a0235"},children:t.label},t.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(kl,{p:t,className:"mb-0",children:"Workflow Steps"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Cl,{p:t,onClick:()=>d("delay"),children:[e.jsx(Se,{style:{width:12,height:12},"aria-hidden":!0}),"Add Delay"]}),e.jsxs(Cl,{p:t,onClick:()=>d("action"),children:[e.jsx(ee,{style:{width:12,height:12},"aria-hidden":!0}),"Add Email"]})]})]}),0===i.length?e.jsx
1s("div",{className:"rounded-xl p-8 flex flex-col items-center gap-3 text-center",style:{border:`1px dashed ${t.cardBorder}`},children:[e.jsx(pe,{style:{width:28,height:28,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"Add steps to build your workflow"})]}):e.jsx("div",{className:"space-y-2",children:i.map((s,r)=>e.jsx(Sl,{step:s,index:r,onUpdate:c,onRemove:u,p:t},s.id))})]})]}),Fl=({p:t,icon:s,label:r,value:a,sub:l,iconBg:n,iconColor:o})=>e.jsxs("div",{className:"rounded-2xl p-4 sm:p-5 flex items-center gap-4 transition-all hover:scale-[1.01]",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`,backdropFilter:"blur(12px)"},children:[e.jsx("div",{className:"flex-shrink-0 w-11 h-11 rounded-xl flex items-center justify-center",style:{background:n},children:e.jsx(s,{style:{width:20,height:20,color:o},"aria-hidden":!0})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:t.labelText},children:r}),e.jsx("p",{className:"text-2xl font-bold font-mono tabular-nums",style:{color:t.headlineColor},children:a}),l&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:t.mutedText},children:l})]})]}),Al=({active:t,payload:s,label:r,p:a})=>t&&(null==s?void 0:s.length)?e.jsxs("div",{className:"rounded-xl px-3 py-2 text-xs shadow-xl",style:{background:"rgba(26,2,53,0.95)",border:`1px solid ${a.cardBorder}`,color:a.bodyText},children:[e.jsx("p",{className:"font-semibold mb-1",style:{color:a.headlineColor},children:r}),s.map(t=>e.jsxs("p",{style:{color:t.fill??a.accentText},children:[t.name,": ",e.jsx("span",{className:"font-bold",children:t.value})]},t.name))]}):null,Rl=({currentPage:t,totalItems:s,pageSize:r,onPageChange:a,onPageSizeChange:l})=>{const n=Math.ceil(s/r),o=(t-1)*r+1,i=Math.min(t*r,s);return e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{children:"Show"}),e.jsxs(g,{value:r.toString(),onValueChange:e=>l(Number(e)),children:[e.jsx(b,{className:"w-[70px] h-8",children:e.jsx(y,{})}),e.jsxs(f,{children:[e.jsx(v,{value:"10",children:"10"}),e.jsx(v,{value:"25",children:"25"}),e.jsx(v,{value:"50",children:"50"}),e.jsx(v,{value:"100",children:"100"})]})]}),e.jsxs("span",{children:["of ",s," (",o,"-",i,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{variant:"outline",size:"sm",onClick:()=>a(1),disabled:1===t,className:"h-8 w-8 p-0",children:e.jsx(lt,{className:"h-4 w-4"})}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>a(t-1),disabled:1===t,className:"h-8 w-8 p-0",children:e.jsx(ne,{className:"h-4 w-4"})}),e.jsxs("span",{className:"px-3 text-sm",children:["Page ",t," of ",n||1]}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>a(t+1),disabled:t>=n,className:"h-8 w-8 p-0",children:e.jsx(oe,{className:"h-4 w-4"})}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>a(n),disabled:t>=n,className:"h-8 w-8 p-0",children:e.jsx(nt,{className:"h-4 w-4"})})]})]})},El=({p:t,...s})=>e.jsx("input",{...s,className:"w-full px-3 py-2 rounded-xl text-sm outline-none transition-all duration-200",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},onFocus:e=>{var r;e.target.style.borderColor=t.inputFocusBorder,null==(r=s.onFocus)||r.call(s,e)},onBlur:e=>{var r;e.target.style.borderColor=t.inputBorder,null==(r=s.onBlur)||r.call(s,e)}}),Ll=({p:t,children:s})=>e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider mb-1.5",style:{color:t.labelText},children:s}),Dl=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:s}),Ml=({p:t,children:s,disabled:r,onClick:a,className:l=""})=>e.jsx("button",{type:"button",onClick:a,disabled:r,className:`inline-flex items-center gap-2 px-3 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed ${l}`,style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:s}
1),Il={dark:{sectionBg:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",cardBg:"rgba(255,255,255,0.04)",cardBgHover:"rgba(255,255,255,0.07)",cardBorder:"rgba(255,255,255,0.09)",cardBorderHover:"rgba(255,255,255,0.18)",inputBg:"rgba(255,255,255,0.06)",inputBorder:"rgba(255,255,255,0.12)",inputFocusBorder:"rgba(139,92,246,0.70)",progressBg:"rgba(255,255,255,0.10)",progressFill:"linear-gradient(to right, #a78bfa, #7c3aed)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.65)",mutedText:"rgba(255,255,255,0.38)",labelText:"rgba(255,255,255,0.50)",accentText:"#a78bfa",placeholderText:"rgba(255,255,255,0.28)",gridLine:"rgba(255,255,255,0.022)",divider:"rgba(255,255,255,0.07)",pillBg:"rgba(139,92,246,0.18)",pillBorder:"rgba(139,92,246,0.40)",pillText:"#a78bfa",successBg:"rgba(16,185,129,0.12)",successBorder:"rgba(16,185,129,0.35)",successText:"#6ee7b7",warningBg:"rgba(245,158,11,0.12)",warningBorder:"rgba(245,158,11,0.35)",warningText:"#fbbf24",dangerBg:"rgba(239,68,68,0.10)",dangerBorder:"rgba(239,68,68,0.30)",dangerText:"#f87171",infoBg:"rgba(59,130,246,0.10)",infoBorder:"rgba(59,130,246,0.30)",infoText:"#93c5fd",btnPrimaryBg:"linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%)",btnPrimaryText:"#ffffff",btnOutlineBg:"rgba(139,92,246,0.10)",btnOutlineBorder:"rgba(139,92,246,0.40)",btnOutlineText:"#a78bfa",btnGhostHoverBg:"rgba(255,255,255,0.06)",btnDestructiveBg:"rgba(239,68,68,0.15)",btnDestructiveBorder:"rgba(239,68,68,0.35)",btnDestructiveText:"#f87171",tableHeaderBg:"rgba(255,255,255,0.03)",tableRowHover:"rgba(255,255,255,0.03)",tableRowSelected:"rgba(139,92,246,0.10)",tableBorder:"rgba(255,255,255,0.06)",tabActiveBg:"rgba(139,92,246,0.25)",tabActiveBorder:"rgba(139,92,246,0.60)",tabActiveText:"#ffffff",tabInactiveBg:"rgba(255,255,255,0.04)",tabInactiveText:"rgba(255,255,255,0.45)",tabHoverBg:"rgba(139,92,246,0.12)",chartGrid:"rgba(255,255,255,0.06)",chartText:"rgba(255,255,255,0.45)",chartColors:["#a78bfa","#34d399","#fbbf24","#f87171","#60a5fa"],spinnerColor:"#a78bfa",checkboxBorder:"rgba(139,92,246,0.50)"},light:{sectionBg:"linear-gradient(160deg, #2D0550 0%, #5B1280 50%, #3D0A6E 100%)",cardBg:"rgba(255,255,255,0.07)",cardBgHover:"rgba(255,255,255,0.12)",cardBorder:"rgba(255,255,255,0.14)",cardBorderHover:"rgba(255,255,255,0.28)",inputBg:"rgba(255,255,255,0.10)",inputBorder:"rgba(255,255,255,0.20)",inputFocusBorder:"rgba(167,139,250,0.80)",progressBg:"rgba(255,255,255,0.18)",progressFill:"linear-gradient(to right, #c4b5fd, #8b5cf6)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.80)",mutedText:"rgba(255,255,255,0.50)",labelText:"rgba(255,255,255,0.60)",accentText:"#c4b5fd",placeholderText:"rgba(255,255,255,0.35)",gridLine:"rgba(255,255,255,0.038)",divider:"rgba(255,255,255,0.14)",pillBg:"rgba(167,139,250,0.22)",pillBorder:"rgba(167,139,250,0.50)",pillText:"#c4b5fd",successBg:"rgba(16,185,129,0.15)",successBorder:"rgba(16,185,129,0.45)",successText:"#a7f3d0",warningBg:"rgba(245,158,11,0.15)",warningBorder:"rgba(245,158,11,0.45)",warningText:"#fde68a",dangerBg:"rgba(239,68,68,0.15)",dangerBorder:"rgba(239,68,68,0.40)",dangerText:"#fca5a5",infoBg:"rgba(59,130,246,0.15)",infoBorder:"rgba(59,130,246,0.40)",infoText:"#bfdbfe",btnPrimaryBg:"linear-gradient(135deg, #8b5cf6 0%, #c4b5fd 100%)",btnPrimaryText:"#1a0035",btnOutlineBg:"rgba(167,139,250,0.15)",btnOutlineBorder:"rgba(167,139,250,0.55)",btnOutlineText:"#c4b5fd",btnGhostHoverBg:"rgba(255,255,255,0.10)",btnDestructiveBg:"rgba(239,68,68,0.18)",btnDestructiveBorder:"rgba(239,68,68,0.45)",btnDestructiveText:"#fca5a5",tableHeaderBg:"rgba(255,255,255,0.05)",tableRowHover:"rgba(255,255,255,0.05)",tableRowSelected:"rgba(167,139,250,0.15)",tableBorder:"rgba(255,255,255,0.10)",tabActiveBg:"rgba(167,139,250,0.28)",tabActiveBorder:"rgba(167,139,250,0.70)",tabActiveText:"#ffffff",tabInactiveBg:"rgba(255,255,255,0.05)",tabInactiveText:"rgba(255,255,255,0.50)",tabHoverBg:"rgba(167,139,250,0.15)",chartGrid:"rgba(255,255,255,0.10)",chartText:"rgba(255,255,255,0.55)",chartColors:["#c4b5fd","#6ee7b7","#fde68a","#fca5a5","#93c5fd"],spinnerColor:"#c4b5fd",checkboxBorder:"rgba(167,139,250,0.60)"}},Pl=[{id:"campaigns",label:"Campaigns",Icon:ee,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState([]),[n,o]=c.useState([]),[i,d]=c.useState(!0),[u,x]=c.useState(!1),[p,m]=c.useState(!1),[g,b]=c.useState(!1),[y,f]=c.useState(!1),[v,j]=c.useState(null),[N,F]=c.useState(!1),[A,R]=c.useState(null),[E,L]=c.useState(""),[D,M]=c.useState(""),[I,P]=c.useState(""),[U,O]=c.useState(""),[z,H]=c.useState(""),[q,W]=c.useState(""),[V,G]=c.useState(null),[Y,J]=c.useState(!1);c.useEffect(()=>{Q()},[]);const Q=async()=>{try{d(!0);const[e,t,s]=await Promise.all([h.from("marketing_campaigns").select("*, marketing_segments(name), email_templates(name, subject)").order("created_at",{ascending:!1}),h.from("marketing_segments").select("id, name, user_count"),h.from("email_templates").select("id, name, subject").eq("is_active",!0)]);if(e.error)throw e.error;r(e.data||[]),l(t.data||[]),o(s.data||[])}catch(e){w.error("Failed to load campaigns")}finally{d(!1)}},X=()=>{L(""),M(""),P(""),O("")}
1,Z={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${t.cardBorder}`,borderRadius:20,maxHeight:"90vh",overflowY:"auto"};return i?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Email Campaigns"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Create and manage email marketing campaigns"})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(ul,{p:t,onClick:()=>b(!0),children:[e.jsx(Je,{style:{width:13,height:13},"aria-hidden":!0})," Import Email
1s"]}),e.jsxs(k,{open:u,onOpenChange:e=>{x(e),e||X()},children:[e.jsx(_,{asChild:!0,children:e.jsxs(cl,{p:t,onClick:()=>{X(),x(!0)},children:[e.jsx(xe,{style:{width:13,height:13},"aria-hidden":!0})," Create Campaign"]})}),e.jsxs(C,{style:Z,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Create Email Campaign"}),e.jsx(S,{style:{color:t.mutedText},children:"Set up a new email campaign to reach your users"})]}),e.jsx("div",{className:"py-4",children:e.jsx(pl,{p:t,campaignName:E,setCampaignName:L,campaignDescription:D,setCampaignDescription:M,selectedSegment:I,setSelectedSegment:P,selectedTemplate:U,setSelectedTemplate:O,segments:a,templates:n})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsx(ul,{p:t,onClick:()=>x(!1),children:"Cancel"}),e.jsxs(cl,{p:t,onClick:async()=>{var e,t;if(E.trim()&&I&&U)try{f(!0);const{data:s}=await h.auth.getSession(),{error:r}=await h.from("marketing_campaigns").insert({name:E,description:D,type:"email",status:"draft",segment_id:I,template_id:U,created_by:null==(t=null==(e=null==s?void 0:s.session)?void 0:e.user)?void 0:t.id});if(r)throw r;w.success("Campaign created"),x(!1),X(),Q()}catch(s){w.error(s.message||"Failed to create campaign")}finally{f(!1)}else w.error("Please fill in all required fields")},disabled:y,children:[y?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,y?"Creating…":"Create Campaign"]})]})]})]})]})]}),e.jsx(k,{open:p,onOpenChange:e=>{m(e),e||(R(null),X())},children:e.jsxs(C,{style:Z,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Edit Campaign"}),e.jsx(S,{style:{color:t.mutedText},children:"Update campaign details"})]}),e.jsx("div",{className:"py-4",children:e.jsx(pl,{p:t,campaignName:E,setCampaignName:L,campaignDescription:D,setCampaignDescription:M,selectedSegment:I,setSelectedSegment:P,selectedTemplate:U,setSelectedTemplate:O,segments:a,templates:n})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsx(ul,{p:t,onClick:()=>m(!1),children:"Cancel"}),e.jsxs(cl,{p:t,onClick:async()=>{if(A&&E.trim())try{f(!0);const{error:e}=await h.from("marketing_campaigns").update({name:E,description:D,segment_id:I||null,template_id:U||null}).eq("id",A.id);if(e)throw e;w.success("Campaign updated"),m(!1),R(null),X(),Q()}catch(e){w.error(e.message||"Failed to update campaign")}finally{f(!1)}else w.error("Campaign name is required")},disabled:y,children:[y?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,y?"Updating…":"Update Campaign"]})]})]})}),e.jsx(k,{open:g,onOpenChange:b,children:e.jsxs(C,{style:Z,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Import Email Addresses"}),e.jsx(S,{style:{color:t.mutedText},children:"Add emails to a campaign manually. Separate with commas, semicolons, or new lines."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Select Campaign *"}),e.jsxs(il,{p:t,value:V||"",onChange:G,children:[e.jsx("option",{value:"",style:{background:"#1a0235"},children:"— Choose campaign —"}),s.map(t=>e.jsx("option",{value:t.id,style:{background:"#1a0235"},children:t.name},t.id))]})]}),e.jsxs("div",{children:[e.jsx(dl,{p:t,children:"Email Addresses *"}),e.jsx("textarea",{value:q,onChange:e=>W(e.target.value),placeholder:"[email protected], [email protected]",className:"w-full px-3 py-2.5 rounded-xl text-sm outline-none font-mono resize-y",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor,minHeight:120},onFocus:e=>{e.target.style.borderColor=t.inputFocusBorder},onBlur:e=>{e.target.style.borderColor=t.inputBorder}}),e.jsx("p",{className:"text-xs mt-1",style:{color:t.mutedText},children:"Separate emails with commas, semicolons, or new lines"})]})]}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsx(ul,{p:t,onClick:()=>b(!1),children:"Cancel"}),e.jsxs(cl,{p:t,onClick:async()=>{if(V&&q.trim())try{J(!0);const e=q.split(/[,;\n]+/).map(e=>e.trim().toLowerCase()).filter(e=>e&&e.includes("@"));if(0===e.length)return void w.error("No valid emails found");const{data:t}=await h.from("campaign_recipients").select("email").eq("campaign_id",V).in("email",e),s=new Set((t||[]).map(e=>e.email)),r=e.filter(e=>!s.has(e));if(0===r.length)return void w.error("All emails already exist in this campaign");const a=r.map(e=>({campaign_id:V,email:e,full_name:null,status:"pending"})),{error:l}=await h.from("campaign_recipients").insert(a);if(l)throw l;w.success(`Imported ${r.length} emails (${s.size} duplicates skipped)`),b(!1),W(""),G(null),Q()}catch(e){w.error(e.message||"Failed to import emails")}finally{J(!1)}else w.error("Please select a campaign and enter emails")},disabled:Y,children:[Y?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,Y?"Importing…":"Import Emails"]}
1)]})]})}),e.jsxs("div",{className:"rounded-2xl p-4 sm:p-5",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsx("p",{className:"text-sm font-semibold mb-3",style:{color:t.headlineColor},children:"Quick Test Email"}),e.jsxs("div",{className:"flex gap-2 max-w-md",children:[e.jsx(nl,{p:t,value:z,onChange:e=>H(e.target.value),placeholder:"Enter your email for testing…",type:"email",style:{flex:1},"aria-label":"Test email address"}),e.jsxs(cl,{p:t,onClick:async()=>{var e,t,r;if(z.trim())try{F(!0);const a=await h.functions.invoke("send-marketing-email",{body:{campaign_id:null==(e=s[0])?void 0:e.id,test_email:z,is_test:!0}});if(a.error)throw new Error(a.error.message);if(!(null==(t=a.data)?void 0:t.success))throw new Error((null==(r=a.data)?void 0:r.error)||"Email sending failed");w.success(`Test email sent to ${z}!`)}catch(a){w.error(`Failed: ${a.message}`)}finally{F(!1)}else w.error("Enter a test email address")},disabled:N||!z.trim()||0===s.length,children:[N?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):e.jsx(Qe,{style:{width:13,height:13},"aria-hidden":!0}),N?"Sending…":"Send Test"]})]}),0===s.length&&e.jsx("p",{className:"text-xs mt-2",style:{color:t.mutedText},children:"Create a campaign with a template first to test emails"})]}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:{background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`},children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:t.headlineColor},children:"All Campaigns"}),e.jsx("button",{type:"button",onClick:Q,className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{color:t.mutedText},"aria-label":"Refresh campaigns",children:e.jsx(re,{style:{width:13,height:13},"aria-hidden":!0})})]}),e.jsxs("div",{className:"grid gap-3 px-4 py-2.5 text-xs font-bold uppercase tracking-wider",style:{gridTemplateColumns:"2fr 1.5fr 1fr 1.5fr auto",background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`,color:t.labelText},children:[e.jsx("span",{children:"Campaign"}),e.jsx("span",{children:"Segment"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Metrics"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),0===s.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-14",children:[e.jsx(Qe,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No campaigns created yet"})]}):s.map((r,a)=>{var l,n,o,i;return e.jsxs("div",{className:"grid gap-3 px-4 py-3.5 items-center transition-all",style:{gridTemplateColumns:"2fr 1.5fr 1fr 1.5fr auto",borderBottom:a<s.length-1?`1px solid ${t.tableBorder}`:"none"},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",style:{color:t.headlineColor},children:r.name}),e.jsx("p",{className:"text-xs truncate mt-0.5",style:{color:t.mutedText},children:(null==(l=r.email_templates)?void 0:l.subject)||"No template"})]}),e.jsx("span",{className:"text-sm truncate",style:{color:t.bodyText},children:(null==(n=r.marketing_segments)?void 0:n.name)||"—"}),e.jsx(xl,{status:r.status,p:t}),e.jsxs("div",{className:"text-xs",style:{color:t.mutedText},children:[e.jsx("span",{style:{color:t.bodyText},children:(null==(o=r.metrics)?void 0:o.sent)||0})," sent ·"," ",e.jsx("span",{style:{color:t.accentText},children:(null==(i=r.metrics)?void 0:i.opened)||0})," opened"]}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>(e=>{R(e),L(e.name),M(e.description||""),P(e.segment_id||""),O(e.template_id||""),m(!0)})(r),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.pillBg,border:`1px solid ${t.pillBorder}`},"aria-label":"Edit campaign",children:e.jsx(qe,{style:{width:11,height:11,color:t.pillText},"aria-hidden":!0})}),"draft"===r.status&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>(async e=>{var t,s;if(z.trim())try{j(e);const r=await h.functions.invoke("send-marketing-email",{body:{campaign_id:e,test_email:z,is_test:!0}});if(r.error)throw new Error(r.error.message);if(!(null==(t=r.data)?void 0:t.success))throw new Error((null==(s=r.data)?void 0:s.error)||"Email sending failed");w.success(`Test email sent to ${z}!`)}catch(r){w.error(`Failed: ${r.message}`)}finally{j(null)}else w.error("Enter a test email address")})(r.id),disabled:!z.trim()||v===r.id,className:"p-1.5 rounded-lg transition-all hover:opacity-80 disabled:opacity-40",style:{background:t.infoBg,border:`1px solid ${t.infoBorder}`}
1,"aria-label":"Send test email",children:v===r.id?e.jsx(K,{style:{width:11,height:11,color:t.infoText},className:"animate-spin"}):e.jsx(Xe,{style:{width:11,height:11,color:t.infoText}})}),e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{if(confirm("Are you sure you want to launch this campaign? Emails will be sent to all users in the segment."))try{j(e);const s=await h.functions.invoke("calculate-segment-users",{body:{segment_id:t,preview_only:!1}});if(s.error)throw s.error;const r=s.data.users||[];if(0===r.length)return void w.error("No users in segment to send to");const a=r.map(t=>({campaign_id:e,user_id:t.user_id,email:t.email,full_name:t.full_name,status:"pending"})),{error:l}=await h.from("campaign_recipients").insert(a);if(l)throw l;const n=await h.functions.invoke("send-marketing-email",{body:{campaign_id:e}});if(n.error)throw n.error;w.success(`Campaign launched! Sent to ${n.data.sent} recipients`),Q()}catch(s){w.error(s.message||"Failed to launch campaign")}finally{j(null)}})(r.id,r.segment_id),disabled:v===r.id,className:"p-1.5 rounded-lg transition-all hover:opacity-80 disabled:opacity-40",style:{background:t.successBg,border:`1px solid ${t.successBorder}`},"aria-label":"Launch campaign",children:v===r.id?e.jsx(K,{style:{width:11,height:11,color:t.successText},className:"animate-spin"}):e.jsx(je,{style:{width:11,height:11,color:t.successText}})})]}),"active"===r.status&&e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{try{const{error:s}=await h.from("marketing_campaigns").update({status:t}).eq("id",e);if(s)throw s;w.success(`Campaign ${t}`),Q()}catch(s){w.error(s.message||"Failed to update campaign")}})(r.id,"paused"),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.warningBg,border:`1px solid ${t.warningBorder}`},"aria-label":"Pause campaign",children:e.jsx(ve,{style:{width:11,height:11,color:t.warningText},"aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm("Are you sure you want to delete this campaign?"))try{const{error:t}=await h.from("marketing_campaigns").delete().eq("id",e);if(t)throw t;w.success("Campaign deleted"),Q()}catch(t){w.error(t.message||"Failed to delete campaign")}})(r.id),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`},"aria-label":"Delete campaign",children:e.jsx(ge,{style:{width:11,height:11,color:t.dangerText},"aria-hidden":!0})})]})]},r.id)})]})]})}},{id:"segments",label:"Segments",Icon:ce,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState(!1),[i,d]=c.useState(!1),[u,x]=c.useState(!1),[p,m]=c.useState(!1),[g,b]=c.useState(!1),[y,f]=c.useState(null),[v,j]=c.useState(""),[N,$]=c.useState(""),[F,A]=c.useState(el),[R,E]=c.useState([]),[L,D]=c.useState(0),[M,I]=c.useState(!1),[P,U]=c.useState([]),[O,z]=c.useState([]),[H,q]=c.useState(!1),[W,V]=c.useState("");c.useEffect(()=>{Y()},[]);const Y=async()=>{try{l(!0);const{data:e,error:t}=await h.from("marketing_segments").select("*").order("created_at",{ascending:!1});if(t)throw t;r(e||[])}catch{w.error("Failed to load segments")}finally{l(!1)}},Q=async()=>{try{q(!0);const{data:e,error:t}=await h.from("profiles").select("user_id, email, full_name, years_of_experience, credits").eq("is_blocked",!1).order("full_name",{ascending:!0});if(t)throw t;z(e||[])}catch{w.error("Failed to load users")}finally{q(!1)}},X=()=>{j(""),$(""),A(el),E([]),D(0),I(!1),U([]),V("")},Z=()=>M?{manual_user_ids:P}:{experience_levels:F.experience_levels.length>0?F.experience_levels:void 0,countries:F.countries.length>0?F.countries:void 0,signup_date_from:F.signup_date_from||void 0,signup_date_to:F.signup_date_to||void 0,min_credits:F.min_credits?parseInt(F.min_credits):void 0,max_credits:F.max_credits?parseInt(F.max_credits):void 0,has_completed_interview:F.has_completed_interview||void 0,min_interviews:F.min_interviews?parseInt(F.min_interviews):void 0,has_purchased:F.has_purchased||void 0,inactive_days:F.inactive_days?parseInt(F.inactive_days):void 0,email_contains:F.email_contains||void 0},ee=async()=>{try{b(!0);const e=M&&P.length>0?{filter_criteria:{manual_user_ids:P},preview_only:!0}:{filter_criteria:Z(),preview_only:!0},t=await h.functions.invoke("calculate-segment-users",{body:e});if(t.error)throw t.error;E(t.data.users||[]),D(t.data.eligible_count||0),d(!0)}catch(e){w.error(e.message||"Failed to calculate segment")}finally{b(!1)}},te=e=>U(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),se=O.filter(e=>{var t,s;if(!W)return!0;const r=W.toLowerCase();return(null==(t=e.email)?void 0:t.toLowerCase().includes(r))||(null==(s=e.full_name)?void 0:s.toLowerCase().includes(r))}),ae=()=>{const e=se.map(e=>e.user_id),t=e.every(e=>P.includes(e));U(t?P.filter(t=>!e.includes(t)):[...new Set([...P,...e])])},le=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Experience Level"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Xa.map(s=>{const r=F.experience_levels.includes(s.value);return e.jsx("button",{type:"button",onClick:()=>{return e=s.value,A(t=>({...t,experience_levels:t.experience_levels.includes(e)?t.experience_levels.filter(t=>t!==e):[...t.experience_levels,e]}));var e},className:"px-2.5 py-1 rounded-lg text-xs font-semibold transition-all",style:{background:r?t.pillBg:t.cardBg,border:`1px solid ${r?t.pillBorder:t.cardBorder}`,color:r?t.pillText:t.mutedText},children:s.label},s.value)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Signup From"}),e.jsx(tl,{p:t,type:"date",value:F.signup_date_from,onChange:e=>A({...F,signup_date_from:e.target.value})})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Signup To"}),e.jsx(tl,{p:t,type:"date",value:F.signup_date_to,onChange:e=>A({...F,signup_date_to:e.target.value})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Min Credits"}),e.jsx(tl,{p:t,type:"number",value:F.min_credits,onChange:e=>A({...F,min_credits:e.target.value}),placeholder:"0"})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Max Credits"}),e.jsx(tl,{p:t,type:"number",value:F.max_credits,onChange:e=>A({...F,max_credits:e.target.value}),placeholder:"100"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Min Interviews"}),e.jsx(tl,{p:t,type:"number",value:F.min_interviews,onChange:e=>A({...F,min_interviews:e.target.value}),placeholder:"0"})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Inactive Days"}),e.jsx(tl,{p:t,type:"number",value:F.inactive_days,onChange:e=>A({...F,inactive_days:e.target.value}),placeholder:"30"})]})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Email Contains"}),e.jsx(tl,{p:t,value:F.email_contains,onChange:e=>A({...F,email_contains:e.target.value}),placeholder:"@gmail.com"})]}),e.jsx("div",{className:"flex gap-4 flex-wrap",children:[{key:"has_completed_interview",label:"Has completed interview"},{key:"has_purchased",label:"Has made purchase"}].map(({key:s,label:r})=>{const a=F[s];return e.jsxs("button",{type:"button",onClick:()=>A({...F,[s]:!a}),className:"flex items-center gap-2 text-sm transition-all",style:{color:a?t.successText:t.mutedText},children:[a?e.jsx(Ke,{style:{width:15,height:15},"aria-hidden":!0}):e.jsx(Ye,{style:{width:15,height:15},"aria-hidden":!0}),r]},s)})})]}),ne=()=>e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(G,{style:{width:13,height:13,position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:t.mutedText},"aria-hidden":!0}),e.jsx(tl,{p:t,value:W,onChange:e=>V(e.target.value),placeholder:"Search by name or email…",style:{paddingLeft:34},"aria-label":"Search users"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs",style:{color:t.mutedText},children:[e.jsx("span",{className:"font-bold",style:{color:t.accentText},children:P.length})," ","users selected"]}),e.jsx("button",{type:"button",onClick:ae,className:"text-xs px-2.5 py-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.btnOutlineBg,border:`1px solid ${t.btnOutlineBorder}`,color:t.btnOutlineText},children:"Toggle All Visible"})]}),H?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`,maxHeight:280,overflowY:"auto"},children:[se.slice(0,100).map((s,r)=>
1{const a=P.includes(s.user_id);return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 cursor-pointer transition-all",style:{borderBottom:r<Math.min(se.length,100)-1?`1px solid ${t.tableBorder}`:"none",background:a?t.tableRowSelected:"transparent"},onClick:()=>te(s.user_id),role:"checkbox","aria-checked":a,tabIndex:0,onKeyDown:e=>"Enter"===e.key&&te(s.user_id),children:[e.jsx("div",{className:"w-4 h-4 rounded flex items-center justify-center flex-shrink-0",style:{background:a?t.accentText:"transparent",border:`1.5px solid ${a?t.accentText:t.inputBorder}`},children:a&&e.jsx("span",{style:{color:"#fff",fontSize:10,fontWeight:700},children:"✓"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",style:{color:t.headlineColor},children:s.full_name||"N/A"}),e.jsx("p",{className:"text-xs truncate",style:{color:t.mutedText},children:s.email})]}),e.jsx("span",{className:"text-xs flex-shrink-0",style:{color:t.mutedText},children:s.years_of_experience||"—"})]},s.user_id)}),0===se.length&&e.jsx("div",{className:"py-8 text-center text-sm",style:{color:t.mutedText},children:W?"No users match your search":"No users available"})]}),se.length>100&&e.jsxs("p",{className:"text-xs text-center",style:{color:t.mutedText},children:["Showing 100 of ",se.length,". Use search to narrow results."]})]}),oe=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(rl,{p:t,children:"Selection Mode"}),e.jsx("div",{className:"flex gap-1.5",children:[{label:"Filter-based",manual:!1},{label:"Manual",manual:!0,icon:Re}].map(({label:s,manual:r,icon:a})=>{const l=M===r;return e.jsxs("button",{type:"button",onClick:()=>{I(r),r&&0===O.length&&Q()},className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-semibold transition-all",style:{background:l?t.pillBg:t.cardBg,border:`1px solid ${l?t.pillBorder:t.cardBorder}`,color:l?t.pillText:t.mutedText},children:[a&&e.jsx(a,{style:{width:11,height:11},"aria-hidden":!0}),s]},s)})})]}),M?e.jsx(ne,{}):e.jsx(le,{})]}),ie=({onSave:s,onCancel:r,saveLabel:a})=>e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-2 flex-wrap",children:[e.jsxs(ll,{p:t,onClick:ee,disabled:g||M&&0===P.length,children:[g?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):e.jsx(Me,{style:{width:13,height:13}}),M?`Preview (${P.length})`:`Preview (${L} users)`]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ll,{p:t,onClick:r,children:"Cancel"}),e.jsxs(al,{p:t,onClick:s,disabled:p||!v.trim()||M&&0===P.length,children:[p?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):e.jsx(J,{style:{width:13,height:13}}),p?"Saving…":a]})]})]}),de={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${t.cardBorder}`,borderRadius:20,maxHeight:"92vh",overflowY:"auto"};return a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"User Segments"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Create dynamic user segments for targeted campaigns"})]}),e.jsxs(k,{open:n,onOpenChange:e=>{o(e),e||X()},children:[e.jsx(_,{asChild:!0,children:e.jsxs(al,{p:t,onClick:()=>{X(),o(!0)},children:[e.jsx(xe,{style:{width:13,height:13},"aria-hidden":!0})," Create Segment"]})}),e.jsxs(C,{style:de,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Create User Segment"}),e.jsx(S,{style:{color:t.mutedText},children:"Filter users or manually select for targeted campaigns"})]}),e.jsxs("div",{className:"space-y-5 py-4",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Segment Name *"}
1),e.jsx(tl,{p:t,value:v,onChange:e=>j(e.target.value),placeholder:"e.g., Active Premium Users"})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Description"}),e.jsx(sl,{p:t,value:N,onChange:e=>$(e.target.value),placeholder:"Describe this segment…"})]}),e.jsx("div",{style:{paddingTop:4,borderTop:`1px solid ${t.divider}`},children:e.jsx(oe,{})})]}),e.jsx(ie,{onSave:async()=>{var e,t;if(v.trim())if(M&&0===P.length)w.error("Please select at least one user");else try{m(!0);const{data:s}=await h.auth.getSession(),{error:r}=await h.from("marketing_segments").insert({name:v,description:N,filter_criteria:Z(),user_count:M?P.length:L,is_dynamic:!M,created_by:null==(t=null==(e=null==s?void 0:s.session)?void 0:e.user)?void 0:t.id});if(r)throw r;w.success("Segment created"),o(!1),X(),Y()}catch(s){w.error(s.message||"Failed to save segment")}finally{m(!1)}else w.error("Segment name is required")},onCancel:()=>o(!1),saveLabel:"Save Segment"})]})]})]}),e.jsx(k,{open:u,onOpenChange:e=>{x(e),e||(f(null),X())},children:e.jsxs(C,{style:de,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Edit Segment"}),e.jsx(S,{style:{color:t.mutedText},children:"Update segment filters and details"})]}),e.jsxs("div",{className:"space-y-5 py-4",children:[e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Segment Name *"}),e.jsx(tl,{p:t,value:v,onChange:e=>j(e.target.value),placeholder:"e.g., Active Premium Users"})]}),e.jsxs("div",{children:[e.jsx(rl,{p:t,children:"Description"}),e.jsx(sl,{p:t,value:N,onChange:e=>$(e.target.value),placeholder:"Describe this segment…"})]}),e.jsx("div",{style:{paddingTop:4,borderTop:`1px solid ${t.divider}`},children:e.jsx(oe,{})})]}),e.jsx(ie,{onSave:async()=>{if(y&&v.trim())if(M&&0===P.length)w.error("Please select at least one user");else try{m(!0);const{error:e}=await h.from("marketing_segments").update({name:v,description:N,filter_criteria:Z(),user_count:M?P.length:L,is_dynamic:!M}).eq("id",y.id);if(e)throw e;w.success("Segment updated"),x(!1),f(null),X(),Y()}catch(e){w.error(e.message||"Failed to update segment")}finally{m(!1)}else w.error("Segment name is required")},onCancel:()=>x(!1),saveLabel:"Update Segment"})]})}),e.jsx(k,{open:i,onOpenChange:d,children:e.jsxs(C,{style:de,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Segment Preview"}),e.jsxs(S,{style:{color:t.mutedText},children:["First 10 of ",L," matching users"]})]}),e.jsx("div",{className:"rounded-xl overflow-hidden mt-2",style:{border:`1px solid ${t.cardBorder}`},children:0===R.length?e.jsx("div",{className:"py-8 text-center text-sm",style:{color:t.mutedText},children:"No users match the current criteria"}):R.map((s,r)=>e.jsxs("div",{className:"grid gap-3 px-4 py-3 text-sm",style:{gridTemplateColumns:"2fr 2fr 1fr 1fr",borderBottom:r<R.length-1?`1px solid ${t.tableBorder}`:"none",color:t.bodyText},children:[e.jsx("span",{style:{color:t.headlineColor},children:s.full_name||"N/A"}),e.jsx("span",{children:s.email}),e.jsx("span",{style:{color:t.mutedText},children:s.years_of_experience||"N/A"}),e.jsxs("span",{style:{color:t.accentText},children:[s.credits," cr"]})]},s.user_id))})]})}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"grid gap-3 px-4 py-3 text-xs font-bold uppercase tracking-wider",style:{gridTemplateColumns:"2fr 1fr 1fr 1.2fr auto",background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`,color:t.labelText},children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"}),e.jsx("span",{children:"Users"}),e.jsx("span",{children:"Created"}),e.jsx("span",{})]}),0===s.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-14",children:[e.jsx(ce,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No segments created yet"})]}):s.map((r,a)=>e.jsxs("div",{className:"grid gap-3 px-4 py-3.5 items-center transition-all",style:{gridTemplateColumns:"2fr 1fr 1fr 1.2fr auto",borderBottom:a<s.length-1?`1px solid ${t.tableBorder}`:"none"},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",style:{color:t.headlineColor},children:r.name}),r.description&&e.jsx("p",{className:"text-xs truncate mt-0.5",style:{color:t.mutedText},children:r.description})]}),e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-full text-xs font-semibold w-fit",style:{background:r.is_dynamic?t.successBg:t.pillBg,border:`1px solid ${r.is_dynamic?t.successBorder:t.pillBorder}`,color:r.is_dynamic?t.successText:t.pillText},children:r.is_dynamic?"Dynamic":"Manual"}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold",style:{color:t.accentText},children:[e.jsx(ce,{style:{width:11,height:11},"aria-hidden":!0}),r.user_count]}),e.jsx("span",{className:"text-xs",style:{color:t.mutedText},children:St(new Date(r.created_at),"MMM dd, yyyy")}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>(e=>{var t,s,r,a;f(e),j(e.name),$(e.description||"");const l=e.filter_criteria;var n;l.manual_user_ids&&Array.isArray(l.manual_user_ids)?(I(!0),U(l.manual_user_ids),0===O.length&&Q()):(I(!1),A({experience_levels:(n=l.experience_levels,Array.isArray(n)?n.filter(e=>"string"==typeof e).map(e=>
1Za[e]??e).filter(Boolean):[]),countries:l.countries||[],signup_date_from:l.signup_date_from||"",signup_date_to:l.signup_date_to||"",min_credits:(null==(t=l.min_credits)?void 0:t.toString())||"",max_credits:(null==(s=l.max_credits)?void 0:s.toString())||"",has_completed_interview:l.has_completed_interview||!1,min_interviews:(null==(r=l.min_interviews)?void 0:r.toString())||"",has_purchased:l.has_purchased||!1,inactive_days:(null==(a=l.inactive_days)?void 0:a.toString())||"",email_contains:l.email_contains||""})),D(e.user_count),x(!0)})(r),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.pillBg,border:`1px solid ${t.pillBorder}`},"aria-label":"Edit segment",children:e.jsx(qe,{style:{width:11,height:11,color:t.pillText},"aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:()=>(async e=>{const{data:t,error:s}=await h.from("marketing_campaigns").select("id, name").eq("segment_id",e);if(s)throw s;if((null==t?void 0:t.length)>0)w.error(`Cannot delete segment. Used by ${t.length} campaign(s): ${t.map(e=>e.name).join(", ")}`);else if(confirm("Are you sure you want to delete this segment?"))try{const{error:t}=await h.from("marketing_segments").delete().eq("id",e);if(t)throw t;w.success("Segment deleted"),Y()}catch(r){w.error(r.message||"Failed to delete segment")}})(r.id),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`},"aria-label":"Delete segment",children:e.jsx(ge,{style:{width:11,height:11,color:t.dangerText},"aria-hidden":!0})})]})]},r.id))]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"button",onClick:Y,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs transition-all hover:opacity-80",style:{color:t.mutedText},onMouseEnter:e=>{e.currentTarget.style.background=t.btnGhostHoverBg},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsx(re,{style:{width:11,height:11},"aria-hidden":!0})," Refresh"]})})]})}},{id:"templates",label:"Templates",Icon:Q,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState(!1),[i,d]=c.useState(!1),[u,x]=c.useState(!1),[p,m]=c.useState(!1),[g,b]=c.useState(null),[y,f]=c.useState(""),[v,j]=c.useState(""),[N,F]=c.useState(hl),[A,R]=c.useState("general"),[E,L]=c.useState("");c.useEffect(()=>{D()},[]);const D=async()=>{try{l(!0);const{data:e,error:t}=await h.from("email_templates").select("*").order("created_at",{ascending:!1});if(t)throw t;r(e||[])}catch(e){w.error("Failed to load templates")}finally{l(!1)}},M=()=>{f(""),j(""),F(hl),R("general")},I=()=>{const e=N.replace(/\{\{full_name\}\}/g,"John Doe").replace(/\{\{email\}\}/g,"[email protected]").replace(/\{\{credits\}\}/g,"50").replace(/\{\{unsubscribe_link\}\}/g,"#").replace(/\{\{subject\}\}/g,v);L(e),d(!0)},P={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${t.cardBorder}`,borderRadius:20,maxHeight:"92vh",overflowY:"auto",maxWidth:860};return a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Email Templates"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Create reusable email templates with personalization"})]}),e.jsxs(k,{open:n,onOpenChange:e=>{o(e),e||M()},children:[e.jsx(_,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:()=>{M(),o(!0)},className:"inline-flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 active:scale-95",style:{background:t.btnPrimaryBg,color:t.btnPrimaryText},children:[e.jsx(xe,{style:{width:13,height:13},"aria-hidden":!0}),"Create Template"]})}),e.jsxs(C,{style:P,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Create Email Template"}),e.jsx(S,{style:{color:t.mutedText},children:"Design an email template with personalization variables"})]}),e.jsx("div",{className:"py-4",children:e.jsx(vl,{p:t,templateName:y,setTemplateName:f,templateSubject:v,setTemplateSubject:j,templateHtml:N,setTemplateHtml:F,templateCategory:A,setTemplateCategory:R})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsxs(fl,{p:t,onClick:I,className:"px-3 py-2 text-sm",children:[e.jsx(Me,{style:{width:13,height:13},"aria-hidden":!0})," Preview"]}),e.jsxs(yl,{p:t,onClick:async()=>{var e,t;if(y.trim()&&v.trim()&&N.trim())try{x(!0);const{data:s}=await h.auth.getSession(),{error:r}=await h.from("email_templates").insert({name:y,subject:v,html_content:N,category:A,created_by:null==(t=null==(e=null==s?void 0:s.session)?void 0:e.user)?void 0:t.id});if(r)throw r;w.success("Template saved"),o(!1),M(),D()}catch(s){w.error(s.message||"Failed to save template")}finally{x(!1)}else w.error("Please fill in all required fields")},disabled:u,children:[u?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,u?"Saving…":"Save Template"]})]})]})]})]}),e.jsx(k,{open:p,onOpenChange:e=>{m(e),e||(b(null),M())},children:e.jsxs(C,{style:P,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Edit Email Template"}),e.jsx(S,{style:{color:t.mutedText},children:"Update template content and settings"})]}),e.jsx("div",{className:"py-4",children:e.jsx(vl,{p:t,templateName:y,setTemplateName:f,templateSubject:v,setTemplateSubject:j,templateHtml:N,setTemplateHtml:F,templateCategory:A,setTemplateCategory:R})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsxs(fl,{p:t,onClick:I,className:"px-3 py-2 text-sm",children:[e.jsx(Me,{style:{width:13,height:13},"aria-hidden":!0})," Preview"]}),e.jsxs(yl,{p:t,onClick:async()=>
1{if(g&&y.trim()&&v.trim()&&N.trim())try{x(!0);const{error:e}=await h.from("email_templates").update({name:y,subject:v,html_content:N,category:A}).eq("id",g.id);if(e)throw e;w.success("Template updated"),m(!1),b(null),M(),D()}catch(e){w.error(e.message||"Failed to update template")}finally{x(!1)}else w.error("Please fill in all required fields")},disabled:u,children:[u?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,u?"Updating…":"Update Template"]})]})]})}),e.jsx(k,{open:i,onOpenChange:d,children:e.jsxs(C,{style:{...P,background:"#ffffff",maxHeight:"80vh"},children:[e.jsx(B,{children:e.jsx(T,{style:{color:"#111"},children:"Template Preview"})}),e.jsx("div",{className:"border rounded-lg p-4 bg-white",dangerouslySetInnerHTML:{__html:E}})]})}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"grid gap-3 px-4 py-3 text-xs font-bold uppercase tracking-wider",style:{gridTemplateColumns:"2fr 2fr 1fr 1fr auto",background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`,color:t.labelText},children:[e.jsx("span",{children:"Template"}),e.jsx("span",{children:"Subject"}),e.jsx("span",{children:"Category"}),e.jsx("span",{children:"Status"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),0===s.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-14",children:[e.jsx(Q,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No templates created yet"})]}):s.map((r,a)=>e.jsxs("div",{className:"grid gap-3 px-4 py-3.5 items-center transition-all",style:{gridTemplateColumns:"2fr 2fr 1fr 1fr auto",borderBottom:a<s.length-1?`1px solid ${t.tableBorder}`:"none"},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsx("span",{className:"font-semibold text-sm truncate",style:{color:t.headlineColor},children:r.name}),e.jsx("span",{className:"text-xs truncate",style:{color:t.bodyText},children:r.subject}),e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-lg text-xs font-medium w-fit",style:{background:t.pillBg,border:`1px solid ${t.pillBorder}`,color:t.pillText},children:r.category}),e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-full text-xs font-semibold w-fit",style:{background:r.is_active?t.successBg:t.cardBg,border:`1px solid ${r.is_active?t.successBorder:t.cardBorder}`,color:r.is_active?t.successText:t.mutedText},children:r.is_active?"Active":"Inactive"}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>(e=>{b(e),f(e.name),j(e.subject),F(e.html_content),R(e.category),m(!0)})(r),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.pillBg,border:`1px solid ${t.pillBorder}`},"aria-label":"Edit template",children:e.jsx(qe,{style:{width:11,height:11,color:t.pillText},"aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:()=>(async(e,t)=>{try{const{error:s}=await h.from("email_templates").update({is_active:!t}).eq("id",e);if(s)throw s;w.success("Template "+(t?"deactivated":"activated")),D()}catch(s){w.error(s.message||"Failed to update template")}})(r.id,r.is_active),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:r.is_active?t.warningBg:t.successBg,border:`1px solid ${r.is_active?t.warningBorder:t.successBorder}`},"aria-label":r.is_active?"Deactivate template":"Activate template",children:r.is_active?e.jsx(Ze,{style:{width:11,height:11,color:t.warningText},"aria-hidden":!0}):e.jsx(et,{style:{width:11,height:11,color:t.successText},"aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm("Are you sure you want to delete this template?"))try{const{error:t}=await h.from("email_templates").delete().eq("id",e);if(t)throw t;w.success("Template deleted"),D()}catch(t){w.error(t.message||"Failed to delete template")}})(r.id),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`},"aria-label":"Delete template",children:e.jsx(ge,{style:{width:11,height:11,color:t.dangerText},"aria-hidden":!0})})]})]},r.id))]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"button",onClick:D,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs transition-all hover:opacity-80",style:{color:t.mutedText},onMouseEnter:e=>{e.currentTarget.style.background=t.btnGhostHoverBg},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsx(re,{style:{width:11,height:11},"aria-hidden":!0}),"Refresh"]})})]})}},{id:"workflows",label:"Workflows",Icon:st,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState(!1),[i,d]=c.useState(!1),[u,x]=c.useState(!1),[p,m]=c.useState(null),[g,b]=c.useState(""),[y,f]=c.useState(""),[v,j]=c.useState("signup"),[N,F]=c.useState([]);c.useEffect(()=>{A()},[]);const A=async()=>{try{l(!0);const{data:e,error:t}=await h.from("marketing_workflows").select("*").order("created_at",{ascending:!1});if(t)throw t;r(e||[])}
1catch(e){w.error("Failed to load workflows")}finally{l(!1)}},R=e=>{F([...N,{id:crypto.randomUUID(),type:e,config:"delay"===e?{minutes:60}:{action:"send_email",template_id:""}}])},E=(e,t)=>F(N.map(s=>s.id===e?{...s,config:{...s.config,...t}}:s)),L=e=>F(N.filter(t=>t.id!==e)),D=()=>{b(""),f(""),j("signup"),F([])},M=async(e,t)=>{try{const{error:s}=await h.from("marketing_workflows").update({status:t}).eq("id",e);if(s)throw s;w.success(`Workflow ${t}`),A()}catch(s){w.error(s.message||"Failed to update workflow")}},I={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${t.cardBorder}`,borderRadius:20,maxHeight:"90vh",overflowY:"auto"};return a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Marketing Workflows"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Automated marketing sequences triggered by user actions"})]}),e.jsxs(k,{open:n,onOpenChange:e=>{o(e),e||D()},children:[e.jsx(_,{asChild:!0,children:e.jsxs(_l,{p:t,onClick:()=>{D(),o(!0)},children:[e.jsx(xe,{style:{width:14,height:14},"aria-hidden":!0}),"Create Workflow"]})}),e.jsxs(C,{style:I,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Create Marketing Workflow"}),e.jsx(S,{style:{color:t.mutedText},children:"Define triggers and actions for automated marketing"})]}),e.jsx("div",{className:"py-4",children:e.jsx($l,{p:t,workflowName:g,setWorkflowName:b,workflowDescription:y,setWorkflowDescription:f,triggerType:v,setTriggerType:j,steps:N,onAddStep:R,onUpdateStep:E,onRemoveStep:L})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsx(Cl,{p:t,onClick:()=>o(!1),children:"Cancel"}),e.jsxs(_l,{p:t,onClick:async()=>{var e,t;if(g.trim())if(0!==N.length)try{d(!0);const{data:s}=await h.auth.getSession(),{error:r}=await h.from("marketing_workflows").insert({name:g,description:y,trigger_type:v,trigger_config:{},workflow_steps:N,created_by:null==(t=null==(e=null==s?void 0:s.session)?void 0:e.user)?void 0:t.id});if(r)throw r;w.success("Workflow created"),o(!1),D(),A()}catch(s){w.error(s.message||"Failed to save workflow")}finally{d(!1)}else w.error("Add at least one step to the workflow");else w.error("Workflow name is required")},disabled:i,children:[i?e.jsx(K,{style:{width:14,height:14},className:"animate-spin"}):null,i?"Saving…":"Save Workflow"]})]})]})]})]}),e.jsx(k,{open:u,onOpenChange:e=>{x(e),e||(m(null),D())},children:e.jsxs(C,{style:I,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Edit Workflow"}),e.jsx(S,{style:{color:t.mutedText},children:"Update triggers and actions"})]}),e.jsx("div",{className:"py-4",children:e.jsx($l,{p:t,workflowName:g,setWorkflowName:b,workflowDescription:y,setWorkflowDescription:f,triggerType:v,setTriggerType:j,steps:N,onAddStep:R,onUpdateStep:E,onRemoveStep:L})}),e.jsxs($,{className:"gap-2 pt-2",children:[e.jsx(Cl,{p:t,onClick:()=>x(!1),children:"Cancel"}),e.jsxs(_l,{p:t,onClick:async()=>{if(p&&g.trim())try{d(!0);const{error:e}=await h.from("marketing_workflows").update({name:g,description:y,trigger_type:v,workflow_steps:N}).eq("id",p.id);if(e)throw e;w.success("Workflow updated"),x(!1),m(null),D(),A()}catch(e){w.error(e.message||"Failed to update workflow")}finally{d(!1)}else w.error("Workflow name is required")},disabled:i,children:[i?e.jsx(K,{style:{width:14,height:14},className:"animate-spin"}):null,i?"Updating…":"Update Workflow"]})]})]})}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"grid gap-3 px-4 py-3 text-xs font-bold uppercase tracking-wider",style:{gridTemplateColumns:"2fr 1fr 1fr 1fr auto",background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`,color:t.labelText},children:[e.jsx("span",{children:"Workflow"}),e.jsx("span",{children:"Trigger"}),e.jsx("span",{children:"Steps"}),e.jsx("span",{children:"Status"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),0===s.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-16 text-center",children:[e.jsx(st,{style:{width:36,height:36,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No workflows created yet"}),e.jsxs(Cl,{p:t,onClick:()=>{D(),o(!0)},children:[e.jsx(xe,{style:{width:13,height:13}}),"Create your first workflow"]})]}):s.map((r,a)=>{var l,n,o;return e.jsxs("div",{className:"grid gap-3 px-4 py-3.5 items-center transition-all",style:{gridTemplateColumns:"2fr 1fr 1fr 1fr auto",borderBottom:a<s.length-1?`1px solid ${t.tableBorder}`:"none",color:t.bodyText},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",style:{color:t.headlineColor},children:r.name}),r.description&&e.jsx("p",{className:"text-xs mt-0.5 truncate",style:{color:t.mutedText},children:r.description})]}),e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-lg text-xs font-medium w-fit",style:{background:t.pillBg,border:`1px solid ${t.pillBorder}`,color:t.pillText},children:(null==(l=jl.find(e=>e.value===r.trigger_type))?void 0:l.label)||r.trigger_type}),e.jsxs("span",{className:"text-sm",style:{color:t.mutedText},children:[(null==(n=r.workflow_steps)?void 0:n.length)||0," step",1!==(null==(o=r.workflow_steps)?void 0:o.length)?"s":""]}),e.jsx(Tl,{status:r.status,p:t}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:["draft"===r.status&&e.jsx("button",{type:"button",onClick:()=>M(r.id,"active"),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.successBg,border:`1px solid ${t.successBorder}`},"aria-label":"Activate workflow",children:e.jsx(je,{style:{width:12,height:12,color:t.successText}})}),"active"===r.status&&e.jsx("button",{type:"button",onClick:()=>M(r.id,"paused"),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.warningBg,border:`1px solid ${t.warningBorder}`},"aria-label":"Pause workflow",children:e.jsx(ve,{style:{width:12,height:12,color:t.warningText}})}),e.jsx(Bl,{p:t,onClick:()=>(e=>{m(e),b(e.name),f(e.description||""),j(e.trigger_type),F(e.workflow_steps||[]),x(!0)})(r),"aria-label":"Edit workflow",children:e.jsx(qe,{style:{width:12,height:12}})}),e.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm("Are you sure you want to delete this workflow?"))try{const{error:t}=await h.from("marketing_workflows").delete().eq("id",e);if(t)throw t;w.success("Workflow deleted"),A()}catch(t){w.error(t.message||"Failed to delete workflow")}})(r.id),className:"p-1.5 rounded-lg transition-all hover:opacity-80",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`},"aria-label":"Delete workflow",children:e.jsx(ge,{style:{width:12,height:12,color:t.dangerText}}
1)})]})]},r.id)})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(Bl,{p:t,onClick:A,children:[e.jsx(re,{style:{width:12,height:12},"aria-hidden":!0}),"Refresh"]})})]})}},{id:"analytics",label:"Analytics",Icon:Le,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState({sent:0,delivered:0,opened:0,clicked:0,bounced:0});c.useEffect(()=>{i()},[]);const i=async()=>{try{l(!0);const{data:e,error:t}=await h.from("marketing_campaigns").select("id, name, status, metrics").not("metrics","is",null).order("created_at",{ascending:!1});if(t)throw t;const s=e||[];r(s);const a=s.reduce((e,t)=>{var s,r,a,l,n;return{sent:e.sent+((null==(s=t.metrics)?void 0:s.sent)||0),delivered:e.delivered+((null==(r=t.metrics)?void 0:r.delivered)||0),opened:e.opened+((null==(a=t.metrics)?void 0:a.opened)||0),clicked:e.clicked+((null==(l=t.metrics)?void 0:l.clicked)||0),bounced:e.bounced+((null==(n=t.metrics)?void 0:n.bounced)||0)}},{sent:0,delivered:0,opened:0,clicked:0,bounced:0});o(a)}catch(e){w.error("Failed to load analytics")}finally{l(!1)}},d=n.sent>0?(n.opened/n.sent*100).toFixed(1):"0",u=n.opened>0?(n.clicked/n.opened*100).toFixed(1):"0",x=n.sent>0?(n.bounced/n.sent*100).toFixed(1):"0",p=s.slice(0,5).map(e=>{var t,s,r;return{name:e.name.length>14?e.name.substring(0,14)+"…":e.name,Sent:(null==(t=e.metrics)?void 0:t.sent)||0,Opened:(null==(s=e.metrics)?void 0:s.opened)||0,Clicked:(null==(r=e.metrics)?void 0:r.clicked)||0}}),m=[{name:"Opened",value:n.opened},{name:"Clicked",value:n.clicked},{name:"Bounced",value:n.bounced},{name:"Unopened",value:Math.max(0,n.sent-n.opened-n.bounced)}].filter(e=>e.value>0),g=({status:s})=>{const r={active:{bg:t.successBg,text:t.successText},draft:{bg:t.cardBg,text:t.mutedText},paused:{bg:t.warningBg,text:t.warningText},completed:{bg:t.infoBg,text:t.infoText}},a=r[s]??r.draft;return e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-full text-xs font-semibold capitalize",style:{background:a.bg,color:a.text},children:s})};return a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Campaign Analytics"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Track performance across all email campaigns"})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4",children:[e.jsx(Fl,{p:t,icon:ee,label:"Total Sent",value:n.sent.toLocaleString(),iconBg:t.infoBg,iconColor:t.infoText}),e.jsx(Fl,{p:t,icon:Me,label:"Open Rate",value:`${d}%`,iconBg:t.successBg,iconColor:t.successText,sub:`${n.opened.toLocaleString()} opens`}),e.jsx(Fl,{p:t,icon:rt,label:"Click Rate",value:`${u}%`,iconBg:t.pillBg,iconColor:t.pillText,sub:`${n.clicked.toLocaleString()} clicks`}),e.jsx(Fl,{p:t,icon:le,label:"Bounce Rate",value:`${x}%`,iconBg:t.dangerBg,iconColor:t.dangerText,sub:`${n.bounced.toLocaleString()} bounces`})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-2xl p-5",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsx("p",{className:"text-sm font-semibold mb-4",style:{color:t.headlineColor},children:"Campaign Performance"}),p.length>0?e.jsx(Ot,{width:"100%",height:260,children:e.jsxs(zt,{data:p,margin:{left:-10,right:4,bottom:0},children:[e.jsx(Ht,{strokeDasharray:"3 3",stroke:t.chartGrid,vertical:!1}),e.jsx(qt,{dataKey:"name",tick:{fontSize:11,fill:t.chartText},axisLine:!1,tickLine:!1}),e.jsx(Wt,{tick:{fontSize:11,fill:t.chartText},axisLine:!1,tickLine:!1}),e.jsx(Vt,{content:e.jsx(Al,{p:t})}),e.jsx(Gt,{dataKey:"Sent",fill:t.chartColors[2],radius:[4,4,0,0]}),e.jsx(Gt,{dataKey:"Opened",fill:t.chartColors[0],radius:[4,4,0,0]}),e.jsx(Gt,{dataKey:"Clicked",fill:t.chartColors[1],radius:[4,4,0,0]})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-[260px] gap-3",children:[e.jsx(Le,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No campaign data yet"})]})]}),e.jsxs("div",{className:"rounded-2xl p-5",style:{background:t.cardBg,border:`1px solid ${t.cardBorder}`},children:[e.jsx("p",{className:"text-sm font-semibold mb-4",style:{color:t.headlineColor},children:"Email Engagement Breakdown"}),m.length>0?e.jsx(Ot,{width:"100%",height:260,children:e.jsxs(Kt,{children:[e.jsx(Yt,{data:m,cx:"50%",cy:"45%",outerRadius:90,dataKey:"value",strokeWidth:0,label:({name:e,percent:t})=>`${e} ${(100*t).toFixed(0)}%`,labelLine:{stroke:t.mutedText,strokeWidth:1},children:m.map((s,r)=>e.jsx(Jt,{fill:t.chartColors[r%t.chartColors.length]},`cell-${r}`))}),e.jsx(Vt,{content:e.jsx(Al,{p:t})})]})}):e.jsx("div",{className:"flex items-center justify-center h-[260px]",children:e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No engagement data yet"})})]})]}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsx("div",{className:"px-5 py-3 flex items-center justify-between",style:{background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`},children:e.jsx("p",{className:"text-sm font-semibold",style:{color:t.headlineColor},children:"All Campaigns Performance"})}),0===s.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[e.jsx(at,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:"No campaigns with metrics yet"})]}):s.map((r,a)=>{var l,n,o,i;return e.jsxs("div",{className:"px-5 py-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 transition-all",style:{borderBottom:a<s.length-1?`1px solid ${t.tableBorder}`:"none"},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("p",{className:"font-semibold text-sm",style:{color:t.headlineColor},children:r.name}),e.jsx(g,{status:r.status})]}),e.jsx("div",{className:"flex gap-5 sm:gap-8 text-sm flex-wrap",children:[{label:"Sent",value:(null==(l=r.metrics)?void 0:l.sent)||0,color:t.bodyText},{label:"Opened",value:(null==(n=r.metrics)?void 0:n.opened)||0,color:t.pillText},{label:"Clicked",value:(null==(o=r.metrics)?void 0:o.clicked)||0,color:t.successText},{label:"Bounced",value:(null==(i=r.metrics)?void 0:i.bounced)||0,color:t.dangerText}].map(({label:s,value:r,color:a})=>e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider",style:{color:t.mutedText},children:s}),e.jsx("p",{className:"font-bold tabular-nums",style:{color:a},children:r})]},s))})]},r.id)})]})]})}},{id:"optouts",label:"Opt-Outs",Icon:ot,Component:({p:t})=>{const[s,r]=c.useState([]),[a,l]=c.useState(!0),[n,o]=c.useState(!1),[i,d]=c.useState(!1),[u,x]=c.useState(""),[p,m]=c.useState(1),[g,b]=c.useState(10),[y,f]=c.useState(""),[v,j]=c.useState("all"),[N,F]=c.useState("");c.useEffect(()=>{A()},[]),c.useEffect(()=>{m(1)},[u]);const A=async()=>{try{l(!0);const{data:e,error:t}=await h.from("marketing_opt_outs").select("*").order("opted_out_at",{ascending:!1});if(t)throw t;r(e||[])}
1catch(e){w.error("Failed to load opt-outs")}finally{l(!1)}},R=s.filter(e=>e.email.toLowerCase().includes(u.toLowerCase())),E=R.slice((p-1)*g,p*g),L={all:{bg:t.dangerBg,border:t.dangerBorder,text:t.dangerText},promotional:{bg:t.warningBg,border:t.warningBorder,text:t.warningText},newsletter:{bg:t.infoBg,border:t.infoBorder,text:t.infoText}},D=({type:t})=>{const s=L[t]??L.newsletter;return e.jsx("span",{className:"inline-block px-2 py-0.5 rounded-full text-xs font-semibold capitalize",style:{background:s.bg,border:`1px solid ${s.border}`,color:s.text},children:t})},M={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${t.cardBorder}`,borderRadius:20};return a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-transparent animate-spin",style:{borderTopColor:t.spinnerColor,borderRightColor:`${t.spinnerColor}44`}})}):e.jsxs("div",{className:"p-5 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Opt-Out Management"}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:t.mutedText},children:"Manage email opt-outs for GDPR compliance"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ml,{p:t,onClick:()=>{const e=[["Email","Type","Reason","Opted Out At"],...R.map(e=>[e.email,e.opt_out_type,e.reason||"",St(new Date(e.opted_out_at),"yyyy-MM-dd HH:mm:ss")])].map(e=>e.join(",")).join("\n"),t=new Blob([e],{type:"text/csv"}),s=window.URL.createObjectURL(t),r=document.createElement("a");r.href=s,r.download=`marketing-opt-outs-${St(new Date,"yyyy-MM-dd")}.csv`,r.click(),window.URL.revokeObjectURL(s),w.success("Opt-outs exported")},children:[e.jsx(se,{style:{width:13,height:13},"aria-hidden":!0}),"Export"]}),e.jsxs(k,{open:n,onOpenChange:o,children:[e.jsx(_,{asChild:!0,children:e.jsxs(Dl,{p:t,children:[e.jsx(xe,{style:{width:13,height:13},"aria-hidden":!0}),"Add Opt-Out"]})}),e.jsxs(C,{style:M,children:[e.jsxs(B,{children:[e.jsx(T,{style:{color:t.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Add Email to Opt-Out List"}),e.jsx(S,{style:{color:t.mutedText},children:"This email will be excluded from all marketing campaigns"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(Ll,{p:t,children:"Email Address *"}),e.jsx(El,{p:t,value:y,onChange:e=>f(e.target.value),placeholder:"[email protected]",type:"email"})]}),e.jsxs("div",{children:[e.jsx(Ll,{p:t,children:"Opt-Out Type"}),e.jsxs("select",{value:v,onChange:e=>j(e.target.value),className:"w-full px-3 py-2 rounded-xl text-sm outline-none",style:{background:t.inputBg,border:`1px solid ${t.inputBorder}`,color:t.headlineColor},children:[e.jsx("option",{value:"all",style:{background:"#1a0235"},children:"All Emails"}),e.jsx("option",{value:"promotional",style:{background:"#1a0235"},children:"Promotional Only"}),e.jsx("option",{value:"newsletter",style:{background:"#1a0235"},children:"Newsletter Only"})]})]}),e.jsxs("div",{children:[e.jsx(Ll,{p:t,children:"Reason (Optional)"}),e.jsx(El,{p:t,value:N,onChange:e=>F(e.target.value),placeholder:"e.g., User request via support"})]})]}),e.jsxs($,{className:"gap-2",children:[e.jsx(Ml,{p:t,onClick:()=>o(!1),children:"Cancel"}),e.jsxs(Dl,{p:t,onClick:async()=>{if(y.trim())try{d(!0);const{error:e}=await h.from("marketing_opt_outs").insert({email:y.toLowerCase().trim(),opt_out_type:v,reason:N||"Manual admin entry"});if(e){if("23505"===e.code)return void w.error("This email is already opted out");throw e}w.success("Opt-out added"),o(!1),f(""),F(""),A()}catch(e){w.error(e.message||"Failed to add opt-out")}finally{d(!1)}else w.error("Email is required")},disabled:i,children:[i?e.jsx(K,{style:{width:13,height:13},className:"animate-spin"}):null,i?"Adding…":"Add Opt-Out"]})]})]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(G,{style:{width:14,height:14,position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:t.mutedText},"aria-hidden":!0}),e.jsx(El,{p:t,value:u,onChange:e=>x(e.target.value),placeholder:"Search by email…",style:{paddingLeft:36}
1,"aria-label":"Search opt-outs"})]}),e.jsxs("span",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-xl text-sm font-semibold",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`,color:t.dangerText},children:[e.jsx(ot,{style:{width:13,height:13},"aria-hidden":!0}),s.length," total opt-outs"]})]}),e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{border:`1px solid ${t.cardBorder}`},children:[e.jsxs("div",{className:"grid gap-3 px-4 py-3 text-xs font-bold uppercase tracking-wider",style:{gridTemplateColumns:"2fr 1fr 2fr 1.2fr auto",background:t.tableHeaderBg,borderBottom:`1px solid ${t.tableBorder}`,color:t.labelText},children:[e.jsx("span",{children:"Email"}),e.jsx("span",{children:"Type"}),e.jsx("span",{children:"Reason"}),e.jsx("span",{children:"Opted Out"}),e.jsx("span",{})]}),0===E.length?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-14",children:[e.jsx(ot,{style:{width:32,height:32,color:t.mutedText},"aria-hidden":!0}),e.jsx("p",{className:"text-sm",style:{color:t.mutedText},children:u?"No matching opt-outs found":"No opt-outs recorded"})]}):E.map((s,r)=>e.jsxs("div",{className:"grid gap-3 px-4 py-3.5 items-center transition-all",style:{gridTemplateColumns:"2fr 1fr 2fr 1.2fr auto",borderBottom:r<E.length-1?`1px solid ${t.tableBorder}`:"none"},onMouseEnter:e=>{e.currentTarget.style.background=t.tableRowHover},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsx("span",{className:"text-sm font-medium truncate",style:{color:t.headlineColor},children:s.email}),e.jsx(D,{type:s.opt_out_type}),e.jsx("span",{className:"text-xs truncate",style:{color:t.bodyText},children:s.reason||"—"}),e.jsx("span",{className:"text-xs",style:{color:t.mutedText},children:St(new Date(s.opted_out_at),"MMM dd, yyyy")}),e.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm("Remove this opt-out? The user will start receiving emails again."))try{const{error:t}=await h.from("marketing_opt_outs").delete().eq("id",e);if(t)throw t;w.success("Opt-out removed"),A()}catch(t){w.error(t.message||"Failed to remove opt-out")}})(s.id),className:"p-1.5 rounded-lg transition-all hover:opacity-80 active:scale-90",style:{background:t.dangerBg,border:`1px solid ${t.dangerBorder}`},"aria-label":`Remove opt-out for ${s.email}`,children:e.jsx(ge,{style:{width:12,height:12,color:t.dangerText},"aria-hidden":!0})})]},s.id))]}),R.length>g&&e.jsx(Rl,{currentPage:p,totalItems:R.length,pageSize:g,onPageChange:m,onPageSizeChange:e=>{b(e),m(1)}}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"button",onClick:A,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs transition-all hover:opacity-80",style:{color:t.mutedText},onMouseEnter:e=>{e.currentTarget.style.background=t.btnGhostHoverBg},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.jsx(re,{style:{width:11,height:11},"aria-hidden":!0}),"Refresh"]})})]})}}],Ul=()=>{var t;const[s,r]=c.useState("campaigns"),{resolvedTheme:a}=m(),l="light"===a?Il.light:Il.dark,n=Pl.find(e=>e.id===s).Component;return e.jsxs("div",{className:"w-full transition-colors duration-300",style:{background:l.sectionBg},children:[e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${l.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${l.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),e.jsxs("div",{className:"relative z-10 w-full p-4 sm:p-6 space-y-4",children:[e.jsx("div",{className:"rounded-2xl p-1.5",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},role:"tablist","aria-label":"Marketing automation sections",children:e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-1",children:Pl.map(({id:t,label:a,Icon:n})=>{const o=s===t;return e.jsxs("button",{role:"tab","aria-selected":o,"aria-controls":`panel-${t}`,onClick:()=>r(t),className:"relative flex flex-col sm:flex-row items-center justify-center gap-1 sm:gap-1.5 px-2 py-2.5 sm:py-2 rounded-xl text-xs font-semibold transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40 hover:scale-[1.02] active:scale-95",style:{background:o?l.tabActiveBg:"transparent",border:`1px solid ${o?l.tabActiveBorder:"transparent"}`,color:o?l.tabActiveText:l.tabInactiveText,boxShadow:o?"0 0 16px rgba(139,92,246,0.20)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background=l.tabHoverBg,e.currentTarget.style.color=l.headlineColor)},onMouseLeave:e=>{o||(e.currentTarget.style.background="transparent",e.currentTarget.style.color=l.tabInactiveText)},children:[e.jsx(n,{"aria-hidden":!0,style:{width:14,height:14,flexShrink:0,filter:o?"drop-shadow(0 0 6px rgba(167,139,250,0.7))":"none"}}),e.jsx("span",{className:"leading-tight",children:a}),o&&e.jsx("span",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 roun
1ded-full",style:{width:20,height:2,background:l.accentText,bottom:4},"aria-hidden":!0})]},t)})})}),e.jsx("div",{id:`panel-${s}`,role:"tabpanel","aria-label":null==(t=Pl.find(e=>e.id===s))?void 0:t.label,className:"rounded-2xl sm:rounded-3xl",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:e.jsx(n,{p:l})})]})]})},Ol=e=>e.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim(),zl=({id:t,type:s="text",value:r,onChange:a,placeholder:l,p:n,disabled:o})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),placeholder:l,disabled:o,style:{width:"100%",padding:"9px 12px",borderRadius:9,border:`1.5px solid ${n.inputBorder}`,background:n.inputBg,color:n.headlineColor,fontSize:13,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s",opacity:o?.5:1},onFocus:e=>!o&&(e.target.style.borderColor=n.inputFocusBorder),onBlur:e=>e.target.style.borderColor=n.inputBorder}),Hl=({value:t,onValueChange:s,placeholder:r,children:a,p:l})=>e.jsxs(g,{value:t,onValueChange:s,children:[e.jsx(b,{style:{width:"100%",padding:"9px 12px",borderRadius:9,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:t?l.headlineColor:l.mutedText,fontSize:13,fontFamily:"inherit",height:"auto",boxShadow:"none",outline:"none"},children:e.jsx(y,{placeholder:r??"Select..."})}),e.jsx(f,{className:"z-[100]",style:{background:l.tooltipBg,border:`1.5px solid ${l.inputBorder}`,borderRadius:10,color:l.headlineColor,fontSize:13,fontFamily:"inherit"},children:a})]}),ql=({children:t,p:s})=>e.jsx("label",{className:"text-xs font-bold uppercase tracking-wide block mb-1.5",style:{color:s.labelText},children:t}),Wl=({icon:t,title:s,description:r,children:a,p:l,headerAction:n})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${l.divider}`,background:l.tableHeaderBg},children:[t&&e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:l.badgeBg,border:`1px solid ${l.badgeBorder}`},children:e.jsx(t,{className:"h-4 w-4",style:{color:l.accentText}})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:l.tableHeaderText},children:s}),r&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:l.mutedText},children:r})]}),n&&e.jsx("div",{className:"ml-auto flex-shrink-0",children:n})]}),e.jsx("div",{className:"p-6",children:a})]}),Vl=({onClick:t,disabled:s,children:r,p:a,variant:l="primary"})=>{const n="ghost"===l?{background:a.stepLockedBg,color:a.bodyText,border:`1px solid ${a.stepLockedBorder}`}:{background:a.btnPrimaryBg,color:"#fff",border:"none"};return e.jsx("button",{type:"button",onClick:t,disabled:s,className:"flex items-center justify-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{...n,fontFamily:"inherit",cursor:s?"not-allowed":"pointer"},children:r})},Gl=({college:t,onEdit:s,onToggle:r,p:a})=>e.jsx("div",{className:"rounded-xl overflow-hidden",style:{background:a.statCardBg,border:`1px solid ${a.statCardBorder}`},children:e.jsxs("div",{className:"p-5 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-semibold text-sm",style:{color:a.headlineColor},children:t.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:t.is_active?"rgba(52,211,153,0.15)":"rgba(255,255,255,0.07)",color:t.is_active?a.greenAccent:a.mutedText,border:`1px solid ${t.is_active?"rgba(52,211,153,0.30)":a.tableBorder}`},children:t.is_active?"Active":"Inactive"})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-x-6 gap-y-1.5 text-xs",style:{color:a.mutedText},children:[e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Email:"})," ",t.contact_email]}),t.contact_phone&&e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Phone:"})," ",t.contact_phone]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Location:"}
1)," ",[t.city,t.state,t.country].filter(Boolean).join(", ")||"—"]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Credits:"})," ",e.jsx("span",{style:{color:a.accentText,fontWeight:700},children:t.credit_pool??0})]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Max Users:"})," ",t.max_students??100]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(Ft,{checked:t.is_active??!1,onCheckedChange:r}),e.jsx("button",{type:"button",onClick:s,className:"rounded-lg p-2 transition-all hover:opacity-80",style:{background:a.badgeBg,border:`1px solid ${a.badgeBorder}`,color:a.accentText},children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]})]})}),Kl=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,r=(e=>({inputBg:e.inputBg,inputBorder:e.inputBorder,inputBorderFocus:e.inputFocusBorder,inputText:e.headlineColor,inputPlaceholder:e.mutedText,errorColor:"#f87171"}))(s),[a,l]=c.useState([]),[n,o]=c.useState(!0),[i,d]=c.useState(!1),[u,x]=c.useState(!1),[p,g]=c.useState(!1),[b,y]=c.useState(!1),[f,N]=c.useState(!1),[k,_]=c.useState(""),[C,B]=c.useState(""),[T,S]=c.useState("+91"),[$,F]=c.useState(""),[E,L]=c.useState("India"),[D,M]=c.useState(""),[I,P]=c.useState("0"),[U,O]=c.useState("100"),[z,H]=c.useState(null),[q,W]=c.useState({}),[V,G]=c.useState(!1),[K,Y]=c.useState(""),[J,Q]=c.useState(""),[X,Z]=c.useState("+91"),[te,se]=c.useState(""),[ae,le]=c.useState(""),[ne,oe]=c.useState([]),[ie,de]=c.useState([]),[ce,ue]=c.useState(!1),[pe,me]=c.useState(null),[he,ge]=c.useState({full_name:"",email:"",phone:""}),[be,fe]=c.useState(!1),[ve,je]=c.useState(""),[we,Ne]=c.useState(""),[ke,Be]=c.useState([]);c.useEffect(()=>{Promise.all([Te(),$e(),Fe()])},[]);const Te=async()=>{o(!0);const{data:e,error:t}=await h.from("colleges").select("*").order("created_at",{ascending:!1});t?w.error(t.message):l(e||[]),o(!1)},$e=async()=>{ue(!0);try{const{data:e,error:t}=await h.functions.invoke("college-create-admin",{body:{action:"list_all_admins"}});if(t)throw t;if(null==e?void 0:e.error)throw new Error(e.error);de((null==e?void 0:e.admins)||[])}catch(e){w.error((null==e?void 0:e.message)||"Failed to load college admins"),de([])}finally{ue(!1)}},Fe=async()=>{try{const{data:{session:e}}=await h.auth.getSession(),{data:t,error:s}=await h.functions.invoke("college-grant-credits",{body:{action:"list"},headers:(null==e?void 0:e.access_token)?{Authorization:`Bearer ${e.access_token}`}:void 0});if(s)throw s;if(null==t?void 0:t.error)throw new Error(t.error);Be((Array.isArray(null==t?void 0:t.transactions)?t.transactions:[]).map(e=>({id:String(e.id??crypto.randomUUID()),collegeName:e.college_name||"Unknown",amount:Math.abs(Number(e.amount??0)),action:"deduct"===e.action?"deduct":"grant",grantedAt:e.granted_at?new Date(e.granted_at).toLocaleString():"—",previousBalance:Number(e.previous_balance??0),newBalance:Number(e.new_balance??0)})))}catch(e){}},Ae=A.find(e=>e.name===E),Ee=(null==Ae?void 0:Ae.states)||[],Le=A.find(e=>e.name===q.country),De=(null==Le?void 0:Le.states)||[],Pe=async()=>{if(!z)return;G(!0);const e={name:q.name,slug:Ol(q.name||""),contact_email:q.contact_email,contact_phone:q.contact_phone,city:q.city,country:q.country,state:q.state,max_students:q.max_students};"number"!=typeof q.credit_pool||Number.isNaN(q.credit_pool)||(e.credit_pool=Math.max(0,Math.floor(q.credit_pool)));const{error:t}=await h.from("colleges").update(e).eq("id",z);t?w.error(t.message):(w.success("College updated"),H(null),Te()),G(!1)},Ue=async()=>{if(!pe)return;const e=ie.find(e=>e.id===pe);if(e){fe(!0);try{const{error:t}=await h.from("profiles").update({full_name:he.full_name,mobile_number:he.phone||null}).eq("user_id",e.user_id);if(t)throw t;w.success("Admin updated successfully"),me(null),await $e()}catch(t){w.error((null==t?void 0:t.message)||"Update failed")}fe(!1)}},Oe={width:"100%",padding:"9px 12px",borderRadius:9,border:`1.5px solid ${s.inputBorder}`,background:s.inputBg,color:s.headlineColor,fontSize:13,fontFamily:"inherit",outline:"none"};return e.jsxs("div",{className:"w-full space-y-6 px-4 sm:px-6 lg:px-8 py-6",style:{fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs(Wl,{icon:Ie,title:"Create New College",description:"Register a new institution on the platform",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"College Name *"}),e.jsx(zl,{value:k,onChange:_,placeholder:"XYZ Institute of Technology",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Contact Email *"}),e.jsx(zl,{type:"email",value:C,onChange:B,placeholder:"[email protected]",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Contact Phone *"}),e.jsx(R,{value:T,onChange:S,themeStyles:r})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Country *"}),e.jsx(Hl,{value:E,onValueChange:e=>{L(e),M("")},p:s,children:A.map(t=>e.jsx(v,{value:t.name,children:t.name},t.code))})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"State *"}),Ee.length>0?e.jsx(Hl,{value:D,onValueChange:M,placeholder:"Select state",p:s,children:Ee.map(t=>e.jsx(v,{value:t,children:t},t))}):e.jsx(zl,{value:D,onChange:M,placeholder:"Enter state",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"City *"}),e.jsx(zl,{value:$,onChange:F,placeholder:"Bangalore",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Initial Credit Pool"}),e.jsx(zl,{type:"number",value:I,onChange:P,placeholder:"0",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Max Users"}),e.jsx(zl,{type:"number",value:U,onChange:O,placeholder:"100",p:s})]})]}),e.jsx("div",{className:"mt-5",children:e.jsxs(Vl,{onClick:async()=>
1{if(!k||!C||!T||T.length<5||!$||!E||!D)return void w.error("All fields are required");d(!0);const{error:e}=await h.from("colleges").insert({name:k,slug:Ol(k),contact_email:C,contact_phone:T,city:$,country:E,state:D,credit_pool:parseInt(I)||0,max_students:parseInt(U)||100});e?w.error(e.message):(w.success("College created successfully"),_(""),B(""),S("+91"),F(""),M(""),L("India"),P("0"),O("100"),Te()),d(!1)},disabled:i,p:s,children:[e.jsx(xe,{className:"h-4 w-4"}),i?"Creating...":"Create College"]})})]}),e.jsx(Wl,{icon:Ie,title:"Registered Colleges",description:`${a.length} college(s) on platform`,p:s,headerAction:e.jsxs(Vl,{onClick:Te,disabled:n,p:s,variant:"ghost",children:[e.jsx(re,{className:"h-4 w-4 "+(n?"animate-spin":"")})," Refresh"]}),children:n?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"Loading..."}):0===a.length?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"No colleges registered yet."}):e.jsx("div",{className:"space-y-3",children:a.map(t=>z===t.id?e.jsxs("div",{className:"rounded-xl p-5 space-y-4",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Name"}),e.jsx(zl,{value:q.name||"",onChange:e=>W(t=>({...t,name:e})),placeholder:"College name",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Contact Email"}),e.jsx(zl,{type:"email",value:q.contact_email||"",onChange:e=>W(t=>({...t,contact_email:e})),placeholder:"Email",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Phone"}),e.jsx(R,{value:q.contact_phone||"+91",onChange:e=>W(t=>({...t,contact_phone:e})),themeStyles:r})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Country"}),e.jsx(Hl,{value:q.country||"India",onValueChange:e=>W(t=>({...t,country:e,state:""})),p:s,children:A.map(t=>e.jsx(v,{value:t.name,children:t.name},t.code))})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"State"}),De.length>0?e.jsx(Hl,{value:q.state||"",onValueChange:e=>W(t=>({...t,state:e})),placeholder:"Select state",p:s,children:De.map(t=>e.jsx(v,{value:t,children:t},t))}):e.jsx(zl,{value:q.state||"",onChange:e=>W(t=>({...t,state:e})),placeholder:"State",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"City"}),e.jsx(zl,{value:q.city||"",onChange:e=>W(t=>({...t,city:e})),placeholder:"City",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Max Users"}),e.jsx(zl,{type:"number",value:q.max_students??100,onChange:e=>W(t=>({...t,max_students:parseInt(e)||100})),placeholder:"100",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Credit Pool"}),e.jsx(zl,{type:"number",value:q.credit_pool??0,onChange:e=>W(t=>({...t,credit_pool:Math.max(0,parseInt(e)||0)})),placeholder:"0",p:s})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Vl,{onClick:Pe,disabled:V,p:s,children:[e.jsx(it,{className:"h-4 w-4"}),V?"Saving...":"Save"]}),e.jsxs(Vl,{onClick:()=>H(null),p:s,variant:"ghost",children:[e.jsx(ye,{className:"h-4 w-4"}),"Cancel"]})]})]},t.id):e.jsx(Gl,{college:t,onEdit:()=>{H(t.id),W({name:t.name,contact_email:t.contact_email,contact_phone:t.contact_phone||"+91",city:t.city||"",country:t.country||"India",state:t.state||"",max_students:t.max_students,credit_pool:t.credit_pool??0})},onToggle:()=>(async e=>{const t=!e.is_active;if(!t){const{count:t}=await h.from("college_members").select("id",{count:"exact",head:!0}).eq("college_id",e.id).eq("role","admin").eq("status","active");if(!t||0===t)return void w.error("Cannot deactivate: no active admin found for this college.");if(!window.confirm(`Deactivate "${e.name}"?\n\nAll college members and students will be locked out, pending credit requests will be auto-denied, and new credit usage will be blocked. In-progress interviews will still finish.\n\nThis can be reversed by reactivating later.`))return}const{error:s}=await h.from("colleges").update({is_active:t}).eq("id",e.id);s?w.error(s.message):(t?(await h.from("college_members").update({status:"active"}).eq("college_id",e.id),await h.from("college_students").update({status:"active"}).eq("college_id",e.id)):(await h.from("college_members").update({status:"inactive"}).eq("college_id",e.id),await h.from("college_students").update({status:"inactive"}).eq("college_id",e.id)),w.success("College "+(t?"activated — all members restored":"deactivated — all members locked")),Te())})(t),p:s},t.id))})}),e.jsxs(Wl,{icon:Re,title:"Create College Admin",description:"Create a new user account and assign them as a college admin",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Full Name *"}),e.jsx(zl,{value:J,onChange:Q,placeholder:"Dr. Rajesh Kumar",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Email *"}),e.jsx(zl,{type:"email",value:K,onChange:Y,placeholder:"[email protected]",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Phone *"}),e.jsx(R,{value:X,onChange:Z,themeStyles:r})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Password *"}),e.jsxs("div",{className:"relative",children:[e.jsx(zl,{type:f?"text":"password",value:te,onChange:se,placeholder:"Min 6 characters",p:s}),e.jsx("button",{type:"button",onClick:()=>N(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2",style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:f?e.jsx(He,{className:"h-4 w-4"}):e.jsx(Me,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(ql,{p:s,children:"Assign to College *"}),e.jsxs("select",{value:ae,onChange:e=>le(e.target.value),style:{...Oe,height:40},children:[e.jsx("option",{value:"",children:"Select a college..."}),a.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(Vl,{onClick:async()=>{var e,t;if(J.trim()&&K&&X&&!(X.length<5)&&te&&ae)if(te.length<6)w.error("Password must be at least 6 characters");else{y(!0);try{const s=await h.functions.invoke("college-create-admin",{body:{email:K.trim().toLowerCase(),full_name:J.trim(),phone:X.trim()||null,password:te,college_id:ae,member_role:"admin"}});if(s.error)throw s.error;if(null==(e=s.data)?void 0:e.error)throw new Error(s.data.error);const r=(null==(t=a.find(e=>e.id===ae))?void 0:t.name)||"";oe(e=>[{email:K.trim().toLowerCase(),fullName:J.trim(),phone:X,collegeName:r,createdAt:(new Date).toLocaleStr
1ing()},...e]),w.success(`Admin created for ${r}`),Y(""),Q(""),Z("+91"),se(""),le(""),await $e()}catch(s){w.error((null==s?void 0:s.message)||"Failed to create admin")}y(!1)}else w.error("All fields are required")},disabled:b||!J.trim()||!K||!X||X.length<5||!te||!ae,p:s,children:[e.jsx(Re,{className:"h-4 w-4"}),b?"Creating...":"Create College Admin"]})}),ne.length>0&&e.jsxs("div",{className:"mt-6 space-y-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide",style:{color:s.labelText},children:"Recently Created"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ne.map((t,r)=>e.jsxs("div",{className:"rounded-xl p-4 flex items-start justify-between",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-3.5 w-3.5",style:{color:s.accentText}}),e.jsx("span",{className:"text-sm font-medium",style:{color:s.bodyText},children:t.fullName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-3.5 w-3.5",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:t.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:t.collegeName})]})]}),e.jsx("button",{type:"button",onClick:()=>oe(e=>e.filter((e,t)=>t!==r)),style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]},r))})]})]}),e.jsx(Wl,{icon:_e,title:"Existing College Admins",description:`${ie.length} admin(s) across all colleges`,p:s,headerAction:e.jsxs(Vl,{onClick:$e,disabled:ce,p:s,variant:"ghost",children:[e.jsx(re,{className:"h-4 w-4 "+(ce?"animate-spin":"")})," Refresh"]}),children:ce?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"Loading..."}):0===ie.length?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"No college admins found."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:ie.map(t=>pe===t.id?e.jsxs("div",{className:"rounded-xl p-4 space-y-3",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Full Name"}),e.jsx(zl,{value:he.full_name,onChange:e=>ge(t=>({...t,full_name:e})),placeholder:"Full name",p:s})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Email (read-only)"}),e.jsx(zl,{type:"email",value:he.email,onChange:()=>{},placeholder:"Email",p:s,disabled:!0})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Phone"}),e.jsx(R,{value:he.phone||"+91",onChange:e=>ge(t=>({...t,phone:e})),themeStyles:r})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(Vl,{onClick:Ue,disabled:be,p:s,children:[e.jsx(it,{className:"h-3.5 w-3.5"}),be?"Saving...":"Save"]}),e.jsxs(Vl,{onClick:()=>me(null),p:s,variant:"ghost",children:[e.jsx(ye,{className:"h-3.5 w-3.5"})," Cancel"]})]})]},t.id):e.jsxs("div",{className:"rounded-xl p-4 space-y-2",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(_e,{className:"h-4 w-4 flex-shrink-0",style:{color:s.accentText}}),e.jsx("span",{className:"text-sm font-medium truncate",style:{color:s.bodyText},children:t.full_name||"—"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(Ft,{checked:"active"===t.status,onCheckedChange:()=>(async e=>{const t="active"===e.status?"inactive":"active",{error:s}=await h.from("college_members").update({status:t}).eq("id",e.id);s?w.error(s.message):(w.success("Admin "+("active"===t?"activated":"deactivated")),await $e())})(t)}),e.jsx("button",{type:"button",onClick:()=>{me(t.id),ge({full_name:t.full_name||"",email:t.email||"",phone:t.phone||"+91"})},className:"rounded-lg p-1.5 transition-all hover:opacity-80",style:{background:s.badgeBg,border:`1px solid ${s.badgeBorder}`,color:s.accentText},children:e.jsx(qe,{className:"h-3 w-3"})})]})]}),e.jsx("div",{children:e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:"active"===t.status?"rgba(52,211,153,0.15)":"rgba(255,255,255,0.07)",color:"active"===t.status?s.greenAccent:s.mutedText,border:`1px solid ${"active"===t.status?"rgba(52,211,153,0.30)":s.tableBorder}`},children:"active"===t.status?"Active":"Inactive"})}),t.email&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs truncate",style:{color:s.mutedText},children:t.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:t.college_name})]}),t.created_at&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:s.mutedText}}),e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:["Added: ",new Date(t.created_at).toLocaleDateString()]})]})]},t.id))})}),e.jsxs(Wl,{icon:Ce,title:"Manage College Credits",description:"Grant or deduct credits from a college's shared pool",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"College"}),e.jsxs("select",{value:ve,onChange:e=>je(e.target.value),style:{...Oe,height:40},children:[e.jsx("option",{value:"",children:"Select a college..."}),a.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (Pool: ",t.credit_pool??0,")"]},t.id))]})]}),e.jsxs("div",{children:[e.jsx(ql,{p:s,children:"Credit Amount"}),e.jsx(zl,{type:"number",value:we,onChange:Ne,placeholder:"500",p:s})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-3",children:[e.jsxs(Vl,{onClick:async()=>{const e=parseInt(we,10);if(!ve||!e||e<=0)w.error("Select a college and enter a valid amount");else{x(!0);try{const{data:{session:t}}=await h.auth.getSession();if(!(null==t?void 0:t.access_token))throw new Error("Session expired");const{data:s,error:r}=await h.functions.invoke("college-grant-credits",{body:{action:"grant",college_id:ve,amount:e},headers:{Authorization:`Bearer ${t.access_token}`}});if(r)throw r;if(null==s?void 0:s.error)throw new Error(s.error);const l=null==s?void 0:s.transaction;l&&Be(t=>{var s;return[{id:String(l.id??crypto.randomUUID()),collegeName:l.college_name||(null==(s=a.find(e=>e.id===ve))?void 0:s.name)||"Unknown",amount:Math.abs(Number(l.amount??e)),action:"grant",grantedAt:l.granted_at?new Date(l.granted_at).toLocaleStr
1ing():(new Date).toLocaleString(),previousBalance:Number(l.previous_balance??0),newBalance:Number(l.new_balance??0)},...t]}),w.success(`${e} credits granted successfully`),Ne(""),je(""),await Promise.all([Te(),Fe()])}catch(t){w.error((null==t?void 0:t.message)||"Grant failed")}x(!1)}},disabled:u||p,p:s,children:[e.jsx(Ce,{className:"h-4 w-4"}),u?"Granting...":"Grant Credits"]}),e.jsxs("button",{type:"button",onClick:async()=>{const e=parseInt(we,10);if(!ve||!e||e<=0)w.error("Select a college and enter a valid amount");else{g(!0);try{const{data:{session:t}}=await h.auth.getSession();if(!(null==t?void 0:t.access_token))throw new Error("Session expired");const{data:s,error:r}=await h.functions.invoke("college-grant-credits",{body:{action:"deduct",college_id:ve,amount:e},headers:{Authorization:`Bearer ${t.access_token}`}});if(r)throw r;if(null==s?void 0:s.error)throw new Error(s.error);const l=null==s?void 0:s.transaction;l&&Be(t=>{var s;return[{id:String(l.id??crypto.randomUUID()),collegeName:l.college_name||(null==(s=a.find(e=>e.id===ve))?void 0:s.name)||"Unknown",amount:Math.abs(Number(l.amount??e)),action:"deduct",grantedAt:l.granted_at?new Date(l.granted_at).toLocaleString():(new Date).toLocaleString(),previousBalance:Number(l.previous_balance??0),newBalance:Number(l.new_balance??0)},...t]}),w.success(`${e} credits deducted successfully`),Ne(""),je(""),await Promise.all([Te(),Fe()])}catch(t){w.error((null==t?void 0:t.message)||"Deduct failed")}g(!1)}},disabled:u||p,style:{display:"inline-flex",alignItems:"center",gap:8,padding:"10px 18px",borderRadius:10,fontSize:14,fontWeight:600,cursor:u||p?"not-allowed":"pointer",opacity:u||p?.6:1,background:`${s.redAccent}1f`,color:s.redAccent,border:`1.5px solid ${s.redAccent}66`,transition:"all 0.18s ease"},children:[e.jsx(ct,{className:"h-4 w-4"}),p?"Deducting...":"Deduct Credits"]})]}),ke.length>0&&e.jsxs("div",{className:"mt-6 space-y-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide",style:{color:s.labelText},children:"Recent Activity"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ke.map(t=>{const r="deduct"===t.action,a=r?s.redAccent:s.greenAccent,l=r?"248,113,113":"52,211,153";return e.jsxs("div",{className:"rounded-xl p-4 flex items-start justify-between",style:{background:`rgba(${l},0.07)`,border:`1px solid rgba(${l},0.18)`},children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5",style:{color:s.mutedText}}),e.jsx("span",{className:"text-sm font-medium",style:{color:s.bodyText},children:t.collegeName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(ct,{className:"h-3.5 w-3.5",style:{color:a}}):e.jsx(We,{className:"h-3.5 w-3.5",style:{color:a}}),e.jsxs("span",{className:"text-sm font-bold",style:{color:a},children:[r?"−":"+",t.amount," credits"]})]}),e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:[t.previousBalance," → ",t.newBalance," · ",t.grantedAt]})]}),e.jsx("button",{type:"button",onClick:()=>Be(e=>e.filter(e=>e.id!==t.id)),style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]},t.id)})})]})]})]})},Yl=e=>e.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim(),Jl=({id:t,type:s="text",value:r,onChange:a,placeholder:l,p:n,disabled:o})=>e.jsx("input",{id:t,type:s,value:r,onChange:e=>a(e.target.value),placeholder:l,disabled:o,style:{width:"100%",padding:"9px 12px",borderRadius:9,border:`1.5px solid ${n.inputBorder}`,background:n.inputBg,color:n.headlineColor,fontSize:13,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s",opacity:o?.5:1},onFocus:e=>!o&&(e.target.style.borderColor=n.inputFocusBorder),onBlur:e=>e.target.style.borderColor=n.inputBorder}),Ql=({children:t,p:s})=>e.jsx("label",{className:"text-xs font-bold uppercase tracking-wide block mb-1.5",style:{color:s.labelText},children:t}),Xl=({value:t,onValueChange:s,placeholder:r,children:a,p:l})=>e.jsxs(g,{value:t,onValueChange:s,children:[e.jsx(b,{style:{width:"100%",padding:"9px 12px",borderRadius:9,border:`1.5px solid ${l.inputBorder}`,background:l.inputBg,color:t?l.headlineColor:l.mutedText,fontSize:13,fontFamily:"inherit",height:"auto",boxShadow:"none",outline:"none"},children:e.jsx(y,{placeholder:r??"Select..."})}),e.jsx(f,{className:"z-[100]",style:{background:l.tooltipBg,border:`1.5px solid ${l.inputBorder}`,borderRadius:10,color:l.headlineColor,fontSize:13,fontFamily:"inherit"},children:a})]}),Zl=({icon:t,title:s,description:r,children:a,p:l,headerRight:n})=>e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:l.cardBg,border:`1px solid ${l.cardBorder}`},children:[e.jsxs("div",{className:"px-6 py-4 flex items-center gap-3",style:{borderBottom:`1px solid ${l.divider}`,background:l.tableHeaderBg},children:[t&&e.jsx("div",{className:"rounded-xl flex items-center justify-center flex-shrink-0",style:{width:32,height:32,background:l.badgeBg,border:`1px solid ${l.badgeBorder}`},children:e.jsx(t,{className:"h-4 w-4",style:{color:l.accentText}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-[0.12em]",style:{color:l.tableHeaderText},children:s}),r&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:l.mutedText},children:r})]}),n&&e.jsx("div",{className:"flex-shrink-0",children:n})]}),e.jsx("div",{className:"p-6",children:a})]}),en=({onClick:t,disabled:s,children:r,p:a,variant:l="primary"})=>{const n={primary:{background:a.btnPrimaryBg,color:"#fff",border:"none"},ghost:{background:a.stepLockedBg,color:a.bodyText,border:`1px solid ${a.stepLockedBorder}`},danger:{background:"rgba(248,113,113,0.10)",color:a.redAccent,border:"1px solid rgba(248,113,113,0.25)"}}[l];return e.jsx("button",{type:"button",onClick:t,disabled:s,className:"flex items-center justify-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{...n,fontFamily:"inherit",curs
1or:s?"not-allowed":"pointer"},children:r})},tn=({corp:t,onEdit:s,onToggle:r,p:a})=>e.jsx("div",{className:"rounded-xl overflow-hidden",style:{background:a.statCardBg,border:`1px solid ${a.statCardBorder}`},children:e.jsxs("div",{className:"p-5 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-semibold text-sm",style:{color:a.headlineColor},children:t.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:t.is_active?"rgba(52,211,153,0.15)":"rgba(255,255,255,0.07)",color:t.is_active?a.greenAccent:a.mutedText,border:`1px solid ${t.is_active?"rgba(52,211,153,0.30)":a.tableBorder}`},children:t.is_active?"Active":"Inactive"})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-x-6 gap-y-1.5 text-xs",style:{color:a.mutedText},children:[t.contact_name&&e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Contact:"})," ",t.contact_name]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Email:"})," ",t.contact_email]}),t.contact_phone&&e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Phone:"})," ",t.contact_phone]}),t.industry&&e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Industry:"})," ",t.industry]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Location:"})," ",[t.city,t.state,t.country].filter(Boolean).join(", ")||"—"]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Credits:"})," ",e.jsx("span",{style:{color:a.accentText,fontWeight:700},children:t.credit_pool??0})]}),e.jsxs("span",{children:[e.jsx("strong",{style:{color:a.bodyText},children:"Max Users:"})," ",t.max_users??50]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(Ft,{checked:t.is_active??!1,onCheckedChange:r}),e.jsx("button",{type:"button",onClick:s,className:"rounded-lg p-2 transition-all hover:opacity-80",style:{background:a.badgeBg,border:`1px solid ${a.badgeBorder}`,color:a.accentText},children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]})]})}),sn=({admin:t,onToggle:s,onEdit:r,p:a})=>{const l="inactive"!==t.status;return e.jsxs("div",{className:"rounded-xl p-4 space-y-3",style:{background:a.statCardBg,border:`1px solid ${a.statCardBorder}`,opacity:l?1:.7},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0",style:{width:28,height:28,background:a.badgeBg,border:`1px solid ${a.badgeBorder}`},children:e.jsx(_e,{className:"h-3.5 w-3.5",style:{color:a.accentText}})}),e.jsx("span",{className:"text-sm font-semibold truncate",style:{color:a.bodyText},children:t.full_name||"—"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:a.badgeBg,color:a.accentText,border:`1px solid ${a.badgeBorder}`},children:"Admin"}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:l?"rgba(52,211,153,0.15)":"rgba(255,255,255,0.07)",color:l?a.greenAccent:a.mutedText,border:`1px solid ${l?"rgba(52,211,153,0.30)":a.tableBorder}`},children:l?"Active":"Inactive"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[t.email&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:a.mutedText}}),e.jsx("span",{className:"text-xs truncate",style:{color:a.mutedText},children:t.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:a.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:a.mutedText},children:t.corporate_name})]}),t.created_at&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:a.mutedText}}),e.jsxs("span",{className:"text-xs",style:{color:a.mutedText},children:["Added: ",new Date(t.created_at).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",style:{borderTop:`1px solid ${a.divider}`},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{checked:l,onCheckedChange:s}),e.jsx("span",{className:"text-xs",style:{color:a.mutedText},children:l?"Active":"Inactive"})]}),e.jsxs("button",{type:"button",onClick:r,className:"rounded-lg p-1.5 transition-all hover:opacity-80 flex items-center gap-1.5",style:{background:a.badgeBg,border:`1px solid ${a.badgeBorder}`,color:a.accentText},children:[e.jsx(qe,{className:"h-3 w-3"}),e.jsx("span",{className:"text-xs font-semibold",children:"Edit"})]})]})]})},rn=({admin:t,onSave:s,onCancel:r,p:a})=>{const[l,n]=c.useState(t.full_name||""),[o,i]=c.useState(t.email||""),[d,u]=c.useState(t.phone||"+91"),[x,p]=c.useState(!1);return e.jsxs("div",{className:"rounded-xl p-4 space-y-3",style:{background:a.statCardBg,border:`1px solid ${a.accentText}55`},children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide",style:{color:a.accentText},children:"Edit Admin"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(Ql,{p:a,children:"Full Name"}
1),e.jsx(Jl,{value:l,onChange:n,placeholder:"Full name",p:a})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:a,children:"Email"}),e.jsx(Jl,{type:"email",value:o,onChange:i,placeholder:"[email protected]",p:a})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:a,children:"Phone"}),e.jsx(R,{value:d,onChange:u,themeStyles:{inputBg:a.inputBg,inputBorder:a.inputBorder,inputBorderFocus:a.inputFocusBorder,inputText:a.headlineColor,inputPlaceholder:a.mutedText}})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(en,{onClick:async()=>{p(!0),await s({full_name:l,email:o,phone:d}),p(!1)},disabled:x,p:a,children:[e.jsx(it,{className:"h-4 w-4"}),x?"Saving...":"Save"]}),e.jsxs(en,{onClick:r,p:a,variant:"ghost",children:[e.jsx(ye,{className:"h-4 w-4"}),"Cancel"]})]})]})},an=()=>{const{resolvedTheme:t}=m(),s="light"===t?j.light:j.dark,[r,a]=c.useState([]),[l,n]=c.useState(!0),[o,i]=c.useState(!1),[d,u]=c.useState(!1),[x,p]=c.useState(!1),[g,b]=c.useState(!1),[y,f]=c.useState(!1),[N,k]=c.useState(""),[_,C]=c.useState(""),[B,T]=c.useState(""),[S,$]=c.useState("+91"),[F,E]=c.useState(""),[L,D]=c.useState(""),[M,I]=c.useState(""),[P,U]=c.useState("India"),[O,z]=c.useState(""),[H,q]=c.useState("0"),[W,V]=c.useState("50"),[G,K]=c.useState(null),[Y,J]=c.useState({}),[Q,X]=c.useState(!1),[Z,te]=c.useState(""),[se,ae]=c.useState(""),[le,ne]=c.useState("+91"),[oe,ie]=c.useState(""),[de,ce]=c.useState(""),[ue,pe]=c.useState([]),[me,he]=c.useState([]),[ge,be]=c.useState(!1),[fe,ve]=c.useState(null),[je,we]=c.useState(""),[Ne,ke]=c.useState(""),[Be,Te]=c.useState([]),Se={inputBg:s.inputBg,inputBorder:s.inputBorder,inputBorderFocus:s.inputFocusBorder,inputText:s.headlineColor,inputPlaceholder:s.mutedText};c.useEffect(()=>{Promise.all([$e(),Fe(),Ae()])},[]);const $e=async()=>{n(!0);const{data:e,error:t}=await h.from("corporates").select("*").order("created_at",{ascending:!1});t?w.error(t.message):a(e||[]),n(!1)},Fe=async()=>{be(!0);try{const{data:e}=await h.from("corporate_members").select("id, user_id, corporate_id, role, status, created_at").eq("role","admin").order("created_at",{ascending:!1});if(!(null==e?void 0:e.length))return void he([]);const t=e.map(e=>e.user_id),{data:s}=await h.from("profiles").select("user_id, full_name, email, mobile_number").in("user_id",t),r={};(s||[]).forEach(e=>{r[e.user_id]={full_name:e.full_name,email:e.email??null,phone:e.mobile_number??null}});const{data:a}=await h.from("corporates").select("id, name"),l={};(a||[]).forEach(e=>{l[e.id]=e.name}),he(e.map(e=>{var t,s,a;return{id:e.id,user_id:e.user_id,full_name:(null==(t=r[e.user_id])?void 0:t.full_name)||null,email:(null==(s=r[e.user_id])?void 0:s.email)||null,phone:(null==(a=r[e.user_id])?void 0:a.phone)||null,corporate_id:e.corporate_id,corporate_name:l[e.corporate_id]||"Unknown",role:e.role,status:e.status,created_at:e.created_at}}))}catch(e){}be(!1)},Ae=async()=>{try{const{data:{session:e}}=await h.auth.getSession(),{data:t,error:s}=await h.functions.invoke("corporate-grant-credits",{body:{action:"list"},headers:(null==e?void 0:e.access_token)?{Authorization:`Bearer ${e.access_token}`}:void 0});if(s)throw s;if(null==t?void 0:t.error)throw new Error(t.error);Te((Array.isArray(null==t?void 0:t.transactions)?t.transactions:[]).map(e=>({id:String(e.id??crypto.randomUUID()),corporateName:e.corporate_name||"Unknown",amount:Math.abs(Number(e.amount??0)),action:"deduct"===e.action?"deduct":"grant",grantedAt:e.granted_at?new Date(e.granted_at).toLocaleString():"—",previousBalance:Number(e.previous_balance??0),newBalance:Number(e.new_balance??0)})))}catch(e){}},Ee=A.find(e=>e.name===P),Le=(null==Ee?void 0:Ee.states)||[],De=A.find(e=>e.name===Y.country),Pe=(null==De?void 0:De.states)||[],Ue=async()=>{if(!G)return;X(!0);const{error:e}=await h.from("corporates").update({name:Y.name,slug:Yl(Y.name||""),contact_name:Y.contact_name,contact_email:Y.contact_email,contact_phone:Y.contact_phone,website:Y.website,industry:Y.industry,city:Y.city,country:Y.country,state:Y.state,max_users:Y.max_users}).eq("id",G);e?w.error(e.message):(w.success("Corporate updated"),K(null),$e()),X(!1)};return e.jsxs("div",{className:"w-full space-y-6 px-4 sm:px-6 lg:px-8 py-6",style:{fontFamily:"'Inter', 'DM Sans', sans-serif"},children:[e.jsxs(Zl,{icon:Ie,title:"Create New Corporate",description:"Register a new corporate organization",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Corporate Name *"}),e.jsx(Jl,{value:N,onChange:k,placeholder:"Acme Technologies Pvt. Ltd.",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Contact Person *"}
1),e.jsx(Jl,{value:_,onChange:C,placeholder:"John Doe",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Contact Email *"}),e.jsx(Jl,{type:"email",value:B,onChange:T,placeholder:"[email protected]",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Contact Phone *"}),e.jsx(R,{value:S,onChange:$,themeStyles:Se})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Website *"}),e.jsx(Jl,{value:F,onChange:E,placeholder:"https://acme.com",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Industry *"}),e.jsx(Jl,{value:L,onChange:D,placeholder:"Technology",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Country *"}),e.jsx(Xl,{value:P,onValueChange:e=>{U(e),z("")},p:s,children:A.map(t=>e.jsx(v,{value:t.name,children:t.name},t.code))})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"State *"}),Le.length>0?e.jsx(Xl,{value:O,onValueChange:z,placeholder:"Select state",p:s,children:Le.map(t=>e.jsx(v,{value:t,children:t},t))}):e.jsx(Jl,{value:O,onChange:z,placeholder:"Enter state",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"City *"}),e.jsx(Jl,{value:M,onChange:I,placeholder:"Bangalore",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Initial Credit Pool"}),e.jsx(Jl,{type:"number",value:H,onChange:q,placeholder:"0",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Max Users"}),e.jsx(Jl,{type:"number",value:W,onChange:V,placeholder:"50",p:s})]})]}),e.jsx("div",{className:"mt-5",children:e.jsxs(en,{onClick:async()=>{if(!(N&&B&&_&&S&&F&&L&&M&&P&&O))return void w.error("All fields are required");i(!0);const{error:e}=await h.from("corporates").insert({name:N,slug:Yl(N),contact_name:_,contact_email:B,contact_phone:S,website:F,industry:L,city:M,country:P,state:O,credit_pool:parseInt(H)||0,max_users:parseInt(W)||50});e?w.error(e.message):(w.success("Corporate created successfully"),k(""),C(""),T(""),$("+91"),E(""),D(""),I(""),z(""),U("India"),q("0"),V("50"),$e()),i(!1)},disabled:o,p:s,children:[e.jsx(xe,{className:"h-4 w-4"}),o?"Creating...":"Create Corporate"]})})]}),e.jsx(Zl,{icon:Ie,title:"Registered Corporates",description:`${r.length} corporate(s) on platform`,p:s,headerRight:e.jsxs(en,{onClick:$e,disabled:l,p:s,variant:"ghost",children:[e.jsx(re,{className:"h-4 w-4 "+(l?"animate-spin":"")})," Refresh"]}),children:l?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"Loading..."}):0===r.length?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"No corporates registered yet."}):e.jsx("div",{className:"space-y-3",children:r.map(t=>G===t.id?e.jsxs("div",{className:"rounded-xl p-5 space-y-4",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Name"}),e.jsx(Jl,{value:Y.name||"",onChange:e=>J(t=>({...t,name:e})),placeholder:"Corporate name",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Contact Person"}),e.jsx(Jl,{value:Y.contact_name||"",onChange:e=>J(t=>({...t,contact_name:e})),placeholder:"Contact name",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Contact Email"}),e.jsx(Jl,{type:"email",value:Y.contact_email||"",onChange:e=>J(t=>({...t,contact_email:e})),placeholder:"Email",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Phone"}),e.jsx(R,{value:Y.contact_phone||"+91",onChange:e=>J(t=>({...t,contact_phone:e})),themeStyles:Se})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Website"}),e.jsx(Jl,{value:Y.website||"",onChange:e=>J(t=>({...t,website:e})),placeholder:"https://",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Industry"}),e.jsx(Jl,{value:Y.industry||"",onChange:e=>J(t=>({...t,industry:e})),placeholder:"Industry",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Country"}),e.jsx(Xl,{value:Y.country||"India",onValueChange:e=>J(t=>({...t,country:e,state:""})),p:s,children:A.map(t=>e.jsx(v,{value:t.name,children:t.name},t.code))})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"State"}),Pe.length>0?e.jsx(Xl,{value:Y.state||"",onValueChange:e=>J(t=>({...t,state:e})),placeholder:"Select state",p:s,children:Pe.map(t=>e.jsx(v,{value:t,children:t},t))}):e.jsx(Jl,{value:Y.state||"",onChange:e=>J(t=>({...t,state:e})),placeholder:"State",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"City"}),e.jsx(Jl,{value:Y.city||"",onChange:e=>J(t=>({...t,city:e})),placeholder:"City",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Max Users"}),e.jsx(Jl,{type:"number",value:Y.max_users??50,onChange:e=>J(t=>({...t,max_users:parseInt(e)||50})),placeholder:"50",p:s})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(en,{onClick:Ue,disabled:Q,p:s,children:[e.jsx(it,{className:"h-4 w-4"}),Q?"Saving...":"Save"]}),e.jsxs(en,{onClick:()=>K(null),p:s,variant:"ghost",children:[e.jsx(ye,{className:"h-4 w-4"}),"Cancel"]})]})]},t.id):e.jsx(tn,{corp:t,onEdit:()=>{K(t.id),J({name:t.name,contact_name:t.contact_name||"",contact_email:t.contact_email,contact_phone:t.contact_phone||"+91",website:t.website||"",industry:t.industry||"",city:t.city||"",country:t.country||"India",state:t.state||"",max_users:t.max_users})},onToggle:()=>(async e=>{const t=!e.is_active;if(!t){const{count:t}=await h.from("corporate_members").select("id",{count:"exact",head:!0}).eq("corporate_id",e.id).eq("role","admin").eq("status","active");if(!t||0===t)return void w.error("Cannot deactivate: no active admin found for this corporate.")}const{error:s}=await h.from("corporates").update({is_active:t}).eq("id",e.id);s?w.error(s.message):(t?(await h.from("corporate_members").update({status:"active"}).eq("corporate_id",e.id),await h.from("candidate_invitations").update({status:"pending"}).eq("corporate_id",e.id).eq("status","expired").gt("expires_at",(new Date).toISOString())):(await h.from("corporate_members").update({status:"inactive"}).eq("corporate_id",e.id),await h.from("candidate_invitations").update({status:"expired"}
1).eq("corporate_id",e.id).eq("status","pending"),await h.from("candidate_invitations").update({status:"expired"}).eq("corporate_id",e.id).eq("status","invited")),w.success("Corporate "+(t?"activated — all members restored":"deactivated — all members locked")),$e())})(t),p:s},t.id))})}),e.jsxs(Zl,{icon:Re,title:"Create Corporate Admin",description:"Create a new user account and assign them as a corporate admin",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Full Name *"}),e.jsx(Jl,{value:se,onChange:ae,placeholder:"Jane Smith",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Email *"}),e.jsx(Jl,{type:"email",value:Z,onChange:te,placeholder:"[email protected]",p:s})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Phone *"}),e.jsx(R,{value:le,onChange:ne,themeStyles:Se})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Password *"}),e.jsxs("div",{className:"relative",children:[e.jsx(Jl,{type:y?"text":"password",value:oe,onChange:ie,placeholder:"Min 6 characters",p:s}),e.jsx("button",{type:"button",onClick:()=>f(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2",style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:y?e.jsx(He,{className:"h-4 w-4"}):e.jsx(Me,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(Ql,{p:s,children:"Assign to Corporate *"}),e.jsx(Xl,{value:de,onValueChange:ce,placeholder:"Select a corporate...",p:s,children:r.map(t=>e.jsx(v,{value:t.id,children:t.name},t.id))})]})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(en,{onClick:async()=>{var e,t;if(se.trim()&&Z&&le&&!(le.length<5)&&oe&&de)if(oe.length<6)w.error("Password must be at least 6 characters");else{b(!0);try{const s=await h.functions.invoke("corporate-create-admin",{body:{email:Z.trim().toLowerCase(),full_name:se.trim(),phone:le.trim()||null,password:oe,corporate_id:de}});if(s.error)throw s.error;if(null==(e=s.data)?void 0:e.error)throw new Error(s.data.error);const a=(null==(t=r.find(e=>e.id===de))?void 0:t.name)||"";pe(e=>[{email:Z.trim().toLowerCase(),fullName:se.trim(),phone:le,corporateName:a,createdAt:(new Date).toLocaleString()},...e]),w.success(`Admin created for ${a}`),te(""),ae(""),ne("+91"),ie(""),ce(""),await Fe()}catch(s){w.error((null==s?void 0:s.message)||"Failed to create admin")}b(!1)}else w.error("All fields are required")},disabled:g||!se.trim()||!Z||!le||le.length<5||!oe||!de,p:s,children:[e.jsx(Re,{className:"h-4 w-4"}),g?"Creating...":"Create Corporate Admin"]})}),ue.length>0&&e.jsxs("div",{className:"mt-6 space-y-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide",style:{color:s.labelText},children:"Recently Created"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ue.map((t,r)=>e.jsxs("div",{className:"rounded-xl p-4 flex items-start justify-between",style:{background:s.statCardBg,border:`1px solid ${s.statCardBorder}`},children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-3.5 w-3.5",style:{color:s.accentText}}),e.jsx("span",{className:"text-sm font-medium",style:{color:s.bodyText},children:t.fullName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-3.5 w-3.5",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:t.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5",style:{color:s.mutedText}}),e.jsx("span",{className:"text-xs",style:{color:s.mutedText},children:t.corporateName})]})]}),e.jsx("button",{type:"button",onClick:()=>pe(e=>e.filter((e,t)=>t!==r)),style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]},r))})]})]}),e.jsx(Zl,{icon:_e,title:"Existing Corporate Admins",description:`${me.length} admin(s) across all corporates`,p:s,headerRight:e.jsxs(en,{onClick:Fe,disabled:ge,p:s,variant:"ghost",children:[e.jsx(re,{className:"h-4 w-4 "+(ge?"animate-spin":"")})," Refresh"]}),children:ge?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText},children:"Loading..."}):0===me.length?e.jsx("p",{className:"text-sm py-4 text-center",style:{color:s.mutedText}
1,children:"No corporate admins found."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:me.map(t=>fe===t.id?e.jsx(rn,{admin:t,onSave:e=>(async(e,t)=>{const{error:s}=await h.from("profiles").update({full_name:t.full_name,mobile_number:t.phone}).eq("user_id",e.user_id);s?w.error(s.message):(w.success("Admin updated"),ve(null),he(s=>s.map(s=>s.id===e.id?{...s,full_name:t.full_name,email:t.email,phone:t.phone}:s)))})(t,e),onCancel:()=>ve(null),p:s},t.id):e.jsx(sn,{admin:t,onToggle:()=>(async e=>{const t="inactive"!==e.status?"inactive":"active",{error:s}=await h.from("corporate_members").update({status:t}).eq("id",e.id);s?w.error(s.message):(w.success("Admin "+("active"===t?"activated":"deactivated")),he(s=>s.map(s=>s.id===e.id?{...s,status:t}:s)))})(t),onEdit:()=>ve(t.id),p:s},t.id))})}),e.jsxs(Zl,{icon:Ce,title:"Manage Corporate Credits",description:"Grant or deduct credits from a corporate's shared pool",p:s,children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Corporate"}),e.jsx(Xl,{value:je,onValueChange:we,placeholder:"Select a corporate...",p:s,children:r.map(t=>e.jsxs(v,{value:t.id,children:[t.name," (Pool: ",t.credit_pool??0,")"]},t.id))})]}),e.jsxs("div",{children:[e.jsx(Ql,{p:s,children:"Credit Amount"}),e.jsx(Jl,{type:"number",value:Ne,onChange:ke,placeholder:"500",p:s})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-3",children:[e.jsxs(en,{onClick:async()=>{const e=parseInt(Ne,10);if(!je||!e||e<=0)w.error("Select a corporate and enter a valid amount");else{u(!0);try{const{data:{session:t}}=await h.auth.getSession();if(!(null==t?void 0:t.access_token))throw new Error("Session expired");const{data:s,error:a}=await h.functions.invoke("corporate-grant-credits",{body:{action:"grant",corporate_id:je,amount:e},headers:{Authorization:`Bearer ${t.access_token}`}});if(a)throw a;if(null==s?void 0:s.error)throw new Error(s.error);const l=null==s?void 0:s.transaction;l&&Te(t=>{var s;return[{id:String(l.id??crypto.randomUUID()),corporateName:l.corporate_name||(null==(s=r.find(e=>e.id===je))?void 0:s.name)||"Unknown",amount:Math.abs(Number(l.amount??e)),action:"grant",grantedAt:l.granted_at?new Date(l.granted_at).toLocaleString():(new Date).toLocaleString(),previousBalance:Number(l.previous_balance??0),newBalance:Number(l.new_balance??0)},...t]}),w.success(`${e} credits granted successfully`),ke(""),we(""),await Promise.all([$e(),Ae()])}catch(t){w.error((null==t?void 0:t.message)||"Grant failed")}u(!1)}},disabled:d||x,p:s,children:[e.jsx(Ce,{className:"h-4 w-4"}),d?"Granting...":"Grant Credits"]}),e.jsxs("button",{type:"button",onClick:async()=>{const e=parseInt(Ne,10);if(!je||!e||e<=0)w.error("Select a corporate and enter a valid amount");else{p(!0);try{const{data:{session:t}}=await h.auth.getSession();if(!(null==t?void 0:t.access_token))throw new Error("Session expired");const{data:s,error:a}=await h.functions.invoke("corporate-grant-credits",{body:{action:"deduct",corporate_id:je,amount:e},headers:{Authorization:`Bearer ${t.access_token}`}});if(a)throw a;if(null==s?void 0:s.error)throw new Error(s.error);const l=null==s?void 0:s.transaction;l&&Te(t=>{var s;return[{id:String(l.id??crypto.randomUUID()),corporateName:l.corporate_name||(null==(s=r.find(e=>e.id===je))?void 0:s.name)||"Unknown",amount:Math.abs(Number(l.amount??e)),action:"deduct",grantedAt:l.granted_at?new Date(l.granted_at).toLocaleString():(new Date).toLocaleString(),previousBalance:Number(l.previous_balance??0),newBalance:Number(l.new_balance??0)},...t]}),w.success(`${e} credits deducted successfully`),ke(""),we(""),await Promise.all([$e(),Ae()])}catch(t){w.error((null==t?void 0:t.message)||"Deduct failed")}p(!1)}},disabled:d||x,style:{display:"inline-flex",alignItems:"center",gap:8,padding:"10px 18px",borderRadius:10,fontSize:14,fontWeight:600,cursor:d||x?"not-allowed":"pointer",opacity:d||x?.6:1,background:`${s.redAccent}1f`,color:s.redAccent,border:`1.5px solid ${s.redAccent}66`,transition:"all 0.18s ease"},children:[e.jsx(ct,{className:"h-4 w-4"}),x?"Deducting...":"Deduct Credits"]})]}),Be.length>0&&e.jsxs("div",{className:"mt-6 space-y-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide",style:{color:s.labelText},children:"Recent Activity"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:Be.map(t=>{const r="deduct"===t.action,a=r?s.redAccent:s.greenAccent,l=r?"248,113,113":"52,211,153";return e.jsxs("div",{className:"rounded-xl p-4 flex items-start justify-between",style:{background:`rgba(${l},0.07)`,border:`1px solid rgba(${l},0.18)`},children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5",
1style:{color:s.mutedText}}),e.jsx("span",{className:"text-sm font-medium",style:{color:s.bodyText},children:t.corporateName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(ct,{className:"h-3.5 w-3.5",style:{color:a}}):e.jsx(We,{className:"h-3.5 w-3.5",style:{color:a}}),e.jsxs("span",{className:"text-sm font-bold",style:{color:a},children:[r?"−":"+",t.amount," credits"]})]}),e.jsxs("span",{className:"text-xs",style:{color:s.mutedText},children:[t.previousBalance," → ",t.newBalance," · ",t.grantedAt]})]}),e.jsx("button",{type:"button",onClick:()=>Te(e=>e.filter(e=>e.id!==t.id)),style:{color:s.mutedText,background:"none",border:"none",cursor:"pointer"},children:e.jsx(ye,{className:"h-4 w-4"})})]},t.id)})})]})]})]})};var ln="Toggle",nn=c.forwardRef((t,r)=>{const{pressed:a,defaultPressed:l,onPressedChange:n,...o}=t,[c,u]=i({prop:a,onChange:n,defaultProp:l??!1,caller:ln});return e.jsx(s.button,{type:"button","aria-pressed":c,"data-state":c?"on":"off","data-disabled":t.disabled?"":void 0,...o,ref:r,onClick:d(t.onClick,()=>{t.disabled||u(!c)})})});nn.displayName=ln;var on=nn;const dn=E("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}}),cn=c.forwardRef(({className:t,variant:s,size:r,...a},l)=>e.jsx(on,{ref:l,className:x(dn({variant:s,size:r,className:t})),...a}));cn.displayName=on.displayName;const un={bold:!1,italic:!1,underline:!1,unorderedList:!1,orderedList:!1,alignLeft:!0,alignCenter:!1,h1:!1,h2:!1,h3:!1},xn=({value:t,onChange:s,placeholder:r})=>{const a=c.useRef(null),[l,n]=c.useState(un),o=c.useMemo(()=>{var e,s,r;return!(null==(r=null==(s=null==(e=null==t?void 0:t.replace(/<p><br><\/p>/g,""))?void 0:e.replace(/&nbsp;/g," "))?void 0:s.replace(/<[^>]*>/g,""))?void 0:r.trim())},[t]),i=()=>{const e=window.getSelection(),t=null==e?void 0:e.anchorNode,s=a.current;if(!s||!t||!s.contains(t))return void n(e=>({...e,alignLeft:!e.alignCenter}));const r=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,l=e=>null==r?void 0:r.closest(e),o=r?window.getComputedStyle(r).textAlign:"left";n({bold:!!l("b, strong"),italic:!!l("i, em"),underline:!!l("u"),unorderedList:!!l("ul"),orderedList:!!l("ol"),alignLeft:"center"!==o,alignCenter:"center"===o,h1:!!l("h1"),h2:!!l("h2"),h3:!!l("h3")})};c.useEffect(()=>{const e=a.current;e&&e.innerHTML!==t&&(e.innerHTML=t||"")},[t]),c.useEffect(()=>{const e=()=>i();return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[]);const d=()=>{var e;return null==(e=a.current)?void 0:e.focus()},u=()=>{var e;s((null==(e=a.current)?void 0:e.innerHTML)||""),i()},x=(e,t)=>{d(),document.execCommand(e,!1,t),u()},p=e=>{var t;d();const s=null==(t=document.queryCommandValue("formatBlock"))?void 0:t.toString().toUpperCase();document.execCommand("formatBlock",!1,s===e?"P":e),u()};return e.jsxs("div",{className:"rounded-md border border-input bg-background",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-0.5 border-b border-input px-2 py-1.5",children:[e.jsx(cn,{size:"sm",pressed:l.bold,onPressedCh
1ange:()=>x("bold"),"aria-label":"Bold",children:e.jsx(ut,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.italic,onPressedChange:()=>x("italic"),"aria-label":"Italic",children:e.jsx(xt,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.underline,onPressedChange:()=>x("underline"),"aria-label":"Underline",children:e.jsx(pt,{className:"h-4 w-4"})}),e.jsx("div",{className:"mx-1 h-5 w-px bg-border"}),e.jsx(cn,{size:"sm",pressed:l.h1,onPressedChange:()=>p("H1"),"aria-label":"Heading 1",children:e.jsx(mt,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.h2,onPressedChange:()=>p("H2"),"aria-label":"Heading 2",children:e.jsx(ht,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.h3,onPressedChange:()=>p("H3"),"aria-label":"Heading 3",children:e.jsx(gt,{className:"h-4 w-4"})}),e.jsx("div",{className:"mx-1 h-5 w-px bg-border"}),e.jsx(cn,{size:"sm",pressed:l.unorderedList,onPressedChange:()=>x("insertUnorderedList"),"aria-label":"Bullet List",children:e.jsx(bt,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.orderedList,onPressedChange:()=>x("insertOrderedList"),"aria-label":"Ordered List",children:e.jsx(yt,{className:"h-4 w-4"})}),e.jsx("div",{className:"mx-1 h-5 w-px bg-border"}),e.jsx(cn,{size:"sm",pressed:l.alignLeft,onPressedChange:()=>x("justifyLeft"),"aria-label":"Align Left",children:e.jsx(ft,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",pressed:l.alignCenter,onPressedChange:()=>x("justifyCenter"),"aria-label":"Align Center",children:e.jsx(vt,{className:"h-4 w-4"})}),e.jsx("div",{className:"mx-1 h-5 w-px bg-border"}),e.jsx(cn,{size:"sm",onPressedChange:()=>x("undo"),"aria-label":"Undo",children:e.jsx(jt,{className:"h-4 w-4"})}),e.jsx(cn,{size:"sm",onPressedChange:()=>x("redo"),"aria-label":"Redo",children:e.jsx(wt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative",children:[o&&r?e.jsx("div",{className:"pointer-events-none absolute left-3 top-2 text-sm text-muted-foreground",children:r}):null,e.jsx("div",{ref:a,contentEditable:!0,suppressContentEditableWarning:!0,onInput:u,onBlur:u,className:"min-h-[150px] px-3 py-2 text-sm focus:outline-none prose prose-sm max-w-none [&_h1]:text-2xl [&_h1]:font-bold [&_h2]:text-xl [&_h2]:font-semibold [&_h3]:text-lg [&_h3]:font-medium [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5"})]})]})},pn={dark:{cardBg:"rgba(255,255,255,0.04)",cardBorder:"rgba(255,255,255,0.09)",cardHoverBg:"rgba(255,255,255,0.06)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.65)",mutedText:"rgba(255,255,255,0.38)",labelText:"rgba(255,255,255,0.55)",accentText:"#a78bfa",inputBg:"rgba(255,255,255,0.05)",inputBorder:"rgba(255,255,255,0.12)",inputFocusBorder:"rgba(139,92,246,0.70)",inputText:"#ffffff",divider:"rgba(255,255,255,0.07)",iconBg:"rgba(139,92,246,0.16)",shimmer:"rgba(255,255,255,0.06)",badgeActiveBg:"rgba(16,185,129,0.14)",badgeActiveText:"#6ee7b7",badgeActiveBorder:"rgba(16,185,129,0.30)",badgeInactiveBg:"rgba(255,255,255,0.06)",badgeInactiveText:"rgba(255,255,255,0.38)",badgeInactiveBorder:"rgba(255,255,255,0.12)",btnPrimaryBg:"linear-gradient(135deg, #5b21b6 0%, #7c3aed 100%)",btnPrimaryBorder:"rgba(139,92,246,0.55)",btnPrimaryText:"#ffffff",btnGhostBg:"rgba(255,255,255,0.05)",btnGhostBorder:"rgba(255,255,255,0.12)",btnGhostText:"rgba(255,255,255,0.65)",btnDestructBg:"rgba(239,68,68,0.12)",btnDestructBorder:"rgba(239,68,68,0.28)",btnDestructText:"#fca5a5",tableHeadText:"rgba(255,255,255,0.45)",tableRowHover:"rgba(255,255,255,0.04)",tableBorder:"rgba(255,255,255,0.07)",tagBg:"rgba(255,255,255,0.07)",tagText:"rgba(255,255,255,0.55)"},light:{cardBg:"rgba(255,255,255,0.07)",cardBorder:"rgba(255,255,255,0.14)",cardHoverBg:"rgba(255,255,255,0.10)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.80)",mutedText:"rgba(255,255,255,0.50)",labelText:"rgba(255,255,255,0.65)",accentText:"#c4b5fd",inputBg:"rgba(255,255,255,0.08)",inputBorder:"rgba(255,255,255,0.18)",inputFocusBorder:"rgba(167,139,250,0.80)",inputText:"#ffffff",divider:"rgba(255,255,255,0.12)",iconBg:"rgba(167,139,250,0.20)",shimmer:"rgba(255,255,255,0.10)",badgeActiveBg:"rgba(16,185,129,0.18)",badgeActiveText:"#a7f3d0",badgeActiveBorder:"rgba(16,185,129,0.35)",badgeInactiveBg:"rgba(255,255,255,0.08)",badgeInactiveText:"rgba(255,255,255,0.45)",badgeInactiveBorder:"rgba(255,255,255,0.18)",btnPrimaryBg:"linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%)",btnPrimaryBorder:"rgba(167,139,250,0.65)",btnPrimaryText:"#ffffff",btnGhostBg:"rgba(255,255,255,0.08)",btnGhostBorder:"rgba(255,255,255,0.18)",btnGhostText:"rgba(255,255,255,0.75)",btnDestructBg:"rgba(239,68,68,0.16)",btnDestructBorder:"rgba(239,68,68,0.35)",btnDestructText:"#fecaca",tableHeadText:"rgba(255,255,255,0.55)",tableRowHover:"rgba(255,255,255,0.06)",tableBorder:"rgba(255,255,255,0.10)",tagBg:"rgba(255,255,255,0.10)",tagText:"rgba(255,255,255,0.65)"}},mn=({value:t,onChange:s,placeholder:r,type:a="text",p:l,className:n=""})=>{const[o,i]=c.useState(!1);return e.jsx("input",{type:a,value:t,onChange:e=>s(e.target.value),placeholder:r,onFocus:()=>i(!0),onBlur:()=>i(!1),className:`w-full rounded-xl px-3.5 py-2.5 text-sm outline-none transition-all duration-200 ${n}`,style:{background:l.inputBg,border:`1px solid ${o?l.inputFocusBorder:l.inputBorder}`,color:l.inputText,fontFamily:"'Inter', sans-serif",boxShadow:o?`0 0 0 3px ${l.inputFocusBorder}22`:"none"}})},hn=({value:t,onValueChange:s,options:r,p:a})=>e.jsxs(g,{value:t,onValueChange:s,children:[e.jsx(b,{className:"rounded-xl border outline-none text-sm",style:{background:a.inputBg,borderColor:a.inputBorder,color:a.inputText},children:e.jsx(y,{})}),e.jsx(f,{children:r.map(t=>e.jsx(v,{value:t.value,children:t.label},t.value))})]}),gn=[{value:"full-time",label:"Full-time"},{value:"part-time",label:"Part-time"},{value:"contract",label:"Contract"},{value:"internship",label:"Internship"}],bn={title:"",description:"",location:"",employment_type:"full-time",department:"",experience_level:"",valid_until:""},yn=({form:t,setForm:s,p:r})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Job Title *"}),e.jsx(mn,{value:t.title,onChange:e=>s({...t,title:e}),placeholder:"e.g. Senior Frontend Developer",p:r})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Description *"}),e.jsx(xn,{value:t.description,onChange:e=>s({...t,description:e}),placeholder:"Job description, responsibilities, requirements..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Location"}),e.jsx(mn,{value:t.location,onChange:e=>s({...t,location:e}),placeholder:"Remote / Bangalore",p:r})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Type"}),e.jsx(hn,{value:t.employment_type,onValueChange:e=>s({...t,employment_type:e}),options:gn,p:r})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Department"}),e.jsx(mn,{value:t.department,onChange:e=>s({...t,department:e}),placeholder:"Engineering",p:r})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Experience"}),e.jsx(mn,{value:t.experience_level,onChange:e=>s({...t,experience_level:e}),placeholder:"3–5 years",p:r})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:r.labelText,fontFamily:"'Roboto Slab', serif"},children:"Valid Until"}
1),e.jsx(mn,{type:"date",value:t.valid_until,onChange:e=>s({...t,valid_until:e}),p:r})]})]}),fn=({showCreateDialog:t,setShowCreateDialog:s})=>{const{resolvedTheme:r}=m(),a="light"===r?pn.light:pn.dark,[l,n]=c.useState([]),[o,i]=c.useState(!0),[d,u]=c.useState(null),[x,p]=c.useState(!1),[g,b]=c.useState({...bn}),[y,f]=c.useState(null),[v,j]=c.useState({...bn}),[w,N]=c.useState(!1),[_,S]=c.useState(null),[$,F]=c.useState(!1),A=async()=>{i(!0);const{data:e,error:t}=await h.from("jobs").select("*").order("created_at",{ascending:!1});t?D({title:"Error fetching jobs",description:t.message,variant:"destructive"}):n(e||[]),i(!1)};c.useEffect(()=>{A()},[]);const R={background:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",border:`1px solid ${a.cardBorder}`,backdropFilter:"blur(20px)",color:a.headlineColor};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(k,{open:t,onOpenChange:s,children:e.jsxs(C,{className:"max-w-lg max-h-[90vh] overflow-y-auto",style:R,children:[e.jsx(B,{children:e.jsx(T,{style:{color:a.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Create Job Posting"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx(yn,{form:g,setForm:b,p:a}),e.jsxs("button",{onClick:async()=>{var e;if(!g.title.trim()||!g.description.trim())return void D({title:"Title and Description are required",variant:"destructive"});p(!0);const{data:t}=await h.auth.getUser(),{error:r}=await h.from("jobs").insert({title:g.title.trim(),description:g.description.trim(),location:g.location.trim()||null,employment_type:g.employment_type,department:g.department.trim()||null,experience_level:g.experience_level.trim()||null,valid_until:g.valid_until||null,created_by:null==(e=null==t?void 0:t.user)?void 0:e.id});r?D({title:"Error creating job",description:r.message,variant:"destructive"}):(D({title:"Job posting created"}),b({...bn}),s(!1),A()),p(!1)},disabled:x,className:"w-full mt-5 flex items-center justify-center gap-2 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200 disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",style:{background:a.btnPrimaryBg,border:`1px solid ${a.btnPrimaryBorder}`,color:a.btnPrimaryText},children:[x?e.jsx(K,{className:"w-4 h-4 animate-spin"}):e.jsx(xe,{className:"w-4 h-4"}),x?"Creating…":"Create Job Posting"]})]})]})}),e.jsx(k,{open:!!y,onOpenChange:()=>f(null),children:e.jsxs(C,{className:"max-w-lg max-h-[90vh] overflow-y-auto",style:R,children:[e.jsx(B,{children:e.jsx(T,{style:{color:a.headlineColor,fontFamily:"'Roboto Slab', serif"},children:"Edit Job Posting"})}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx(yn,{form:v,setForm:j,p:a}),e.jsxs("button",{onClick:async()=>{if(!y)return;if(!v.title.trim()||!v.description.trim())return void D({title:"Title and Description are required",variant:"destructive"});N(!0);const{error:e}=await h.from("jobs").update({title:v.title.trim(),description:v.description.trim(),location:v.location.trim()||null,employment_type:v.employment_type,department:v.department.trim()||null,experience_level:v.experience_level.trim()||null,valid_until:v.valid_until||null}).eq("id",y.id);e?D({title:"Error updating job",description:e.message,variant:"destructive"}):(D({title:"Job updated"}),f(null),A()),N(!1)},disabled:w,className:"w-full flex items-center justify-center gap-2 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200 disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/40",style:{background:a.btnPrimaryBg,border:`1px solid ${a.btnPrimaryBorder}`,color:a.btnPrimaryText},children:[w?e.jsx(K,{className:"w-4 h-4 animate-spin"}):e.jsx(Y,{className:"w-4 h-4"}),w?"Updating…":"Update Job Posting"]}),e.jsx(L,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center justify-center gap-2 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200",style:{background:a.btnGhostBg,border:`1px solid ${a.btnGhostBorder}`,color:a.btnGhostText},children:[e.jsx(De,{className:"w-4 h-4"}),"Cancel"]})})]})]})}),o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(K,{className:"w-8 h-8 animate-spin",style:{color:a.accentText}})}):0===l.length?e.jsxs("div",{className:"flex flex-col items-center justify-center py-14 roun
1ded-2xl gap-3",style:{background:a.cardBg,border:`1px solid ${a.cardBorder}`},children:[e.jsx(Pe,{className:"w-10 h-10 opacity-25",style:{color:a.accentText}}),e.jsx("p",{className:"text-sm",style:{color:a.mutedText,fontFamily:"'Roboto Slab', serif"},children:"No job postings yet"})]}):e.jsx("div",{className:"space-y-3",children:l.map(t=>e.jsx("div",{className:"relative overflow-hidden rounded-2xl p-4 sm:p-5 transition-all duration-200",style:{background:a.cardBg,border:`1px solid ${a.cardBorder}`,backdropFilter:"blur(10px)"},onMouseEnter:e=>e.currentTarget.style.background=a.cardHoverBg,onMouseLeave:e=>e.currentTarget.style.background=a.cardBg,children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsx("h4",{className:"text-base font-bold truncate",style:{color:a.headlineColor,fontFamily:"'Roboto Slab', serif"},children:t.title}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider",style:{background:t.is_active?a.badgeActiveBg:a.badgeInactiveBg,color:t.is_active?a.badgeActiveText:a.badgeInactiveText,border:`1px solid ${t.is_active?a.badgeActiveBorder:a.badgeInactiveBorder}`},children:[t.is_active?e.jsx(Y,{className:"w-2.5 h-2.5"}):e.jsx(De,{className:"w-2.5 h-2.5"}),t.is_active?"Active":"Inactive"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-1.5",children:[t.location&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-lg",style:{background:a.tagBg,color:a.tagText},children:[e.jsx(Nt,{className:"w-3 h-3","aria-hidden":!0})," ",t.location]}),t.employment_type&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-lg",style:{background:a.tagBg,color:a.tagText},children:[e.jsx(Pe,{className:"w-3 h-3","aria-hidden":!0})," ",t.employment_type]}),t.department&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-lg",style:{background:a.tagBg,color:a.tagText},children:[e.jsx(Ie,{className:"w-3 h-3","aria-hidden":!0})," ",t.department]}),t.valid_until&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-lg",style:{background:a.tagBg,color:a.tagText},children:[e.jsx(we,{className:"w-3 h-3","aria-hidden":!0})," ",St(new Date(t.valid_until),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0",children:[e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none text-xs",style:{color:a.mutedText},children:[e.jsx(Ft,{checked:t.is_active,onCheckedChange:()=>(async e=>{const{error:t}=await h.from("jobs").update({is_active:!e.is_active}).eq("id",e.id);t?D({title:"Error updating job",description:t.message,variant:"destructive"}):A()})(t)}),e.jsx("span",{children:t.is_active?"On":"Off"})]}),e.jsxs("button",{onClick:()=>(e=>{f(e),j({title:e.title,description:e.description,location:e.location||"",employment_type:e.employment_type||"full-time",department:e.department||"",experience_level:e.experience_level||"",valid_until:e.valid_until?e.valid_until.split("T")[0]:""})})(t),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150",style:{background:a.btnGhostBg,border:`1px solid ${a.btnGhostBorder}`,color:a.btnGhostText},children:[e.jsx(qe,{className:"w-3.5 h-3.5"})," Edit"]}),e.jsxs("button",{onClick:()=>(async e=>{const{data:t,error:s}=await h.from("job_applications").select("*").eq("job_id",e.id).order("applied_at",{ascending:!1});s?D({title:"Error fetching applications",description:s.message,variant:"destructive"}):u({jobTitle:e.title,apps:t||[]})})(t),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150",style:{background:a.btnGhostBg,border:`1px solid ${a.btnGhostBorder}`,color:a.btnGhostText},children:[e.jsx(ce,{className:"w-3.5 h-3.5"})," Applications"]}),e.jsxs("button",{onClick:()=>(async e=>{if(!confirm(`Delete "${e.title}"? This cannot be undone.`))return;S(e.id);const{error:t}=await h.from("jobs").delete().eq("id",e.id);t?D({title:"Error deleting job",description:t.message,variant:"destructive"}):(D({title:"Job deleted"}),A()),S(null)})(t),disabled:_===t.id,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150 disabled:opacity-60",style:{background:a.btnDestructBg,border:`1px solid ${a.btnDestructBorder}`,color:a.btnDestructText},children:[_===t.id?e.jsx(K,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ge,{className:"w-3.5 h-3.5"}),_===t.id?"…":"Delete"]})]})]})},t.id))}),e.jsx(k,{open:!!d,onOpenChange:()=>u(null),children:e.jsxs(C,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",style:R,children:[e.jsx(B,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs(T,{style:{color:a.headlineColor,fontFamily:"'Roboto Slab', serif"},children:["Applications — ",null==d?void 0:d.jobTitle]}),d&&d.apps.length>0&&e.jsxs("button",{onClick:async()=>
1{if(d&&0!==d.apps.length){F(!0);try{const e=[["Name","Email","Phone","LinkedIn","Resume Link","Applied Date"]];for(const l of d.apps){let t="";if(l.resume_path){const{data:e}=await h.storage.from("career-resumes").createSignedUrl(l.resume_path,604800);(null==e?void 0:e.signedUrl)&&(t=e.signedUrl)}e.push([l.candidate_name,l.candidate_email,l.candidate_phone,l.linkedin_url||"",t,St(new Date(l.applied_at),"MMM dd, yyyy")])}const t=e.map(e=>e.map(e=>`"${e.replace(/"/g,'""')}"`).join(",")).join("\n"),s=new Blob([t],{type:"text/csv;charset=utf-8;"}),r=URL.createObjectURL(s),a=document.createElement("a");a.href=r,a.download=`Applications - ${d.jobTitle}.csv`,a.click(),URL.revokeObjectURL(r),D({title:"CSV exported"})}catch(e){D({title:"Export failed",description:e.message,variant:"destructive"})}finally{F(!1)}}},disabled:$,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150 disabled:opacity-60",style:{background:a.btnGhostBg,border:`1px solid ${a.btnGhostBorder}`,color:a.btnGhostText},children:[$?e.jsx(K,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(se,{className:"w-3.5 h-3.5"}),$?"Exporting…":"Download CSV"]})]})}),0===(null==d?void 0:d.apps.length)?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(ce,{className:"w-8 h-8 opacity-25",style:{color:a.accentText}}),e.jsx("p",{className:"text-sm",style:{color:a.mutedText},children:"No applications received yet"})]}):e.jsx("div",{className:"overflow-x-auto mt-2",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{style:{borderBottom:`1px solid ${a.tableBorder}`},children:["Name","Email","Phone","LinkedIn","Resume","Applied"].map(t=>e.jsx("th",{className:"text-left px-3 py-2 text-xs font-bold uppercase tracking-wider",style:{color:a.tableHeadText,fontFamily:"'Roboto Slab', serif"},children:t},t))})}),e.jsx("tbody",{children:null==d?void 0:d.apps.map(t=>e.jsxs("tr",{style:{borderBottom:`1px solid ${a.tableBorder}`},onMouseEnter:e=>e.currentTarget.style.background=a.tableRowHover,onMouseLeave:e=>e.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"px-3 py-2.5 font-medium",style:{color:a.headlineColor},children:t.candidate_name}),e.jsx("td",{className:"px-3 py-2.5",style:{color:a.bodyText},children:t.candidate_email}),e.jsx("td",{className:"px-3 py-2.5",style:{color:a.bodyText}
1,children:t.candidate_phone}),e.jsx("td",{className:"px-3 py-2.5",children:t.linkedin_url?e.jsx("a",{href:t.linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs underline",style:{color:a.accentText},children:"View"}):e.jsx("span",{style:{color:a.mutedText},children:"—"})}),e.jsx("td",{className:"px-3 py-2.5",children:t.resume_path?e.jsxs("button",{onClick:()=>(async(e,t)=>{const{data:s,error:r}=await h.storage.from("career-resumes").download(e);if(r)return void D({title:"Error downloading resume",description:r.message,variant:"destructive"});const a=URL.createObjectURL(s),l=document.createElement("a");l.href=a,l.download=t||"resume",l.click(),URL.revokeObjectURL(a)})(t.resume_path,t.resume_filename),className:"flex items-center gap-1 text-xs px-2 py-1 rounded-lg transition-all",style:{background:a.btnGhostBg,color:a.accentText,border:`1px solid ${a.btnGhostBorder}`},children:[e.jsx(se,{className:"w-3 h-3"})," ",t.resume_filename||"Download"]}):e.jsx("span",{style:{color:a.mutedText},children:"—"})}),e.jsx("td",{className:"px-3 py-2.5 text-xs",style:{color:a.mutedText},children:St(new Date(t.applied_at),"MMM d, yyyy")})]},t.id))})]})})]})})]})},vn=()=>{const{toast:t}=p(),[s,r]=c.useState(!0),[a,l]=c.useState(!0),[n,o]=c.useState(!1),[i,d]=c.useState(null),[u,x]=c.useState(5),[m,g]=c.useState(10),[b,y]=c.useState(!1);c.useEffect(()=>{let e=!1;return(async()=>{var s,a,n;l(!0);const[o,i]=await Promise.all([h.from("platform_settings").select("value, updated_at").eq("key","free_user_report_gate").maybeSingle(),h.from("platform_settings").select("value").eq("key","action_plan_credit_cost").maybeSingle()]);if(e)return;if(o.error)t({title:"Failed to load settings",description:o.error.message,variant:"destructive"});else{const e=null==(s=o.data)?void 0:s.value;r((null==e?void 0:e.enabled)??!0),d((null==(a=o.data)?void 0:a.updated_at)??null)}const c=(null==(n=i.data)?void 0:n.value)??{};x(c["7_day"]??5),g(c["15_day"]??10),l(!1)})(),()=>{e=!0}},[t]);return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 p-6 backdrop-blur-md",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-violet-500 to-fuchsia-500 shadow-lg shadow-violet-500/30",children:e.jsx(kt,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-base font-semibold text-white",children:"Free-User Report Gate"}),e.jsxs("p",{className:"mt-1 text-sm text-white/60",children:["When ON, users who have never purchased credits see only the"," ",e.jsx("span",{className:"text-white/85",children:"Overall Score"})," and"," ",e.jsx("span",{className:"text-white/85",children:"Communication"})," insights. Domain Skills, Structural Thinking, Job Alignment, and the full transcript are blurred with a CTA to purchase. When OFF, all users see the full report."]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[(a||n)&&e.jsx(K,{className:"h-4 w-4 animate-spin text-white/60"}),e.jsx(Ft,{checked:s,onCheckedChange:async e=>{var a;o(!0);const l=s;r(e);const{data:n}=await h.auth.getUser(),{error:i,data:c}=await h.from("platform_settings").update({value:{enabled:e},updated_by:(null==(a=null==n?void 0:n.user)?void 0:a.id)??null}).eq("key","free_user_report_gate").select("updated_at").maybeSingle();i?(r(l),t({title:"Failed to save",description:i.message,variant:"destructive"})):(d((null==c?void 0:c.updated_at)??(new Date).toISOString()),t({title:e?"Report gate enabled":"Report gate disabled",description:e?"Free users now see only Communication + Overall Score.":"All users now see the full report."})),o(!1)},disabled:a||n,"aria-label":"Toggle free-user report gate"})]})]}),e.jsxs("div",{className:"mt-5 flex items-center gap-2 rounded-xl border border-white/8 bg-white/3 px-4 py-3 text-xs text-white/55",children:[e.jsx(_t,{className:"h-3.5 w-3.5 text-emerald-400"}),e.jsxs("span",{children:["Status:"," ",e.jsx("span",{className:"font-semibold text-white/85",children:s?"Active — free users see locked report":"Disabled — all users see full report"}),i&&e.jsxs(e.Fragment,{children:[" ","· Last updated ",new Date(i).toLocaleStr
1ing()]})]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 p-6 backdrop-blur-md",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-amber-500 to-orange-500 shadow-lg shadow-amber-500/30",children:e.jsx(Ct,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-base font-semibold text-white",children:"AI Action Plan — Credit Cost"}),e.jsx("p",{className:"mt-1 text-sm text-white/60",children:"Configure how many credits are deducted when individuals or college students generate a personalized improvement plan."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx(N,{htmlFor:"cost7",className:"text-white/80 text-xs",children:"7-Day Plan (credits)"}),e.jsx(M,{id:"cost7",type:"number",min:1,max:500,value:u,onChange:e=>x(Math.max(1,parseInt(e.target.value||"1",10))),className:"mt-1 bg-white/5 border-white/15 text-white",disabled:a||b})]}),e.jsxs("div",{children:[e.jsx(N,{htmlFor:"cost15",className:"text-white/80 text-xs",children:"15-Day Plan (credits)"}),e.jsx(M,{id:"cost15",type:"number",min:1,max:500,value:m,onChange:e=>g(Math.max(1,parseInt(e.target.value||"1",10))),className:"mt-1 bg-white/5 border-white/15 text-white",disabled:a||b})]})]}),e.jsxs(F,{onClick:async()=>{var e;y(!0);const{data:s}=await h.auth.getUser(),{error:r}=await h.from("platform_settings").upsert({key:"action_plan_credit_cost",value:{"7_day":u,"15_day":m},updated_by:(null==(e=null==s?void 0:s.user)?void 0:e.id)??null},{onConflict:"key"});t(r?{title:"Failed to save",description:r.message,variant:"destructive"}:{title:"Action plan costs updated",description:`7-day: ${u} · 15-day: ${m} credits`}),y(!1)},disabled:a||b,className:"bg-gradient-to-r from-amber-500 to-orange-500 hover:opacity-90",children:[b&&e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Action Plan Costs"]})]})]})},jn={dark:{sectionBg:"linear-gradient(160deg, #15002B 0%, #2A044C 50%, #1A0235 100%)",cardBg:"rgba(255,255,255,0.04)",cardBorder:"rgba(255,255,255,0.09)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.65)",mutedText:"rgba(255,255,255,0.38)",labelText:"rgba(255,255,255,0.40)",accentText:"#a78bfa",accentBg:"rgba(139,92,246,0.18)",accentBorder:"rgba(139,92,246,0.40)",divider:"rgba(255,255,255,0.07)",gridLine:"rgba(255,255,255,0.022)",destructiveBg:"rgba(239,68,68,0.10)",destructiveBorder:"rgba(239,68,68,0.30)",destructiveText:"#fca5a5",inputBg:"rgba(255,255,255,0.06)",inputBorder:"rgba(255,255,255,0.14)"},light:{sectionBg:"linear-gradient(160deg, #2D0550 0%, #5B1280 50%, #3D0A6E 100%)",cardBg:"rgba(255,255,255,0.07)",cardBorder:"rgba(255,255,255,0.14)",headlineColor:"#ffffff",bodyText:"rgba(255,255,255,0.80)",mutedText:"rgba(255,255,255,0.50)",labelText:"rgba(255,255,255,0.55)",accentText:"#c4b5fd",accentBg:"rgba(167,139,250,0.20)",accentBorder:"rgba(167,139,250,0.50)",divider:"rgba(255,255,255,0.14)",gridLine:"rgba(255,255,255,0.038)",destructiveBg:"rgba(239,68,68,0.12)",destructiveBorder:"rgba(239,68,68,0.35)",destructiveText:"#fca5a5",inputBg:"rgba(255,255,255,0.10)",inputBorder:"rgba(255,255,255,0.22)"}},wn=[{value:"analytics",label:"Platform Analytics",group:"Analytics"},{value:"revenue",label:"Revenue Analytics",group:"Analytics"},{value:"interview-insights",label:"Interview Insights",group:"Analytics"},{value:"system-health",label:"System Health",group:"Analytics"},{value:"user-feedback",label:"Feedback Analytics",group:"Analytics"},{value:"marketing",label:"All Users Management",group:"User Management"},{value:"user-management",label:"Admin User Management",group:"User Management"},{value:"newsletter",label:"Newsletter Subscriptions",group:"Marketing"},{value:"marketing-automation",label:"Marketing Automation",group:"Marketing"},{value:"evaluations",label:"Interview Evaluation Manager",group:"Interviews"},{value:"orders",label:"Order Management",group:"Finance"},{value:"credit-packs",label:"Credit Pack Management",group:"Finance"},{value:"promo-codes",label:"Promo Code Management",group:"Finance"},{value:"credit-adjustments",label:"Credit Adjustment",group:"Finance"},{value:"referrals",label:"Manual Referral Management",group:"Referral"}
1,{value:"referral-settings",label:"Referral Settings",group:"Referral"},{value:"blog-posts",label:"Blog",group:"Content"},{value:"content-engine",label:"Content Engine",group:"Content",href:"/admin/content-engine"},{value:"hiring-management",label:"Hiring Management",group:"Hiring"},{value:"college-management",label:"College Management",group:"Admin"},{value:"corporate-management",label:"Corporate Management",group:"Admin"},{value:"platform-settings",label:"Platform Settings",group:"Admin"},{value:"delete-user",label:"Delete User",group:"Admin"},{value:"policies",label:"Policy",group:"Admin"},{value:"export",label:"Export Info",group:"Admin"},{value:"profile-logs",label:"Profile Access Logs",group:"Admin"},{value:"contacts",label:"Contact Us — Queries",group:"Support"}],Nn=({children:t,p:s,danger:r=!1,className:a=""})=>e.jsx("div",{className:`rounded-2xl overflow-hidden transition-all duration-300 ${a}`,style:{background:r?s.destructiveBg:s.cardBg,border:`1px solid ${r?s.destructiveBorder:s.cardBorder}`,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:t}),kn=({title:t,desc:s,p:r})=>e.jsxs("div",{className:"px-5 py-4",style:{borderBottom:`1px solid ${r.divider}`},children:[e.jsx("h2",{className:"text-base font-bold",style:{fontFamily:"'Roboto Slab',serif",color:r.headlineColor},children:t}),s&&e.jsx("p",{className:"text-xs mt-0.5",style:{color:r.mutedText},children:s})]}),_n=()=>{var t;const s=u(),[r,a]=c.useState("analytics"),[l,n]=c.useState(null),[o,i]=c.useState(!1),{resolvedTheme:d}=m(),p="light"===d?jn.light:jn.dark;c.useEffect(()=>{window.scrollTo(0,0)},[]);const h=(null==(t=wn.find(e=>e.value===r))?void 0:t.label)||"Select Tab",g="delete-user"===r;return e.jsxs("div",{className:"min-h-screen transition-colors duration-300",style:{background:p.sectionBg},children:[e.jsx("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{backgroundImage:[`linear-gradient(${p.gridLine} 1px, transparent 1px)`,`linear-gradient(90deg, ${p.gridLine} 1px, transparent 1px)`].join(", "),backgroundSize:"40px 40px",zIndex:0}}),e.jsx(I,{title:"Admin Dashboard — SmartMentor.ai",description:"Admin panel for SmartMentor.ai"}),e.jsx(P,{}),e.jsxs("main",{className:"relative z-10 w-full max-w-[1920px] mx-auto px-4 sm:px-6 lg:px-8 pt-24 pb-12",style:{fontFamily:"'Inter','DM Sans',sans-serif"},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"linear-gradient(135deg,rgba(139,92,246,0.40),rgba(109,40,217,0.30))",border:`1px solid ${p.accentBorder}`},children:e.jsx(Bt,{className:"w-5 h-5",style:{color:p.accentText}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-[0.18em]",style:{color:p.accentText},children:"Administration"}),e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",style:{fontFamily:"'Roboto Slab',serif",color:p.headlineColor},children:"Admin Dashboard"})]})]}),e.jsxs(Qt,{value:r,onValueChange:a,children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] mb-2",style:{color:p.mutedText},children:["Active:"," ",e.jsx("span",{style:{color:g?p.destructiveText:p.accentText},children:h})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(new Set(wn.map(e=>e.group))).map(t=>{var o;const i="Danger"===t,d=(null==(o=wn.find(e=>e.value===r))?void 0:o.group)===t,c=wn.filter(e=>e.group===t),u=i?p.destructiveBg:d?p.accentBg:p.cardBg,m=i?p.destructiveBorder:p.accentBorder,h=i?p.destructiveText:d?p.headlineColor:p.accentText;return e.jsxs(U,{open:l===t,onOpenChange:e=>n(e?t:null),children:[e.jsx(O,{asChild:!0,children:e.jsxs("button",{role:"combobox","aria-expanded":l===t,"aria-label":`Filter ${t}`,className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-xs font-semibold transition-all hover:scale-[1.03]",style:{background:u,border:`1.5px solid ${m}`,color:h,backdropFilter:"blur(10px)",boxShadow:d?"0 4px 16px rgba(0,0,0,0.25)":"0 2px 8px rgba(0,0,0,0.15)"},children:[e.jsx("span",{className:"truncate",children:t}),e.jsx(Tt,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-70"})]})}),e.jsx(z,{className:"w-64 p-0 rounded-xl overflow-hidden",style:{background:jn.dark.sectionBg,border:`1px solid ${i?p.destructiveBorder:p.accentBorder}`},align:"start",children:e.jsx(Ps,{style:{background:"transparent"},children:e.jsxs(Us,{className:"max-h-72",children:[e.jsx(Os,{style:{color:p.mutedText,fontSize:13,padding:"12px 16px"},children:"No tabs found."}),e.jsx(zs,{children:c.map(t=>{const l=t.href,o="delete-user"===t.value;return e.jsxs(Hs,{value:t.label,onSelect:()=>{l?s(l):a(t.value),n(null)},className:"cursor-pointer transition-colors",style:{color:o?p.destructiveText:p.bodyText},children:[e.jsx(it,{className:x("mr-2 h-3.5 w-3.5 flex-shrink-0 transition-opacity",r===t.value?"opacity-100":"opacity-0"),style:{color:o?p.destructiveText:p.accentText}}),e.jsx("span",{className:"text-xs",children:t.label})]},t.value)})})]})})})]},t)})})]}),e.jsx(Xt,{value:"analytics",children:e.jsx(Nn,{p:p,children:e.jsx(ga,{})})}),e.jsx(Xt,{value:"revenue",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-6",children:e.jsx(Qa,{})})})}),e.jsx(Xt,{value:"interview-insights",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-6",children:e.jsx(Ja,{})})})}),e.jsx(Xt,{value:"system-health",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-6",children:e.jsx(Ya,{})})})}),e.jsx(Xt,{value:"user-feedback",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"User Feedback Analytics",desc:"NPS scores and user feedback analysis",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ua,{})})]})}),e.jsx(Xt,{value:"contacts",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Contact Submissions",de
1sc:"Manage incoming contact form submissions",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ka,{})})]})}),e.jsx(Xt,{value:"newsletter",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Newsletter Subscribers",desc:"Manage newsletter subscriptions",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(ja,{})})]})}),e.jsx(Xt,{value:"marketing",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"All Users Management",desc:"User database for user management",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ca,{})})]})}),e.jsx(Xt,{value:"marketing-automation",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Marketing Automation Suite",desc:"Create campaigns, manage segments, build workflows",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ul,{})})]})}),e.jsx(Xt,{value:"evaluations",className:"mb-20",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Interview Evaluation Manager",desc:"Manage and regenerate interview evaluations",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(aa,{})})]})}),e.jsx(Xt,{value:"orders",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-5",children:e.jsx(Lr,{})})})}),e.jsx(Xt,{value:"credit-packs",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Credit Packs Management",desc:"Manage credit packs available for purchase",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(xr,{})})]})}),e.jsx(Xt,{value:"promo-codes",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-5",children:e.jsx(vr,{})})})}),e.jsx(Xt,{value:"credit-adjustments",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Credit Adjustments",desc:"Adjust user credit balances manually as needed",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Tr,{})})]})}),e.jsx(Xt,{value:"user-management",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Admin User Management",desc:"Manage admin users in the platform",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Qr,{})})]})}),e.jsx(Xt,{value:"referrals",children:e.jsx(Nn,{p:p,children:e.jsx("div",{className:"p-5",children:e.jsx(Gr,{})})})}),e.jsx(Xt,{value:"referral-settings",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Referral Settings",desc:"Configure and manage referral program settings",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(ar,{})})]})}),e.jsx(Xt,{value:"export",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Export",desc:"Export platform data to CSV for reporting and analysis",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Nr,{})})]})}),e.jsx(Xt,{value:"profile-logs",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Profile Access Audit Logs",desc:"Monitor all profile access activities for security and compliance",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Xs,{})})]})}),e.jsx(Xt,{value:"blog-posts",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Blog Management",desc:"Create, edit, and publish blog posts",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ra,{})})]})}),e.jsx(Xt,{value:"college-management",children:e.jsx(Nn,{p:p,children:e.jsx(Kl,{})})}),e.jsx(Xt,{value:"corporate-management",children:e.jsx(Nn,{p:p,children:e.jsx(an,{})})}),e.jsx(Xt,{value:"hiring-management",children:e.jsxs(Nn,{p:p,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4",style:{borderBottom:`1px solid ${p.divider}`},children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold",style:{fontFamily:"'Roboto Slab',serif",color:p.headlineColor},children:"Hiring Management"}),e.jsx("p",{className:"text-xs mt-0.5",style:{color:p.mutedText},children:"Manage job postings and view applications"})]}),e.jsxs("button",{onClick:()=>i(!0),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all hover:scale-[1.03]",style:{background:p.accentBg,border:`1px solid ${p.accentBorder}`,color:p.accentText},children:[e.jsx(xe,{className:"w-4 h-4"})," Add Job Posting"]})]}),e.jsx("div",{className:"p-5",children:e.jsx(fn,{showCreateDialog:o,setShowCreateDialog:i})})]})}),e.jsx(Xt,{value:"delete-user",children:e.jsxs(Nn,{p:p,danger:!0,children:[e.jsx(kn,{title:"⚠ Delete User",desc:"Permanent — this action cannot be undone",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ia,{})})]})}),e.jsx(Xt,{value:"policies",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Policy Document Management",desc:"Edit and manage all legal policy documents displayed on the platform",p:p}),e.jsx("div",{className:"p-5",children:e.jsx(Ks,{})})]})}),e.jsx(Xt,{value:"platform-settings",children:e.jsxs(Nn,{p:p,children:[e.jsx(kn,{title:"Platform Settings",desc:"Global feature flags that control platform-wide behavior",p:p}),e.jsx(vn,{})]})})]})]})]})};export{_n 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.