1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/fileStorage-CHa2HEhP.js","assets/index-DMpD5zQ4.js","assets/index-CVDhzJfm.css"])))=>i.map(i=>d[i]); 2import{c as be,bF as _a,bG as ba,r as b,k as Le,bH as wa,z as bs,G as cs,F as Oe,N as xa,bI as es,e as Ss,j as e,bA as Qa,aq as Ja,a as Ks,B as v,X as ss,t as ne,C as P,f as F,O as J,s as C,ar as I,as as U,aw as R,E as Ke,i as He,h as ws,U as Ca,aG as A,ak as Ps,al as Ds,am as As,an as as,g as ms,aE as B,aF as O,I as N,L as se,a0 as ns,ax as Ga,b6 as Wa,a1 as xe,a2 as me,a3 as ue,a4 as je,a5 as E,bJ as Ya,bK as Za,bL as Xa,a7 as Qe,ac as et,Z as rs,a8 as us,a9 as js,aa as ps,aJ as ka,aI as ye,K as $s,at as st,bM as at,bN as tt,bO as nt,bP as rt,Y as it,ao as lt}from"./index-DMpD5zQ4.js";import{a as ct,b as dt,c as ot,d as ht,e as xt,f as mt,g as ut,h as jt,i as pt}from"./useAdmin-DFdKarrW.js";import{S as ls}from"./scroll-area-CoAEOFg9.js";import{C as gt}from"./clipboard-check-CuzwFvj5.js";import{S as Gs}from"./settings-D4t6uka4.js";import{F as ds}from"./folder-kanban-DL6mQDSN.js";import{C as ts}from"./calendar-days-PPcmA_c3.js";import{A as Cs}from"./award-B72AyuG0.js";import{V as Ws}from"./video-DteP5QmJ.js";import{S as Vs}from"./shield-BAaFniQN.js";import{T as Sa}from"./tag-DOBh7HAo.js";import{B as gs}from"./briefcase-Hwi-bO0X.js";import{C as vt}from"./calendar-D83ENLM0.js";import{G as ks}from"./globe-__AbA6qd.js";import{B as yt}from"./building-hbYu4h8O.js";import{M as ft}from"./menu-DgD9-fgp.js";import{B as D}from"./badge-bMO3_tW7.js";import{T as ce,a as de,b as M,c as g,d as oe,e as p}from"./table-C7-St2aw.js";import{D as Y,a as _e,b as Z,c as X,d as ee,e as Bs,f as Ne}from"./dialog-Drq6wm62.js";import{S as G}from"./switch-DW4WFj1t.js";import{A as Se,b as Pe,c as De,d as Ae,e as Me,f as Te,g as Fe,h as qe,a as ma}from"./alert-dialog-BdJU2A1f.js";import{S as Ms}from"./star-CrzUnXU9.js";import{E as Ys}from"./ellipsis-vertical-BGEiIgvz.js";import{T as pe}from"./trash-2-B5JnNIVZ.js";import{L as u}from"./label-CAB3OdUz.js";import{T as K}from"./textarea-BmqJYY1S.js";import{P as we}from"./plus-BPK3OS2-.js";import{S as Hs}from"./square-pen-EZvLgx82.js";import{T as Je,a as Ge,b as le,c as ge}from"./tabs-ZII6aAIe.js";import{a as Nt,b as _t,c as bt,d as wt,e as Ct,f as kt,g as St,h as Pt}from"./useJobs-C3JAIRe-.js";import{D as Zs}from"./download-D3D9UcI7.js";import{R as xs,U as Dt,e as At,f as Mt}from"./useRoleRequests-snd3_B8L.js";import{C as Tt}from"./circle-alert-xoMAZWvJ.js";import{g as Ft}from"./generatePayslip-C9TUa3Wi.js";import{c as qt,d as Lt,e as Rt,f as Et,g as It,h as Ut,i as zt,j as Pa,k as Ot,l as Kt,m as $t,n as Vt,o as Bt,p as Ht,a as Da,q as Qt,r as Jt,s as Gt,t as Wt,v as Yt,w as Zt,x as Xt,y as en,z as sn}from"./useTeamSystem-HjQPGF8k.js";import{L as an}from"./lock-CrOy6rXE.js";import{C as Qs}from"./credit-card-BcpbAeHM.js";import{W as tn}from"./wallet-BE9kZID_.js";import{H as nn}from"./history-DMjYeBgP.js";import{C as rn}from"./clock-DpH3fNh0.js";import{R as ln}from"./reply-DcWEhn28.js";import{S as Js}from"./send-BcKsSsSq.js";import{S as Is}from"./save-B9sBNypQ.js";import{a as cn,b as dn}from"./useVideoCallRequests-yTgjQD7f.js";import{C as Ts}from"./chart-column-D09L9wue.js";import{u as on,a as hn,b as xn}from"./useResumes-DVzfdUD5.js";import{P as Xs}from"./pen-Ce1LaxBX.js";import"./index-BgKL7wpb.js";import"./fileStorage-CHa2HEhP.js";import"./jspdf.es.min-Bho5K9mF.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const mn=be("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/** 8 * @license lucide-react v0.462.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const un=be("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** 13 * @license lucide-react v0.462.0 - ISC 14 * 15 * This source code is licensed under the ISC license. 16 * See the LICENSE file in the root directory of this source tree. 17 */const jn=be("Handshake",[["path",{d:"m11 17 2 2a1 1 0 1 0 3-3",key:"efffak"}],["path",{d:"m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4",key:"9pr0kb"}],["path",{d:"m21 3 1 11h-2",key:"1tisrp"}],["path",{d:"M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3",key:"1uvwmv"}],["path",{d:"M3 4h8",key:"1ep09j"}]]);/** 18 * @license lucide-react v0.462.0 - ISC 19 * 20 * This source code is licensed under the ISC license. 21 * See the LICENSE file in the root directory of this source tree. 22 */const pn=be("ListTodo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);/** 23 * @license lucide-react v0.462.0 - ISC 24 * 25 * This source code is licensed under the ISC license. 26 * See the LICENSE file in the root directory of this source tree. 27 */const gn=be("LockOpen",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]]);/** 28 * @license lucide-react v0.462.0 - ISC 29 * 30 * This source code is licensed under the ISC license. 31 * See the LICENSE file in the root directory of this source tree. 32 */const vn=be("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);/** 33 * @license lucide-react v0.462.0 - ISC 34 * 35 * This source code is licensed under the ISC license. 36 * See the LICENSE file in the root directory of this source tree. 37 */const Aa=be("Navigation",[["polygon",{points:"3 11 22 2 13 21 11 13 3 11",key:"1ltx0t"}]]);/** 38 * @license lucide-react v0.462.0 - ISC 39 * 40 * This source code is licensed under the ISC license. 41 * See the LICENSE file in the root directory of this source tree. 42 */const yn=be("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);/** 43 * @license lucide-react v0.462.0 - ISC 44 * 45 * This source code is licensed under the ISC license. 46 * See the LICENSE file in the root directory of this source tree. 47 */const Fs=be("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/** 48 * @license lucide-react v0.462.0 - ISC 49 * 50 * This source code is licensed under the ISC license. 51 * See the LICENSE file in the root directory of this source tree. 52 */const fn=be("Plane",[["path",{d:"M17.8 19.2 16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.
vendor: 6,778 bytes, lines 52-67
521-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z",key:"1v9wt8"}]]);/** 53 * @license lucide-react v0.462.0 - ISC 54 * 55 * This source code is licensed under the ISC license. 56 * See the LICENSE file in the root directory of this source tree. 57 */const ua=be("ShieldBan",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m4.243 5.21 14.39 12.472",key:"1c9a7c"}]]);/** 58 * @license lucide-react v0.462.0 - ISC 59 * 60 * This source code is licensed under the ISC license. 61 * See the LICENSE file in the root directory of this source tree. 62 */const Nn=be("UserMinus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/** 63 * @license lucide-react v0.462.0 - ISC 64 * 65 * This source code is licensed under the ISC license. 66 * See the LICENSE file in the root directory of this source tree. 67 */const ja=be("UsersRound",[["path",{d:"M18 21a8 8 0 0 0-16 0",key:"3ypg7q"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3",key:"10s06x"}]]);function _n(s,l){const n=kn(s);let i;if(n.date){const c=Sn(n.date,2);i=Pn(c.restDateString,c.year)}if(!i||isNaN(i.getTime()))return new Date(NaN);const o=i.getTime();let t=0,m;if(n.time&&(t=Dn(n.time),isNaN(t)))return new Date(NaN);if(n.timezone){if(m=An(n.timezone),isNaN(m))return new Date(NaN)}else{const c=new Date(o+t),r=new Date(0);return r.setFullYear(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate()),r.setHours(c.getUTCHours(),c.getUTCMinutes(),c.getUTCSeconds(),c.getUTCMilliseconds()),r}return new Date(o+t+m)}const _s={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},bn=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,wn=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,Cn=/^([+-])(\d{2})(?::?(\d{2}))?$/;function kn(s){const l={},a=s.split(_s.dateTimeDelimiter);let n;if(a.length>2)return l;if(/:/.test(a[0])?n=a[0]:(l.date=a[0],n=a[1],_s.timeZoneDelimiter.test(l.date)&&(l.date=s.split(_s.timeZoneDelimiter)[0],n=s.substr(l.date.length,s.length))),n){const i=_s.timezone.exec(n);i?(l.time=n.replace(i[1],""),l.timezone=i[1]):l.time=n}return l}function Sn(s,l){const a=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+l)+"})|(\\d{2}|[+-]\\d{"+(2+l)+"})$)"),n=s.match(a);if(!n)return{year:NaN,restDateString:""};const i=n[1]?parseInt(n[1]):null,o=n[2]?parseInt(n[2]):null;return{year:o===null?i:o*100,restDateString:s.slice((n[1]||n[2]).length)}}function Pn(s,l){if(l===null)return new Date(NaN);const a=s.match(bn);if(!a)return new Date(NaN);const n=!!a[4],i=hs(a[1]),o=hs(a[2])-1,t=hs(a[3]),m=hs(a[4]),c=hs(a[5])-1;if(n)return Ln(l,m,c)?Mn(l,m,c):new Date(NaN);{const r=new Date(0);return!Fn(l,o,t)||!qn(l,i)?new Date(NaN):(r.setUTCFullYear(l,o,Math.max(i,t)),r)}}function hs(s){return s?parseInt(s):1}function Dn(s){const l=s.match(wn);if(!l)return NaN;const a=Us(l[1]),n=Us(l[2]),i=Us(l[3]);return Rn(a,n,i)?a*_a+n*ba+i*1e3:NaN}function Us(s){return s&&parseFloat(s.replace(",","."))||0}function An(s){if(s==="Z")return 0;const l=s.match(Cn);if(!l)return 0;const a=l[1]==="+"?-1:1,n=parseInt(l[2]),i=l[3]&&parseInt(l[3])||0;return En(n,i)?a*(n*_a+i*ba):NaN}function Mn(s,l,a){const n=new Date(0);n.setUTCFullYear(s,0,4);const i=n.getUTCDay()||7,o=(l-1)*7+a+1-i;return n.setUTCDate(n.getUTCDate()+o),n}const Tn=[31,null,31,30,31,30,31,31,30,31,30,31];function Ma(s){return s%400===0||s%4===0&&s%100!==0}function Fn(s,l,a){return l>=0&&l<=11&&a>=1&&a<=(Tn[l]||(Ma(s)?29:28))}function qn(s,l){return l>=1&&l<=(Ma(s)?366:365)}function Ln(s,l,a){return l>=1&&l<=53&&a>=0&&a<=6}function Rn(s,l,a){return s===24?l===0&&a===0:a>=0&&a<60&&l>=0&&l<60&&s>=0&&s<25}function En(s,l){return l>=0&&l<=59}const zs=[{label:"Users & Access",icon:Le,items:[{value:"users",label:"Users",icon:Le},{value:"role-requests",label:"Role Requests",icon:gt},{value:"settings",label:"Settings",icon:Gs}]},{label:"Team & Operations",icon:ja,items:[{value:"team",label:"Team",icon:ja},{value:"projects",label:"Projects",icon:ds},{value:"attendance",label:"Attendance",icon:ts},{value:"announcements",label:"Announcements",icon:wa}]},{label:"Learning",icon:bs,items:[{value:"courses",label:"Courses",icon:bs},{value:"enrollments",label:"Enrollments",icon:cs},{value:"certificates",label:"Certificates",icon:Cs},{value:"video-calls",label:"Video Calls",icon:Ws}]},{label:"Blog & Content",icon:Oe,items:[{value:"applications",label:"Applications",icon:Vs},{value:"posts",label:"Posts",icon:Oe},{value:"content-calendar",label:"Content Calendar",icon:ts},{value:"categories",label:"Categories",icon:Sa}]},{label:"Jobs & Freelancing",icon:gs,items:[{value:"jobs",label:"Jobs",icon:gs},{value:"freelancing",label:"Freelancing",icon:ds}]},{label:"Community",icon:xa,items:[{value:"community-events",label:"Events",icon:vt}]},{label:"Communications",icon:es,items:[{value:"messages",label:"Contact Messages",icon:es},{value:"service-inquiries",label:"Service Inquiries",icon:Ss},{value:"newsletter",label:"Newsletter",icon:es}]},{label:"CMS Pages",icon:ks,items:[{value:"service-pages",label:"Services",icon:ks},{value:"industry-pages",label:"Industries",icon:yt},{value:"freelancing-pages",label:"Freelance Pages",icon:jn},{value:"community-pages",label:"Community Pages",icon:xa},{value:"managed-pages",label:"Nav Pages",icon:Aa}]},{label:"Scholarships & Visas",icon:fn,items:[{value:"scholarships",label:"Scholarships",icon:cs}]},{label:"Tools",icon:Oe,items:[{value:"resume",label:"Resumes",icon:Oe}]}],In=({activeTab:s,onTabChange:l})=>{const[a,n]=b.useState(()=>{const r=zs.find(d=>d.items.some(x=>x.value===s));return r?[r.label]:[zs[0].label]}),[i,o]=b.useState(!1),t=r=>{n(d=>d.includes(r)?d.filter(x=>x!==r):[...d,r])},m=r=>{l(r),o(!1)},c=e.jsx(ls,{className:"h-full",children:e.jsx("div",{className:"p-3 space-y-1",children:zs.map(r=>{const d=a.includes(r.label),x=r.items.some(j=>j.value===s);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t(r.label),className:Ks("w-full flex items-center gap-2 px-3 py-2.5 rounded-lg text-sm font-semibold transition-colors",x?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[e.jsx(r.icon,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"flex-1 text-left",children:r.label}),d?e.jsx(Qa,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Ja,{className:"h-3.5 w-3.5 shrink-0"})]}),d&&e.jsx("div",{className:"ml-3 mt-0.5 space-y-0.5 border-l-2 border-border pl-3",children:r.items.map(j=>e.jsxs("button",{onClick:()=>
67m(j.value),className:Ks("w-full flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors",s===j.value?"bg-primary text-primary-foreground font-medium":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[e.jsx(j.icon,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:j.label})]},j.value))})]},r.label)})})});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"lg:hidden mb-4",children:e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>o(!i),className:"gap-2",children:[i?e.jsx(ss,{className:"h-4 w-4"}):e.jsx(ft,{className:"h-4 w-4"}),i?"Close Menu":"Admin Menu"]})}),i&&e.jsx("div",{className:"lg:hidden mb-4 border rounded-xl bg-card shadow-sm max-h-[60vh] overflow-hidden",children:c}),e.jsx("aside",{className:"hidden lg:block w-64 shrink-0 border rounded-xl bg-card shadow-sm h-[calc(100vh-12rem)] sticky top-28",children:c})]})};function Un(){return J({queryKey:["admin-stats"],queryFn:async()=>{const[{count:s},{count:l},{count:a},{count:n},{count:i},{count:o},{count:t},{count:m},{count:c}]=await Promise.all([C.from("profiles").select("*",{count:"exact",head:!0}),C.from("courses").select("*",{count:"exact",head:!0}),C.from("blog_posts").select("*",{count:"exact",head:!0}),C.from("job_postings").select("*",{count:"exact",head:!0}),C.from("enrollments").select("*",{count:"exact",head:!0}),C.from("freelance_projects").select("*",{count:"exact",head:!0}),C.from("certificates").select("*",{count:"exact",head:!0}),C.from("contact_messages").select("*",{count:"exact",head:!0}).eq("is_read",!1),C.from("service_inquiries").select("*",{count:"exact",head:!0}).eq("is_read",!1)]);return{users:s??0,courses:l??0,blogPosts:a??0,jobs:n??0,enrollments:i??0,freelanceProjects:o??0,certificates:t??0,unreadMessages:m??0,unreadInquiries:c??0}}})}const pa=[{key:"users",label:"Total Users",icon:Le,color:"text-blue-500 bg-blue-500/10"},{key:"courses",label:"Courses",icon:bs,color:"text-purple-500 bg-purple-500/10"},{key:"enrollments",label:"Enrollments",icon:cs,color:"text-green-500 bg-green-500/10"},{key:"certificates",label:"Certificates",icon:Cs,color:"text-amber-500 bg-amber-500/10"},{key:"blogPosts",label:"Blog Posts",icon:Oe,color:"text-pink-500 bg-pink-500/10"},{key:"jobs",label:"Job Postings",icon:gs,color:"text-orange-500 bg-orange-500/10"},{key:"freelanceProjects",label:"Freelance Projects",icon:ds,color:"text-teal-500 bg-teal-500/10"},{key:"unreadMessages",label:"Unread Messages",icon:Ss,color:"text-red-500 bg-red-500/10"},{key:"unreadInquiries",label:"Unread Inquiries",icon:ts,color:"text-indigo-500 bg-indigo-500/10"}],zn=()=>{const{data:s,isLoading:l}=Un();return l?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 xl:grid-cols-9 gap-4",children:pa.map(a=>e.jsx(ne,{className:"h-24"},a.key))}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 xl:grid-cols-9 gap-3",children:pa.map(a=>{const n=a.icon,i=(s==null?void 0:s[a.key])??0,o=(a.key==="unreadMessages"||a.key==="unreadInquiries")&&i>0;return e.jsx(P,{className:o?"ring-1 ring-destructive/30":"",children:e.jsxs(F,{className:"p-3 flex flex-col items-center text-center gap-1.5",children:[e.jsx("div",{className:`p-1.5 rounded-lg ${a.color}`,children:e.jsx(n,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-xl font-bold",children:i.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:a.label})]})},a.key)})})},On=()=>{const{data:s,isLoading:l}=ct(),a=dt(),[n,i]=b.useState(null),o=async(c,r)=>{try{await a.mutateAsync({id:c.id,status:r,userId:c.user_id}),A.success(`Application ${r}!`)}catch{A.error("Failed to update application")}},t=(s==null?void 0:s.filter(c=>c.status==="pending"))||[],m=(s==null?void 0:s.filter(c=>c.status!=="pending"))||[];return l?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"Blogger Applications"})}),e.jsx(F,{children:e.jsx("div",{className:"space-y-4",children:[1,2,3].map(c=>e.jsx(ne,{className:"h-16"},c))})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:["Pending Applications",t.length>0&&e.jsx(D,{variant:"secondary",children:t.length})]})}),e.jsx(F,{children:t.length>0?e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Applicant"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Sample Topic"}),e.jsx(g,{children:"Date"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:t.map(c=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:c.full_name}),e.jsx(p,{children:c.email}),e.jsx(p,{className:"max-w-[200px] truncate",children:c.sample_topic}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(c.created_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsxs(Y,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>i(c),children:e.jsx(Ke,{className:"h-4 w-4"})})}),e.jsxs(Z,{className:"max-w-lg",children:[e.jsxs(X,{children:[e.jsx(ee,{children:"Application Details"}),e.jsx(Bs,{children:"Review this blogger application"})]}),n&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Full Name"}),e.jsx("p",{className:"mt-1",children:n.full_name})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Email"}),e.jsx("p",{className:"mt-1",children:n.email})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Bio"}),e.jsx("p",{className:"mt-1 text-sm",children:n.bio})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Sample Topic"}),e.jsx("p",{className:"mt-1 text-sm",children:n.sample_topic})]}),n.portfolio_url&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Portfolio"}),e.jsxs("a",{href:n.portfolio_url,target:"_blank",rel:"noopener noreferrer",className:"mt-1 text-sm text-primary flex items-center gap-1 hover:underline",children:[n.portfolio_url,e.jsx(He,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsxs(v,{className:"flex-1",onClick:()=>o(n,"approved"),disabled:a.isPending,children:[e.jsx(ws,{className:"h-4 w-4 mr-2"}),"Approve"]}),e.jsxs(v,{variant:"destructive",className:"flex-1",onClick:()=>o(n,"rejected"),disabled:a.isPending,children:[e.jsx(ss,{className:"h-4 w-4 mr-2"}),"Reject"]})]})]})]})]}),e.jsx(v,{size:"icon",variant:"ghost",className:"text-green-500 hover:text-green-600 hover:bg-green-500/10",onClick:()=>o(c,"approved"),disabled:a.isPending,children:e.jsx(ws,{className:"h-4 w-4"})}),e.jsx(v,{size:"icon",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>o(c,"rejected"),disabled:a.isPending,children:e.jsx(ss,{className:"h-4 w-4"})})]})})]},c.id))})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Ca,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No pending applications"})]})})]}),m.length>0&&e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"Reviewed Applications"})}),e.jsx(F,{children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Applicant"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Date"})]})}),e.jsx(oe,{children:m.map(c=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:c.full_name}),e.jsx(p,{children:c.email}),e.jsx(p,{children:e.jsx(D,{variant:c.status==="approved"?"default":"destructive",className:c.status==="approved"?"bg-green-500/10 text-green-500 border-green-500/20":"",children:c.status})}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(c.created_at),"MMM d, yyyy")})]},c.id))})]})})]})]})},Kn=()=>{const{data:s,isLoading:l}=ot(),a=ht(),n=xt(),[i,o]=b.useState(null),t=async()=>
67{if(i)try{await a.mutateAsync(i),A.success("Post deleted"),o(null)}catch{A.error("Failed to delete post")}},m=async(r,d)=>{try{await n.mutateAsync({id:r,is_published:!d}),A.success(d?"Post unpublished":"Post published")}catch{A.error("Failed to update post")}},c=async(r,d)=>{try{await n.mutateAsync({id:r,is_featured:!d}),A.success(d?"Removed from featured":"Added to featured")}catch{A.error("Failed to update post")}};return l?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"All Posts"})}),e.jsx(F,{children:e.jsx("div",{className:"space-y-4",children:[1,2,3].map(r=>e.jsx(ne,{className:"h-16"},r))})})]}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:["All Posts",s&&e.jsx(D,{variant:"secondary",children:s.length})]})}),e.jsx(F,{children:s&&s.length>0?e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Title"}),e.jsx(g,{children:"Author"}),e.jsx(g,{children:"Category"}),e.jsx(g,{children:"Published"}),e.jsx(g,{children:"Featured"}),e.jsx(g,{children:"Date"}),e.jsx(g,{className:"w-[60px]"})]})}),e.jsx(oe,{children:s.map(r=>{var d,x;return e.jsxs(M,{children:[e.jsx(p,{className:"font-medium max-w-[200px] truncate",children:r.title}),e.jsx(p,{children:((d=r.author)==null?void 0:d.full_name)||"Unknown"}),e.jsx(p,{children:((x=r.category)==null?void 0:x.name)||e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(p,{children:e.jsx(G,{checked:r.is_published||!1,onCheckedChange:()=>m(r.id,r.is_published||!1),disabled:n.isPending})}),e.jsx(p,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>c(r.id,r.is_featured||!1),disabled:n.isPending,className:r.is_featured?"text-yellow-500":"text-muted-foreground",children:e.jsx(Ms,{className:`h-4 w-4 ${r.is_featured?"fill-current":""}`})})}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(r.created_at),"MMM d, yyyy")}),e.jsx(p,{children:e.jsxs(Ps,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",children:e.jsx(Ys,{className:"h-4 w-4"})})}),e.jsxs(As,{align:"end",children:[r.is_published&&e.jsx(as,{asChild:!0,children:e.jsxs(ms,{to:`/blog/${r.slug}`,children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"View"]})}),e.jsxs(as,{className:"text-destructive",onClick:()=>o(r.id),children:[e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})})]},r.id)})})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Oe,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No posts yet"})]})}),e.jsx(Se,{open:!!i,onOpenChange:()=>o(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Post?"}),e.jsx(Me,{children:"This action cannot be undone. This will permanently delete the post and all its comments."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:t,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})},$n=()=>J({queryKey:["content-calendar"],queryFn:async()=>{const{data:s,error:l}=await C.from("content_calendar").select("*").order("sort_order",{ascending:!0}).order("scheduled_date",{ascending:!0});if(l)throw l;const a=s||[],n=a.map(t=>t.post_id).filter(Boolean);if(!n.length)return a;const{data:i}=await C.from("blog_posts").select("id, slug, title, is_published").in("id",n),o=new Map((i||[]).map(t=>[t.id,t]));return a.map(t=>({...t,post:t.post_id?o.get(t.post_id)??null:null}))}}),Vn=()=>{const s=B();return O({mutationFn:async l=>{const{data:a,error:n}=await C.functions.invoke("generate-article",{body:{calendar_id:l}});if(n){let i=n.message;try{const o=n.context;if(o){const t=await o.json();t!=null&&t.error&&(i=t.error)}}catch{}throw new Error(i)}if(a!=null&&a.error)throw new Error(a.error);return a},onSettled:()=>{s.invalidateQueries({queryKey:["content-calendar"]}),s.invalidateQueries({queryKey:["admin-blog-posts"]})}})},Bn=()=>{const s=B();return O({mutationFn:async({topicId:l,postId:a})=>{const{error:n}=await C.from("blog_posts").update({is_published:!0,published_at:new Date().toISOString()}).eq("id",a);if(n)throw n;const{error:i}=await C.from("content_calendar").update({status:"published"}).eq("id",l);if(i)throw i},onSuccess:()=>{s.invalidateQueries({queryKey:["content-calendar"]}),s.invalidateQueries({queryKey:["admin-blog-posts"]}),s.invalidateQueries({queryKey:["blog-posts"]})}})},Hn=()=>{const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("content_calendar").insert({...l,sort_order:999});if(a)throw a},onSuccess:()=>s.invalidateQueries({queryKey:["content-calendar"]})})},Qn=()=>{const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("content_calendar").delete().eq("id",l);if(a)throw a},onSuccess:()=>s.invalidateQueries({queryKey:["content-calendar"]})})},ga={planned:{label:"Planned",className:"bg-muted text-muted-foreground"},writing:{label:"Creatingâ¦",className:"bg-[hsl(var(--brand-blue))] text-primary-foreground"},drafted:{label:"Draft ready",className:"bg-amber-500 text-white"},published:{label:"Published",className:"bg-emerald-600 text-white"},failed:{label:"Failed",className:"bg-destructive text-destructive-foreground"}},Jn=({topic:s})=>{var r,d,x,j;const l=Vn(),a=Bn(),n=Qn(),i=(r=s.post)!=null&&r.is_published?"published":s.status,o=ga[i]??ga.planned,t=l.isPending,m=async()=>{try{const _=await l.mutateAsync(s.id);_!=null&&_.image_warning?A.warning("Draft written, but its featured image needs attention"):A.success("Article and featured image created â review them, then publish")}catch(_){A.error(_ instanceof Error?_.message:"Failed to write the article")}},c=async()=>
67{if(s.post_id)try{await a.mutateAsync({topicId:s.id,postId:s.post_id}),A.success("Article published")}catch{A.error("Failed to publish")}};return e.jsxs("div",{className:"rounded-xl border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("p",{className:"font-semibold leading-snug",children:s.title}),e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ns,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:s.search_term})]}),s.scheduled_date&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ts,{className:"h-3.5 w-3.5"}),R(_n(s.scheduled_date),"EEE, MMM d yyyy")]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(D,{className:o.className,children:o.label}),e.jsx(v,{variant:"ghost",size:"icon",className:"text-destructive",onClick:()=>n.mutate(s.id),disabled:n.isPending,children:e.jsx(pe,{className:"h-4 w-4"})})]})]}),s.error_message&&e.jsx("p",{className:i==="failed"?"text-xs text-destructive":"text-xs text-amber-700 dark:text-amber-400",children:s.error_message}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.post_id?e.jsxs(e.Fragment,{children:[!((d=s.post)!=null&&d.is_published)&&e.jsxs(v,{onClick:c,disabled:a.isPending,className:"gap-2",children:[a.isPending?e.jsx(se,{className:"h-4 w-4 animate-spin"}):e.jsx(Ga,{className:"h-4 w-4"}),"Publish"]}),e.jsx(v,{variant:"outline",asChild:!0,className:"gap-2",children:e.jsxs(ms,{to:`/blogger/posts/${s.post_id}/edit`,children:[e.jsx(Fs,{className:"h-4 w-4"}),"Review & edit"]})}),((x=s.post)==null?void 0:x.is_published)&&((j=s.post)==null?void 0:j.slug)&&e.jsx(v,{variant:"ghost",asChild:!0,className:"gap-2",children:e.jsxs(ms,{to:`/blog/${s.post.slug}`,children:[e.jsx(Ke,{className:"h-4 w-4"}),"View live"]})})]}):e.jsxs(v,{onClick:m,disabled:t,className:"gap-2",children:[t?e.jsx(se,{className:"h-4 w-4 animate-spin"}):e.jsx(yn,{className:"h-4 w-4"}),t?"Creating article & imageâ¦":i==="failed"?"Retry":"Create Article & Image"]})})]})},Gn=()=>{const[s,l]=b.useState(!1),[a,n]=b.useState({title:"",search_term:"",scheduled_date:"",notes:""}),i=Hn(),o=async()=>{if(!a.title.trim()||!a.search_term.trim()){A.error("Title and search term are required");return}try{await i.mutateAsync({title:a.title.trim(),search_term:a.search_term.trim(),scheduled_date:a.scheduled_date||null,notes:a.notes.trim()||null}),A.success("Topic added"),n({title:"",search_term:"",scheduled_date:"",notes:""}),l(!1)}catch{A.error("Failed to add topic")}};return e.jsxs(Y,{open:s,onOpenChange:l,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),"Add topic"]})}),e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(ee,{children:"Add a topic"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"ct-title",children:"Working title *"}),e.jsx(N,{id:"ct-title",value:a.title,onChange:t=>n({...a,title:t.target.value}),placeholder:"The Executive Guide toâ¦"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"ct-term",children:"Target search term *"}),e.jsx(N,{id:"ct-term",value:a.search_term,onChange:t=>n({...a,search_term:t.target.value}),placeholder:"AI software development Australia"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"ct-date",children:"Scheduled date"}),e.jsx(N,{id:"ct-date",type:"date",value:a.scheduled_date,onChange:t=>n({...a,scheduled_date:t.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"ct-notes",children:"Direction for the writer (optional)"}),e.jsx(K,{id:"ct-notes",rows:3,value:a.notes,onChange:t=>n({...a,notes:t.target.value}),placeholder:"Angle, examples to include, who it's aimed atâ¦"})]})]}),e.jsx(Ne,{children:e.jsxs(v,{onClick:o,disabled:i.isPending,children:[i.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Add topic"]})})]})]})},Wn=()=>{const{data:s,isLoading:l}=$n(),a=b.useMemo(()=>{const n=s||[];return{total:n.length,published:n.filter(i=>{var o;return(o=i.post)==null?void 0:o.is_published}).length,drafted:n.filter(i=>{var o;return i.post_id&&!((o=i.post)!=null&&o.is_published)}).length}},[s]);return l?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"Content Calendar"})}),e.jsx(F,{className:"space-y-4",children:[1,2,3].map(n=>e.jsx(ne,{className:"h-28"},n))})]}):e.jsxs(P,{children:[e.jsxs(I,{className:"flex flex-row items-start justify-between gap-4 space-y-0",children:[e.jsxs("div",{children:[e.jsxs(U,{className:"flex items-center gap-2",children:["Content Calendar",e.jsx(D,{variant:"secondary",children:a.total})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a.published," published · ",a.drafted," awaiting review. Each article and its featured image are created for search and AI answer engines, then saved for approval."]})]}),e.jsx(Gn,{})]}),e.jsx(F,{children:s&&s.length>0?e.jsx("div",{className:"space-y-3",children:s.map(n=>e.jsx(Jn,{topic:n},n.id))}):e.jsxs("div",{className:"text-center py-10 text-muted-foreground",children:[e.jsx(ts,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No topics scheduled yet"})]})})]})},Yn=()=>{const{data:s,isLoading:l}=Wa(),a=mt(),n=ut(),i=jt(),[o,t]=b.useState(!1),[m,c]=b.useState(null),[r,d]=b.useState(null),[x,j]=b.useState({name:"",slug:"",description:""}),_=L=>L.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),k=async()=>
67{if(!x.name.trim()){A.error("Name is required");return}try{await a.mutateAsync({name:x.name,slug:x.slug||_(x.name),description:x.description||void 0}),A.success("Category created"),t(!1),j({name:"",slug:"",description:""})}catch{A.error("Failed to create category")}},w=async()=>{if(!m||!x.name.trim()){A.error("Name is required");return}try{await n.mutateAsync({id:m.id,name:x.name,slug:x.slug,description:x.description||void 0}),A.success("Category updated"),c(null),j({name:"",slug:"",description:""})}catch{A.error("Failed to update category")}},S=async()=>{if(r)try{await i.mutateAsync(r),A.success("Category deleted"),d(null)}catch{A.error("Failed to delete category. It may have posts associated with it.")}},V=L=>{c(L),j({name:L.name,slug:L.slug,description:L.description||""})};return l?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"Categories"})}),e.jsx(F,{children:e.jsx("div",{className:"space-y-4",children:[1,2,3].map(L=>e.jsx(ne,{className:"h-12"},L))})})]}):e.jsxs(P,{children:[e.jsxs(I,{className:"flex flex-row items-center justify-between",children:[e.jsx(U,{children:"Categories"}),e.jsxs(Y,{open:o,onOpenChange:t,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{children:[e.jsx(we,{className:"h-4 w-4 mr-2"}),"Add Category"]})}),e.jsxs(Z,{children:[e.jsxs(X,{children:[e.jsx(ee,{children:"Create Category"}),e.jsx(Bs,{children:"Add a new blog category"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"name",children:"Name *"}),e.jsx(N,{id:"name",value:x.name,onChange:L=>{j({...x,name:L.target.value,slug:_(L.target.value)})},placeholder:"Category name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"slug",children:"Slug"}),e.jsx(N,{id:"slug",value:x.slug,onChange:L=>j({...x,slug:L.target.value}),placeholder:"category-slug"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"description",children:"Description"}),e.jsx(K,{id:"description",value:x.description,onChange:L=>j({...x,description:L.target.value}),placeholder:"Category description",rows:3})]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(v,{onClick:k,disabled:a.isPending,children:[a.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Create"]})]})]})]})]}),e.jsx(F,{children:s&&s.length>0?e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Slug"}),e.jsx(g,{children:"Description"}),e.jsx(g,{className:"w-[100px]",children:"Actions"})]})}),e.jsx(oe,{children:s.map(L=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:L.name}),e.jsx(p,{className:"text-muted-foreground",children:L.slug}),e.jsx(p,{className:"max-w-[200px] truncate text-muted-foreground",children:L.description||"â"}),e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>V(L),children:e.jsx(Hs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive",onClick:()=>d(L.id),children:e.jsx(pe,{className:"h-4 w-4"})})]})})]},L.id))})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Sa,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No categories yet"})]})}),e.jsx(Y,{open:!!m,onOpenChange:()=>c(null),children:e.jsxs(Z,{children:[e.jsxs(X,{children:[e.jsx(ee,{children:"Edit Category"}),e.jsx(Bs,{children:"Update category details"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-name",children:"Name *"}),e.jsx(N,{id:"edit-name",value:x.name,onChange:L=>j({...x,name:L.target.value}),placeholder:"Category name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-slug",children:"Slug"}),e.jsx(N,{id:"edit-slug",value:x.slug,onChange:L=>j({...x,slug:L.target.value}),placeholder:"category-slug"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-description",children:"Description"}),e.jsx(K,{id:"edit-description",value:x.description,onChange:L=>j({...x,description:L.target.value}),placeholder:"Category description",rows:3})]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>c(null),children:"Cancel"}),e.jsxs(v,{onClick:w,disabled:n.isPending,children:[n.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Changes"]})]})]})}),e.jsx(Se,{open:!!r,onOpenChange:()=>d(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Category?"}),e.jsx(Me,{children:"This action cannot be undone. Posts in this category will become uncategorized."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:S,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})},va=[{value:"full-time",label:"Full-time"},{value:"part-time",label:"Part-time"},{value:"internship",label:"Internship"},{value:"contract",label:"Contract"}],Zn=[{value:"entry",label:"Entry Level"},{value:"mid",label:"Mid Level"},{value:"senior",label:"Senior Level"},{value:"lead",label:"Lead Level"}],Xn=[{value:"pending",label:"Pending",color:"bg-yellow-100 text-yellow-800"},{value:"reviewing",label:"Reviewing",color:"bg-blue-100 text-blue-800"},{value:"shortlisted",label:"Shortlisted",color:"bg-green-100 text-green-800"},{value:"rejected",label:"Rejected",color:"bg-red-100 text-red-800"},{value:"hired",label:"Hired",color:"bg-purple-100 text-purple-800"}],Os={title:"",slug:"",category:"",location:"",employment_type:"full-time",experience_level:"mid",short_description:"",full_description:"",responsibilities:"",requirements:"",benefits:"",salary_min:"",salary_max:"",hide_salary:!1,is_published:!1,is_featured:!1},er=()=>{const[s,l]=b.useState("postings"),[a,n]=b.useState(!1),[i,o]=b.useState(null),[t,m]=b.useState(Os),[c,r]=b.useState(),[d,x]=b.useState(null),{data:j,isLoading:_}=Nt(),{data:k,isLoading:w}=_t(c),S=bt(),V=wt(),L=Ct(),q=kt(),Q=St(),ve=async y=>{try{await Pt(y)}catch{A.error("Couldn't download the resume. Opened it in a new tab instead.")}},he=async y=>{try{const{getSignedFileUrl:T}=await Ya(async()=>{const{getSignedFileUrl:ke}=await import("./fileStorage-CHa2HEhP.js");return{getSignedFileUrl:ke}},__vite__mapDeps([0,1,2]));window.open(await T(y),"_blank","noopener,noreferrer")}
67catch{A.error("Couldn't open the resume â you may not have access to it.")}},Ce=async y=>{await Q.mutateAsync(y)},vs=y=>y.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),ys=y=>{m(T=>({...T,title:y,slug:i?T.slug:vs(y)}))},W=y=>{m(T=>({...T,employment_type:y,hide_salary:y==="internship"?!0:T.hide_salary}))},os=async y=>{y.preventDefault();const T={...t,salary_min:t.salary_min?parseFloat(t.salary_min):null,salary_max:t.salary_max?parseFloat(t.salary_max):null};i?await V.mutateAsync({id:i.id,...T}):await S.mutateAsync(T),n(!1),o(null),m(Os)},re=y=>{var T,ke;o(y),m({title:y.title,slug:y.slug,category:y.category,location:y.location,employment_type:y.employment_type,experience_level:y.experience_level,short_description:y.short_description||"",full_description:y.full_description,responsibilities:y.responsibilities||"",requirements:y.requirements||"",benefits:y.benefits||"",salary_min:((T=y.salary_min)==null?void 0:T.toString())||"",salary_max:((ke=y.salary_max)==null?void 0:ke.toString())||"",hide_salary:y.hide_salary||!1,is_published:y.is_published||!1,is_featured:y.is_featured||!1}),n(!0)},We=async y=>{await L.mutateAsync(y)},Ye=async(y,T)=>{await q.mutateAsync({id:y,status:T})};return _?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ne,{className:"h-12 w-full"}),e.jsx(ne,{className:"h-64 w-full"})]}):e.jsx("div",{className:"space-y-6",children:e.jsxs(Je,{value:s,onValueChange:l,children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs(Ge,{children:[e.jsxs(le,{value:"postings",className:"gap-2",children:[e.jsx(gs,{className:"h-4 w-4"}),"Job Postings"]}),e.jsxs(le,{value:"applications",className:"gap-2",children:[e.jsx(Le,{className:"h-4 w-4"}),"Applications"]})]}),s==="postings"&&e.jsxs(Y,{open:a,onOpenChange:n,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{onClick:()=>{o(null),m(Os)},className:"gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),"Add Job"]})}),e.jsxs(Z,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsx(ee,{children:i?"Edit Job Posting":"Create Job Posting"})}),e.jsxs("form",{onSubmit:os,className:"space-y-6",children:[e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"title",children:"Job Title *"}),e.jsx(N,{id:"title",value:t.title,onChange:y=>ys(y.target.value),placeholder:"e.g., AI Engineer",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"slug",children:"URL Slug *"}),e.jsx(N,{id:"slug",value:t.slug,onChange:y=>m(T=>({...T,slug:y.target.value})),placeholder:"ai-engineer",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"category",children:"Category *"}),e.jsx(N,{id:"category",value:t.category,onChange:y=>m(T=>({...T,category:y.target.value})),placeholder:"e.g., Artificial Intelligence",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"location",children:"Location *"}),e.jsx(N,{id:"location",value:t.location,onChange:y=>m(T=>({...T,location:y.target.value})),placeholder:"e.g., Pakistan, Remote",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Employment Type *"}),e.jsxs(xe,{value:t.employment_type,onValueChange:W,children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsx(je,{children:va.map(y=>e.jsx(E,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Experience Level *"}),e.jsxs(xe,{value:t.experience_level,onValueChange:y=>m(T=>({...T,experience_level:y})),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsx(je,{children:Zn.map(y=>e.jsx(E,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"salary_min",children:"Salary Min (PKR)"}),e.jsx(N,{id:"salary_min",type:"number",value:t.salary_min,onChange:y=>m(T=>({...T,salary_min:y.target.value})),placeholder:"50000",disabled:t.employment_type==="internship"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"salary_max",children:"Salary Max (PKR)"}),e.jsx(N,{id:"salary_max",type:"number",value:t.salary_max,onChange:y=>m(T=>({...T,salary_max:y.target.value})),placeholder:"100000",disabled:t.employment_type==="internship"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"short_description",children:"Short Description"}),e.jsx(K,{id:"short_description",value:t.short_description,onChange:y=>m(T=>({...T,short_description:y.target.value})),placeholder:"Brief overview for job listing cards",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"full_description",children:"Full Description *"}),e.jsx(K,{id:"full_description",value:t.full_description,onChange:y=>m(T=>({...T,full_description:y.target.value})),placeholder:"Complete job description",rows:4,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"responsibilities",children:"Responsibilities"}),e.jsx(K,{id:"responsibilities",value:t.responsibilities,onChange:y=>m(T=>({...T,responsibilities:y.target.value})),placeholder:"List key responsibilities",rows:4})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"requirements",children:"Requirements"}),e.jsx(K,{id:"requirements",value:t.requirements,onChange:y=>m(T=>({...T,requirements:y.target.value})),placeholder:"Required skills and qualifications",rows:4})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"benefits",children:"Benefits"}
67),e.jsx(K,{id:"benefits",value:t.benefits,onChange:y=>m(T=>({...T,benefits:y.target.value})),placeholder:"What you offer employees",rows:3})]}),e.jsxs("div",{className:"flex flex-wrap gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{id:"hide_salary",checked:t.hide_salary,onCheckedChange:y=>m(T=>({...T,hide_salary:y})),disabled:t.employment_type==="internship"}),e.jsx(u,{htmlFor:"hide_salary",children:"Hide Salary"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{id:"is_published",checked:t.is_published,onCheckedChange:y=>m(T=>({...T,is_published:y}))}),e.jsx(u,{htmlFor:"is_published",children:"Published"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{id:"is_featured",checked:t.is_featured,onCheckedChange:y=>m(T=>({...T,is_featured:y}))}),e.jsx(u,{htmlFor:"is_featured",children:"Featured"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(v,{type:"submit",disabled:S.isPending||V.isPending,children:[(S.isPending||V.isPending)&&e.jsx(se,{className:"mr-2 h-4 w-4 animate-spin"}),i?"Update Job":"Create Job"]})]})]})]})]})]}),e.jsx(ge,{value:"postings",className:"mt-6",children:e.jsx(P,{children:e.jsx(F,{className:"p-0",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Job Title"}),e.jsx(g,{children:"Type"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Created"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:j&&j.length>0?j.map(y=>{var T;return e.jsxs(M,{children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[y.is_featured&&e.jsx(Ms,{className:"h-4 w-4 text-yellow-500 fill-yellow-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:y.title}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[y.category," ⢠",y.location]})]})]})}),e.jsx(p,{children:e.jsx(D,{variant:"outline",children:(T=va.find(ke=>ke.value===y.employment_type))==null?void 0:T.label})}),e.jsx(p,{children:e.jsx(D,{variant:y.is_published?"default":"secondary",children:y.is_published?"Published":"Draft"})}),e.jsx(p,{children:R(new Date(y.created_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>window.open(`/jobs/${y.slug}`,"_blank"),children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>re(y),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsxs(Se,{children:[e.jsx(ma,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",children:e.jsx(pe,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Job Posting?"}),e.jsx(Me,{children:"This will permanently delete this job and all associated applications."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:()=>We(y.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})})]},y.id)}):e.jsx(M,{children:e.jsxs(p,{colSpan:5,className:"text-center py-8",children:[e.jsx(gs,{className:"h-12 w-12 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"No job postings yet"})]})})})]})})})}),e.jsx(ge,{value:"applications",className:"mt-6",children:e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsx(U,{children:"Job Applications"}),e.jsxs(xe,{value:c||"all",onValueChange:y=>r(y==="all"?void 0:y),children:[e.jsx(me,{className:"w-[250px]",children:e.jsx(ue,{placeholder:"Filter by job"})}),e.jsxs(je,{children:[e.jsx(E,{value:"all",children:"All Applications"}),j==null?void 0:j.map(y=>e.jsx(E,{value:y.id,children:y.title},y.id))]})]})]})}),e.jsx(F,{className:"p-0",children:w?e.jsx("div",{className:"p-8 text-center",children:e.jsx(se,{className:"h-8 w-8 animate-spin mx-auto"})}):e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Applicant"}),e.jsx(g,{children:"Job"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Applied"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:k&&k.length>0?k.map(y=>{var T,ke;return e.jsxs(M,{children:[e.jsx(p,{children:e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[y.first_name," ",y.last_name]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.email})]})}),e.jsx(p,{children:e.jsx("div",{className:"text-sm",children:((T=y.job)==null?void 0:T.title)||"â"})}),e.jsx(p,{children:e.jsxs(xe,{value:y.status||"pending",onValueChange:Re=>Ye(y.id,Re),children:[e.jsx(me,{className:"w-[130px]",children:e.jsx(ue,{})}),e.jsx(je,{children:Xn.map(Re=>e.jsx(E,{value:Re.value,children:Re.label},Re.value))})]})}),e.jsx(p,{children:R(new Date(y.created_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(Y,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>x(y),children:e.jsx(Ke,{className:"h-4 w-4"})})}),e.jsxs(Z,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsx(ee,{children:"Application Details"})}),d&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-2 uppercase tracking-wide",children:"Personal Information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Name"}),e.jsxs("p",{className:"font-medium",children:[d.first_name," ",d.last_name]})]}),e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Email"}),e.jsx("p",{className:"font-medium",children:d.email})]}),e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Phone"}),e.jsx("p",{className:"font-medium",children:d.phone})]}),e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"WhatsApp"}),e.jsx("p",{className:"font-medium",children:d.whatsapp||"â"})]}),d.gender&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Gender"}),e.jsx("p",{className:"font-medium capitalize",children:d.gender})]}),d.date_of_birth&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Date of Birth"}),e.jsx("p",{className:"font-medium",children:R(new Date(d.date_of_birth),"MMM d, yyyy")})]}),d.nationality&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Nationality"}),e.jsx("p",{className:"font-medium",children:d.nationality})]})]})]}),(d.street_address||d.city||d.country)&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-2 uppercase tracking-wide",children:"Address"}),e.jsx("p",{className:"font-medium",children:[d.street_address,d.city,d.state_province,d.country,d.postal_code].filter(
67Boolean).join(", ")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-2 uppercase tracking-wide",children:"Professional Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Experience"}),e.jsxs("p",{className:"font-medium",children:[d.years_of_experience??0," years"]})]}),e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Expected Salary"}),e.jsx("p",{className:"font-medium",children:d.expected_salary?`PKR ${d.expected_salary.toLocaleString()}`:"N/A"})]}),d.current_position&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Current Position"}),e.jsx("p",{className:"font-medium",children:d.current_position})]}),d.current_company&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Current Company"}),e.jsx("p",{className:"font-medium",children:d.current_company})]}),d.availability_date&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Available From"}),e.jsx("p",{className:"font-medium",children:R(new Date(d.availability_date),"MMM d, yyyy")})]})]})]}),d.skills&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Skills"}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.skills})]}),d.education_details&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Education"}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.education_details})]}),d.work_experience&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Work Experience"}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.work_experience})]}),d.projects&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Projects"}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.projects})]}),d.cover_letter&&e.jsxs("div",{children:[e.jsx(u,{className:"text-muted-foreground text-xs",children:"Cover Letter"}),e.jsx("p",{className:"whitespace-pre-wrap",children:d.cover_letter})]}),(d.resume_url||d.portfolio_url||d.linkedin_url||d.github_url)&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-2 uppercase tracking-wide",children:"Links"}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[d.resume_url&&e.jsxs("button",{type:"button",onClick:()=>he(d.resume_url),className:"inline-flex items-center gap-1 text-primary hover:underline text-sm",children:["Resume ",e.jsx(He,{className:"h-3 w-3"})]}),d.portfolio_url&&e.jsxs("a",{href:d.portfolio_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline text-sm",children:["Portfolio ",e.jsx(He,{className:"h-3 w-3"})]}),d.linkedin_url&&e.jsxs("a",{href:d.linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline text-sm",children:["LinkedIn ",e.jsx(He,{className:"h-3 w-3"})]}),d.github_url&&e.jsxs("a",{href:d.github_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline text-sm",children:["GitHub ",e.jsx(He,{className:"h-3 w-3"})]})]})]})]})]})]}),y.resume_url&&e.jsx(v,{variant:"ghost",size:"icon",title:"Download resume",onClick:()=>ve(y.resume_url),children:e.jsx(Zs,{className:"h-4 w-4"})}),e.jsxs(Se,{children:[e.jsx(ma,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",title:"Delete application",className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(pe,{className:"h-4 w-4"})})}),e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete this application?"}),e.jsxs(Me,{children:["This will permanently remove ",y.first_name," ",y.last_name,`'s application for "`,((ke=y.job)==null?void 0:ke.title)||"this role",'". This action cannot be undone.']})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>Ce(y.id),children:"Delete"})]})]})]})]})})]},y.id)}):e.jsx(M,{children:e.jsxs(p,{colSpan:5,className:"text-center py-8",children:[e.jsx(Le,{className:"h-12 w-12 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"No applications yet"})]})})})]})})]})})]})})};function Ta(s=""){return J({queryKey:["admin-all-users",s],queryFn:async()=>{let l=C.from("profiles").select("*").order("created_at",{ascending:!1});s.trim()&&(l=l.or(`email.ilike.%${s}%,full_name.ilike.%${s}%`));const{data:a,error:n}=await l.limit(100);if(n)throw n;const{data:i,error:o}=await C.from("user_roles").select("user_id, role");
67if(o)throw o;const t=(i||[]).reduce((m,c)=>(m[c.user_id]||(m[c.user_id]=[]),m[c.user_id].push(c.role),m),{});return(a||[]).map(m=>({...m,roles:t[m.id]||[]}))}})}function sr(){const s=B();return O({mutationFn:async({userId:l,role:a})=>{const{error:n}=await C.from("user_roles").insert({user_id:l,role:a});if(n)throw n.code==="23505"?new Error("User already has this role"):n},onSuccess:(l,{role:a})=>{A.success(`Role "${a}" added successfully`),s.invalidateQueries({queryKey:["admin-all-users"]})},onError:l=>{A.error(l.message)}})}function ar(){const s=B();return O({mutationFn:async({userId:l,role:a})=>{const{error:n}=await C.from("user_roles").delete().eq("user_id",l).eq("role",a);if(n)throw n},onSuccess:(l,{role:a})=>{A.success(`Role "${a}" removed`),s.invalidateQueries({queryKey:["admin-all-users"]})},onError:l=>{A.error(l.message)}})}const tr=["super_admin","admin","moderator","instructor","blogger","student","freelancer","client","user"],nr={super_admin:"bg-yellow-500/10 text-yellow-600 border-yellow-500/20",admin:"bg-red-500/10 text-red-600 border-red-500/20",moderator:"bg-teal-500/10 text-teal-600 border-teal-500/20",instructor:"bg-purple-500/10 text-purple-600 border-purple-500/20",blogger:"bg-pink-500/10 text-pink-600 border-pink-500/20",student:"bg-blue-500/10 text-blue-600 border-blue-500/20",freelancer:"bg-green-500/10 text-green-600 border-green-500/20",client:"bg-orange-500/10 text-orange-600 border-orange-500/20",user:"bg-gray-500/10 text-gray-600 border-gray-500/20"},rr=()=>{var _,k;const[s,l]=b.useState(""),[a,n]=b.useState(""),[i,o]=b.useState(null),{data:t,isLoading:m}=Ta(a),c=sr(),r=ar(),d=w=>{l(w),clearTimeout(window.__userSearchTimeout),window.__userSearchTimeout=setTimeout(()=>{n(w)},400)},x=async()=>{if(!i)return;const{user:w,role:S,action:V}=i;V==="add"?await c.mutateAsync({userId:w.id,role:S}):await r.mutateAsync({userId:w.id,role:S}),o(null)},j=w=>tr.filter(S=>!w.roles.includes(S));return m?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"User Management"})}),e.jsxs(F,{className:"space-y-4",children:[e.jsx(ne,{className:"h-10 w-full"}),[1,2,3,4].map(w=>e.jsx(ne,{className:"h-14"},w))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Le,{className:"h-5 w-5"}),"User Management",e.jsx(D,{variant:"secondary",children:(t==null?void 0:t.length)??0})]}),e.jsxs("div",{className:"relative w-full sm:w-72",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search by name or email...",value:s,onChange:w=>d(w.target.value),className:"pl-9"})]})]})}),e.jsx(F,{className:"p-0",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"User"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Roles"}),e.jsx(g,{children:"Joined"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:t&&t.length>0?t.map(w=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:w.full_name||"â"}),e.jsx(p,{className:"text-muted-foreground text-sm",children:w.email}),e.jsx(p,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:w.roles.length>0?w.roles.map(S=>{var V;return e.jsxs(D,{variant:"outline",className:`text-xs ${nr[S]||""}`,children:[((V=xs[S])==null?void 0:V.label)||S,e.jsx("button",{onClick:()=>o({user:w,role:S,action:"remove"}),className:"ml-1 hover:text-destructive",children:e.jsx(ss,{className:"h-3 w-3"})})]},S)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No roles"})})}),e.jsx(p,{className:"text-muted-foreground text-sm",children:R(new Date(w.created_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsxs(Ps,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",children:e.jsx(mn,{className:"h-4 w-4"})})}),e.jsxs(As,{align:"end",children:[e.jsx(Za,{children:"Add Role"}),e.jsx(Xa,{}),j(w).length>0?j(w).map(S=>{var V;return e.jsxs(as,{onClick:()=>o({user:w,role:S,action:"add"}),children:[e.jsx(we,{className:"h-3 w-3 mr-2"}),((V=xs[S])==null?void 0:V.label)||S]},S)}):e.jsx(as,{disabled:!0,children:"All roles assigned"})]})]})})]},w.id)):e.jsx(M,{children:e.jsx(p,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:a?"No users found":"No users yet"})})})]})})]}),e.jsx(Se,{open:!!i,onOpenChange:()=>o(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:(i==null?void 0:i.action)==="add"?"Add Role":"Revoke Role"}),e.jsx(Me,{children:i?i.action==="add"?`Add "${(_=xs[i.role])==null?void 0:_.label}" role to ${i.user.full_name||i.user.email}?`:`Revoke "${(k=xs[i.role])==null?void 0:k.label}" role from ${i.user.full_name||i.user.email}? They will lose all permissions for this role and must submit a new request to get it back.`:""})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsxs(qe,{onClick:x,disabled:c.isPending||r.isPending,children:[(c.isPending||r.isPending)&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Confirm"]})]})]})})]})};function ir(){return J({queryKey:["admin-all-courses"],queryFn:async()=>{const{data:s,error:l}=await C.from("courses").select(` 68 id, title, slug, level, price, is_published, is_featured, created_at, duration_hours, 69 category:course_categories(name), 70 instructor:profiles!courses_instructor_id_fkey(full_name) 71 `).order("created_at",{ascending:!1});if(l)throw l;const{data:a}=await C.from("enrollments").select("course_id"),n={};
71return(a||[]).forEach(i=>{n[i.course_id]=(n[i.course_id]||0)+1}),(s||[]).map(i=>({...i,enrollments_count:n[i.id]||0}))}})}function lr(){const s=B();return O({mutationFn:async({id:l,...a})=>{const{error:n}=await C.from("courses").update(a).eq("id",l);if(n)throw n},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-all-courses"]}),s.invalidateQueries({queryKey:["admin-stats"]})},onError:l=>{A.error(l.message)}})}function cr(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("courses").delete().eq("id",l);if(a)throw a},onSuccess:()=>{A.success("Course deleted"),s.invalidateQueries({queryKey:["admin-all-courses"]}),s.invalidateQueries({queryKey:["admin-stats"]})},onError:l=>{A.error(l.message)}})}const dr={beginner:"bg-green-500/10 text-green-700",intermediate:"bg-yellow-500/10 text-yellow-700",advanced:"bg-red-500/10 text-red-700"},or=()=>{const{data:s,isLoading:l}=ir(),a=lr(),n=cr(),[i,o]=b.useState(null),t=async(r,d)=>{try{await a.mutateAsync({id:r,is_published:!d}),A.success(d?"Course unpublished":"Course published")}catch{}},m=async(r,d)=>{try{await a.mutateAsync({id:r,is_featured:!d}),A.success(d?"Removed from featured":"Added to featured")}catch{}},c=async()=>{if(i)try{await n.mutateAsync(i),o(null)}catch{A.error("Failed to delete course")}};return l?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"All Courses"})}),e.jsx(F,{children:e.jsx("div",{className:"space-y-4",children:[1,2,3].map(r=>e.jsx(ne,{className:"h-16"},r))})})]}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:["All Courses",s&&e.jsx(D,{variant:"secondary",children:s.length})]})}),e.jsx(F,{children:s&&s.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Title"}),e.jsx(g,{children:"Instructor"}),e.jsx(g,{children:"Category"}),e.jsx(g,{children:"Level"}),e.jsx(g,{className:"text-center",children:e.jsx(Le,{className:"h-4 w-4 inline"})}),e.jsx(g,{children:"Price"}),e.jsx(g,{children:"Published"}),e.jsx(g,{children:"Featured"}),e.jsx(g,{children:"Date"}),e.jsx(g,{className:"w-[60px]"})]})}),e.jsx(oe,{children:s.map(r=>{var d,x;return e.jsxs(M,{children:[e.jsx(p,{className:"font-medium max-w-[200px] truncate",children:r.title}),e.jsx(p,{children:((d=r.instructor)==null?void 0:d.full_name)||"â"}),e.jsx(p,{children:((x=r.category)==null?void 0:x.name)||"â"}),e.jsx(p,{children:e.jsx(D,{variant:"outline",className:dr[r.level||""]||"",children:r.level||"â"})}),e.jsx(p,{className:"text-center",children:r.enrollments_count}),e.jsxs(p,{children:["$",r.price]}),e.jsx(p,{children:e.jsx(G,{checked:r.is_published||!1,onCheckedChange:()=>t(r.id,r.is_published||!1),disabled:a.isPending})}),e.jsx(p,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>m(r.id,r.is_featured||!1),disabled:a.isPending,className:r.is_featured?"text-yellow-500":"text-muted-foreground",children:e.jsx(Ms,{className:`h-4 w-4 ${r.is_featured?"fill-current":""}`})})}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(r.created_at),"MMM d, yyyy")}),e.jsx(p,{children:e.jsxs(Ps,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",children:e.jsx(Ys,{className:"h-4 w-4"})})}),e.jsxs(As,{align:"end",children:[e.jsx(as,{asChild:!0,children:e.jsxs(ms,{to:`/courses/${r.slug}`,children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"})," View"]})}),e.jsxs(as,{className:"text-destructive",onClick:()=>o(r.id),children:[e.jsx(pe,{className:"h-4 w-4 mr-2"})," Delete"]})]})]})})]},r.id)})})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(bs,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No courses yet"})]})}),e.jsx(Se,{open:!!i,onOpenChange:()=>o(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Course?"}),e.jsx(Me,{children:"This will permanently delete the course, its modules, lessons, and all enrollments."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:c,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})};function hr(){return J({queryKey:["admin-all-freelance-projects"],queryFn:async()=>{const{data:s,error:l}=await C.from("freelance_projects").select(` 72 id, title, category, status, budget_type, budget_min, budget_max, 73 proposals_count, is_featured, is_urgent, created_at, 74 client:profiles!freelance_projects_client_id_fkey(full_name, email) 75 `).order("created_at",{ascending:!1});if(l)throw l;return s}})}function xr(){return J({queryKey:["admin-all-proposals"],queryFn:async()=>{const{data:s,error:l}=await C.from("freelance_proposals").select(` 76 id, proposed_rate, status, created_at, cover_letter, estimated_duration, 77 freelancer:freelancer_profiles(user:profiles!freelancer_profiles_user_id_fkey(full_name, email)), 78 project:freelance_projects(title) 79 `).order("created_at",{ascending:!1});if(l)throw l;return s}})}function mr(){const s=B();return O({mutationFn:async({id:l,...a})=>{const{error:n}=await C.from("freelance_projects").update(a).eq("id",l);if(n)throw n},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-all-freelance-projects"]}),s.invalidateQueries({queryKey:["admin-stats"]})},onError:l=>{A.error(l.message)}})}function ur(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("freelance_projects").delete().eq("id",l);if(a)throw a},onSuccess:()=>{A.success("Project deleted"),s.invalidateQueries({queryKey:["admin-all-freelance-projects"]}),s.invalidateQueries({queryKey:["admin-stats"]})},onError:l=>{A.error(l.message)}})}const ya={open:"bg-green-500/10 text-green-700",in_progress:"bg-blue-500/10 text-blue-700",completed:"bg-purple-500/10 text-purple-700",cancelled:"bg-red-500/10 text-red-700",pending:"bg-yellow-500/10 text-yellow-700",accepted:"bg-green-500/10 text-green-700",rejected:"bg-red-500/10 text-red-700"},jr=["open","in_progress","completed","cancelled"],pr=()=>{const[s,l]=b.useState("projects"),{data:a,isLoading:n}=hr(),{data:i,isLoading:o}=xr(),t=mr(),m=ur(),[c,r]=b.useState(null),d=async(_,k)=>{try{await t.mutateAsync({id:_,status:k}),A.success(`Project status updated to ${k}`)}catch{}},x=async(_,k)=>{try{await t.mutateAsync({id:_,is_featured:!k}),A.success(k?"Removed from featured":"Added to featured")}catch{}},j=async()=>
79{if(c)try{await m.mutateAsync(c),r(null)}catch{A.error("Failed to delete project")}};return n?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ne,{className:"h-12 w-full"}),e.jsx(ne,{className:"h-64 w-full"})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(Je,{value:s,onValueChange:l,children:[e.jsxs(Ge,{children:[e.jsxs(le,{value:"projects",className:"gap-2",children:[e.jsx(ds,{className:"h-4 w-4"})," Projects"]}),e.jsxs(le,{value:"proposals",className:"gap-2",children:[e.jsx(Oe,{className:"h-4 w-4"})," Proposals"]})]}),e.jsx(ge,{value:"projects",className:"mt-6",children:e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:["All Freelance Projects",a&&e.jsx(D,{variant:"secondary",children:a.length})]})}),e.jsx(F,{children:a&&a.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Title"}),e.jsx(g,{children:"Client"}),e.jsx(g,{children:"Category"}),e.jsx(g,{children:"Budget"}),e.jsx(g,{children:"Proposals"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Featured"}),e.jsx(g,{children:"Date"}),e.jsx(g,{className:"w-[60px]"})]})}),e.jsx(oe,{children:a.map(_=>{var k;return e.jsxs(M,{children:[e.jsxs(p,{className:"font-medium max-w-[200px] truncate",children:[_.title,_.is_urgent&&e.jsx(Tt,{className:"h-3 w-3 text-red-500 inline ml-1"})]}),e.jsx(p,{children:((k=_.client)==null?void 0:k.full_name)||"â"}),e.jsx(p,{children:_.category}),e.jsx(p,{children:_.budget_min&&_.budget_max?`$${_.budget_min} - $${_.budget_max}`:_.budget_type||"â"}),e.jsx(p,{className:"text-center",children:_.proposals_count||0}),e.jsx(p,{children:e.jsxs(xe,{value:_.status||"open",onValueChange:w=>d(_.id,w),children:[e.jsx(me,{className:"w-[130px] h-8",children:e.jsx(ue,{})}),e.jsx(je,{children:jr.map(w=>e.jsx(E,{value:w,children:e.jsx(D,{variant:"outline",className:ya[w]||"",children:w.replace("_"," ")})},w))})]})}),e.jsx(p,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>x(_.id,_.is_featured||!1),className:_.is_featured?"text-yellow-500":"text-muted-foreground",children:e.jsx(Ms,{className:`h-4 w-4 ${_.is_featured?"fill-current":""}`})})}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(_.created_at),"MMM d, yyyy")}),e.jsx(p,{children:e.jsxs(Ps,{children:[e.jsx(Ds,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",children:e.jsx(Ys,{className:"h-4 w-4"})})}),e.jsx(As,{align:"end",children:e.jsxs(as,{className:"text-destructive",onClick:()=>r(_.id),children:[e.jsx(pe,{className:"h-4 w-4 mr-2"})," Delete"]})})]})})]},_.id)})})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ds,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No freelance projects yet"})]})})]})}),e.jsx(ge,{value:"proposals",className:"mt-6",children:e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:["All Proposals",i&&e.jsx(D,{variant:"secondary",children:i.length})]})}),e.jsx(F,{children:o?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(_=>e.jsx(ne,{className:"h-16"},_))}):i&&i.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Freelancer"}),e.jsx(g,{children:"Project"}),e.jsx(g,{children:"Rate"}),e.jsx(g,{children:"Duration"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Date"})]})}),e.jsx(oe,{children:i.map(_=>{var k,w,S;return e.jsxs(M,{children:[e.jsx(p,{children:((w=(k=_.freelancer)==null?void 0:k.user)==null?void 0:w.full_name)||"â"}),e.jsx(p,{className:"font-medium max-w-[200px] truncate",children:((S=_.project)==null?void 0:S.title)||"â"}),e.jsxs(p,{children:["$",_.proposed_rate]}),e.jsx(p,{children:_.estimated_duration||"â"}),e.jsx(p,{children:e.jsx(D,{variant:"outline",className:ya[_.status||""]||"",children:_.status||"pending"})}),e.jsx(p,{className:"text-muted-foreground",children:R(new Date(_.created_at),"MMM d, yyyy")})]},_.id)})})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Oe,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No proposals yet"})]})})]})})]}),e.jsx(Se,{open:!!c,onOpenChange:()=>r(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Project?"}),e.jsx(Me,{children:"This will permanently delete the project and all its proposals."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})};function Fa(){return J({queryKey:["admin-team-members"],queryFn:async()=>{const{data:s,error:l}=await C.from("team_members").select("*").order("display_order",{ascending:!0});if(l)throw l;return s}})}function gr(){const s=B(),{toast:l}=Qe();return O({mutationFn:async a=>{const{data:n,error:i}=await C.from("team_members").insert({user_id:a.user_id,display_name:a.display_name,role_title:a.role_title,is_visible:!0}).select().single();if(i)throw i;return n},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-team-members"]}),s.invalidateQueries({queryKey:["team-members"]}),l({title:"Team member added"})},onError:a=>{l({title:"Error",description:a.message,variant:"destructive"})}})}function vr(){const s=B(),{toast:l}=Qe();return O({mutationFn:async({id:a,is_visible:n})=>{const{error:i}=await C.from("team_members").update({is_visible:n}).eq("id",a);if(i)throw i},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-team-members"]}),s.invalidateQueries({queryKey:["team-members"]})},onError:a=>{l({title:"Error",description:a.message,variant:"destructive"})}})}function yr(){const s=B(),{toast:l}=Qe();return O({mutationFn:async a=>{const{error:n}=await C.from("team_members").delete().eq("id",a);if(n)throw n},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-team-members"]}),s.invalidateQueries({queryKey:["team-members"]}),l({title:"Team member removed"})},onError:a=>{l({title:"Error",description:a.message,variant:"destructive"})}})}var fr="Separator",fa="horizontal",Nr=["horizontal","vertical"],qa=b.forwardRef((s,l)=>{const{decorative:a,orientation:n=fa,...i}=s,o=_r(n)?n:fa,m=a?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return e.jsx(et.div,{"data-orientation":o,...m,...i,ref:l})});qa.displayName=fr;function _r(s){return Nr.includes(s)}var La=qa;const Be=b.forwardRef(({className:s,orientation:l="horizontal",decorative:a=!0,...n},i)=>e.jsx(La,{ref:i,decorative:a,orientation:l,className:Ks("shrink-0 bg-border",l==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...n}));Be.displayName=La.displayName;function br(){const s=B(),{toast:l}=Qe();return O({mutationFn:async({userId:a,ban:n})=>{const{data:i,error:o}=await C.functions.invoke("admin-ban-user",{body:{user_id:a,ban:n}});if(o)throw o;if(i!=null&&i.error)throw new Error(i.error);return i},onSuccess:(a,{ban:n})=>{l({title:n?"Account blocked":"Account unblocked"}),s.invalidateQueries({queryKey:["admin-team-members"]})},onError:a=>l({title:"Error",description:a.message,variant:"destructive"})})}function wr(s=new Date){const l=s.getFullYear(),a=s.getMonth(),n=s.getDate()>=11?0:-1,i=new Date(l,a+n,11),o=new Date(l,a+n+1,10),t=m=>`${m.getFullYear()}
79-${String(m.getMonth()+1).padStart(2,"0")}-${String(m.getDate()).padStart(2,"0")}`;return{from:t(i),to:t(o)}}const Cr=()=>{var ta,na,ra,ia,la,ca;const{user:s}=rs(),{data:l,isLoading:a}=Fa(),{data:n}=Ta(""),{data:i}=qt(),o=gr(),t=vr(),m=Lt(),c=Rt(),r=yr(),d=Et(),x=It(),j=Ut(),_=zt(),k=br(),{toast:w}=Qe(),[S,V]=b.useState(!1),[L,q]=b.useState(null),[Q,ve]=b.useState(null),[he,Ce]=b.useState(null),[vs,ys]=b.useState(null),[W,os]=b.useState(null),[re,We]=b.useState(null),[Ye,y]=b.useState({reason:"",since:new Date().toISOString().split("T")[0]}),[T,ke]=b.useState(null),[Re,Ra]=b.useState("active"),[is,fs]=b.useState(null),[qs,Ls]=b.useState(null),[Ee,Ns]=b.useState({user_id:"",display_name:"",role_title:""}),[$,H]=b.useState({}),[z,Ie]=b.useState({basic_pay:"",bonus:"",period_type:"monthly",period_from:"",period_to:"",description:"",payment_method:"",payment_date:new Date().toISOString().split("T")[0]}),[ae,$e]=b.useState({basic_pay:"",bonus:"",period_type:"monthly",period_from:"",period_to:"",description:"",payment_method:"",payment_date:""}),Ea=(l==null?void 0:l.map(h=>h.user_id))??[],Ia=(n==null?void 0:n.filter(h=>!Ea.includes(h.id)))??[],ea=(l??[]).filter(h=>(h.employment_status??"active")==="active"),sa=(l??[]).filter(h=>h.employment_status==="inactive"),aa=Re==="active"?ea:sa,Ua=async()=>{!Ee.user_id||!Ee.display_name||!Ee.role_title||(await o.mutateAsync(Ee),Ns({user_id:"",display_name:"",role_title:""}),V(!1))},za=h=>{const f=n==null?void 0:n.find(te=>te.id===h);Ns({user_id:h,display_name:(f==null?void 0:f.full_name)||"",role_title:""})},Oa=h=>{ve(h),H({display_name:h.display_name||"",role_title:h.role_title||"",department:h.department||"",position_title:h.position_title||"",display_order:h.display_order||0,joining_date:h.joining_date||"",is_visible:h.is_visible??!0,is_founder:h.is_founder??!1,gender:h.gender||"male",bio:h.bio||"",photo_url:h.photo_url||"",phone:h.phone||"",personal_email:h.personal_email||"",company_email:h.company_email||"",date_of_birth:h.date_of_birth||"",national_id:h.national_id||"",emergency_contact_name:h.emergency_contact_name||"",emergency_contact_phone:h.emergency_contact_phone||"",address:h.address||"",city:h.city||"",country:h.country||"",linkedin_url:h.linkedin_url||"",facebook_url:h.facebook_url||"",youtube_url:h.youtube_url||"",contract_start:h.contract_start||"",contract_end:h.contract_end||""})},Ka=async()=>{Q&&(await c.mutateAsync({id:Q.id,...$}),ve(null))},$a=async h=>{Ce(h);const f=new Date,{from:te,to:Ue}=wr(f);Ie({basic_pay:"",bonus:"",period_type:"monthly",period_from:te,period_to:Ue,description:"",payment_method:"",payment_date:f.toISOString().split("T")[0]});try{const{data:fe}=await C.from("team_member_sensitive").select("salary_amount").eq("member_id",h.id).maybeSingle();fe!=null&&fe.salary_amount&&Ie(ze=>({...ze,basic_pay:String(fe.salary_amount)}))}catch{}},Rs=(parseFloat(z.basic_pay)||0)+(parseFloat(z.bonus)||0),Va=async()=>{if(!he||!z.basic_pay||!s)return;const h=Rs;let f=z.description||"";if(!f){const te=[];z.period_type==="monthly"?te.push("Monthly Salary"):te.push("Daily Rate Payment"),z.period_from&&z.period_to&&te.push(`(${R(new Date(z.period_from),"MMM d, yyyy")} â ${R(new Date(z.period_to),"MMM d, yyyy")})`),f=te.join(" ")}await x.mutateAsync({member_id:he.id,amount:h,payment_date:z.payment_date,description:f,payment_method:z.payment_method||void 0,created_by:s.id,basic_pay:parseFloat(z.basic_pay)||0,bonus:parseFloat(z.bonus)||0,period_type:z.period_type,period_from:z.period_from||void 0,period_to:z.period_to||void 0}),Ce(null)},Ba=h=>{fs(h),$e({basic_pay:String(h.basic_pay||h.amount||""),bonus:String(h.bonus||"0"),period_type:h.period_type||"monthly",period_from:h.period_from||"",period_to:h.period_to||"",description:h.description||"",payment_method:h.payment_method||"",payment_date:h.payment_date||""})},Es=(parseFloat(ae.basic_pay)||0)+(parseFloat(ae.bonus)||0),Ha=async()=>{is&&(await j.mutateAsync({id:is.id,amount:Es,basic_pay:parseFloat(ae.basic_pay)||0,bonus:parseFloat(ae.bonus)||0,period_type:ae.period_type,period_from:ae.period_from||void 0,period_to:ae.period_to||void 0,description:ae.description||void 0,payment_method:ae.payment_method||void 0,payment_date:ae.payment_date}),fs(null))};return a?e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{children:"Team Management"})}),e.jsx(F,{className:"space-y-4",children:[1,2,3].map(h=>e.jsx(ne,{className:"h-14"},h))})]}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{children:[e.jsxs(I,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Le,{className:"h-5 w-5"}),"Team Management",e.jsx(D,{variant:"secondary",children:(l==null?void 0:l.length)??0})]}),e.jsxs(v,{onClick:()=>V(!0),size:"sm",children:[e.jsx(we,{className:"h-4 w-4 mr-2"}),"Add Team Member"]})]}),e.jsx(Je,{value:Re,onValueChange:h=>Ra(h),className:"mt-4",children:e.jsxs(Ge,{children:[e.jsxs(le,{value:"active",children:["Active (",ea.length,")"]}),e.jsxs(le,{value:"inactive",children:["Inactive (",sa.length,")"]})]})})]}),e.jsx(F,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Photo"}),e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Role"}),e.jsx(g,{children:"Department"}),e.jsx(g,{children:"Phone"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Order"}),e.jsx(g,{children:"Joined"}),e.jsx(g,{children:Re==="inactive"?"Left / Reason":"Status"}),e.jsx(g,{children:"Visible"}),e.jsx(g,{children:"Locked"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:aa.length>0?aa.map(h=>{var f;return e.jsxs(M,{children:[e.jsx(p,{children:e.jsxs(us,{className:"h-10 w-10",children:[h.photo_url?e.jsx(js,{src:h.photo_url,alt:h.display_name,className:"object-cover"}):null,e.jsx(ps,{className:"bg-primary/10 text-primary text-xs",children:((f=h.display_name)==null?void 0:f.split(" ").map(te=>te[0]).join("").slice(0,2).toUpperCase())||e.jsx(Ca,{className:"h-4 w-4"})})]})}),e.jsx(p,{className:"font-medium whitespace-nowrap",children:h.display_name}),e.jsx(p,{className:"text-muted-foreground whitespace-nowrap",children:h.role_title}),e.jsx(p,{className:"text-muted-foreground",children:h.department||"â"}),e.jsx(p,{className:"text-muted-foreground text-xs",children:h.phone||"â"}),e.jsx(p,{className:"text-muted-foreground text-xs",children:h.company_email||h.personal_email||"â"}),e.jsxs(p,{children:["#",h.display_order||0]}),e.jsx(p,{className:"text-xs whitespace-nowrap",children:h.joining_date?R(new Date(h.joining_date),"MMM d, yyyy"):"â"}),e.jsx(p,{className:"text-xs max-w-[220px]",children:h.employment_status==="inactive"?e.jsxs("div",{children:[e.jsx(D,{variant:"outline",className:"text-muted-foreground",children:h.inactive_since?R(new Date(h.inactive_since),"MMM d, yyyy"):"Inactive"}),h.inactive_reason&&e.jsx("p",{className:"text-muted-foreground mt-1 line-clamp-2",children:h.inactive_reason})]}):e.jsx(D,{className:"bg-green-500/10 text-green-600 border-green-500/20",children:"Active"})}),e.jsx(p,{children:e.jsx(G,{checked:h.is_visible??!0,onCheckedChange:te=>t.mutate({id:h.id,is_visible:te})})}),e.jsx(p,{children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>m.mutate({id:h.id,is_locked:!(h.is_locked??!1)}),className:h.is_locked?"text-destructive":"text-muted-foreground",title:h.is_locked?"Unlock Profile":"Lock Profile",children:h.is_locked?e.jsx(an,{className:"h-4 w-4"}):e.jsx(gn,{className:"h-4 w-4"})})}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex gap-0.5 justify-end",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>ys(h),title:"View Details",children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>Oa(h),title:"Edit All Info",children:e.jsx(Hs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>$a(h),title:"Add Payment",children:e.jsx(Qs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>ke(h),title:"Update Basic Pay",children:e.jsx(tn,{className:"h-4 w-4"})}),h.employment_status==="inactive"?e.jsx(v,{variant:"ghost",size:"icon",title:"Mark as Active",className:"text-green-600 hover:text-green-700",onClick:()=>{y({reason:"",since:new Date().toISOString().split("T")[0]}),We({member:h,makeInactive:!1})},children:e.jsx(Dt,{className:"h-4 w-4"})}):e.jsx(v,{variant:"ghost",size:"icon",title:"Mark as Inactive",className:"text-amber-600 hover:text-amber-700",onClick:()=>{y({reason:"",since:new Date().toISOString().split("T")[0]}),We({member:h,makeInactive:!0})},children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>os({member:h,ban:!0}),title:"Block Account",className:"text-orange-600 hover:text-orange-700",children:e.jsx(ua,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>q(h.id),className:"text-destructive hover:text-destructive",children:e.jsx(pe,{className:"h-4 w-4"})})]})})]}
79,h.id)}):e.jsx(M,{children:e.jsx(p,{colSpan:12,className:"text-center py-8 text-muted-foreground",children:Re==="inactive"?"No inactive team members.":"No active team members yet. Add one to get started."})})})]})})})]}),i&&i.length>0&&e.jsxs(P,{className:"mt-6",children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Qs,{className:"h-5 w-5"})," Recent Payments"]})}),e.jsx(F,{className:"p-0",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Member"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Date"}),e.jsx(g,{children:"Description"}),e.jsx(g,{children:"Method"}),e.jsx(g,{children:"Status"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:i.slice(0,20).map(h=>{var f;return e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:((f=h.member)==null?void 0:f.display_name)||"â"}),e.jsxs(p,{className:"font-bold",children:["PKR ",Number(h.amount).toLocaleString()]}),e.jsx(p,{children:R(new Date(h.payment_date),"MMM d, yyyy")}),e.jsx(p,{className:"text-muted-foreground",children:h.description||"â"}),e.jsx(p,{children:h.payment_method||"â"}),e.jsx(p,{children:e.jsx(D,{children:h.status})}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(v,{variant:"ghost",size:"icon",title:"Download Payslip PDF",onClick:()=>{var te,Ue,fe,ze,Ze,Xe,da,oa,ha;return Ft({employee:{name:((te=h.member)==null?void 0:te.display_name)||"Employee",role:(Ue=h.member)==null?void 0:Ue.role_title,email:((fe=h.member)==null?void 0:fe.company_email)||((ze=h.member)==null?void 0:ze.personal_email),employeeId:(Ze=h.member)==null?void 0:Ze.employee_code,bankName:(Xe=h.member)==null?void 0:Xe.bank_name,bankAccount:(da=h.member)==null?void 0:da.bank_account_number,iban:(oa=h.member)==null?void 0:oa.bank_iban,taxId:(ha=h.member)==null?void 0:ha.tax_id},payment:h})},children:e.jsx(Zs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",title:"Email payslip notification",onClick:async()=>{var ze,Ze,Xe;const te=((ze=h.member)==null?void 0:ze.company_email)||((Ze=h.member)==null?void 0:Ze.personal_email);if(!te){w({title:"No email on file",variant:"destructive"});return}const Ue=h.payment_date?R(new Date(h.payment_date),"MMMM yyyy"):"the latest pay period",{error:fe}=await C.functions.invoke("send-email",{body:{template:"payslip_notice",data:{email:te,full_name:(Xe=h.member)==null?void 0:Xe.display_name,period:Ue,amount:`${h.currency||"PKR"} ${Number(h.amount).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`,payment_date:h.payment_date?R(new Date(h.payment_date),"d MMMM yyyy"):void 0,portal_url:`${window.location.origin}/team/profile`}}});w(fe?{title:"Failed to send email",description:fe.message,variant:"destructive"}:{title:`Payslip notification sent to ${te}`})},children:e.jsx(es,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>Ba(h),title:"Edit Payment",children:e.jsx(Hs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>Ls(h.id),title:"Delete Payment",className:"text-destructive hover:text-destructive",children:e.jsx(pe,{className:"h-4 w-4"})})]})})]},h.id)})})]})})]}),e.jsx(Y,{open:S,onOpenChange:V,children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(ee,{children:"Add Team Member"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Select User"}),e.jsxs(xe,{value:Ee.user_id,onValueChange:za,children:[e.jsx(me,{children:e.jsx(ue,{placeholder:"Choose a registered user..."})}),e.jsx(je,{children:Ia.map(h=>e.jsxs(E,{value:h.id,children:[h.full_name||h.email," (",h.email,")"]},h.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Display Name"}),e.jsx(N,{value:Ee.display_name,onChange:h=>Ns(f=>({...f,display_name:h.target.value})),placeholder:"e.g. John Doe"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Role / Title"}),e.jsx(N,{value:Ee.role_title,onChange:h=>Ns(f=>({...f,role_title:h.target.value})),placeholder:"e.g. CTO"})]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>V(!1),children:"Cancel"}),e.jsxs(v,{onClick:Ua,disabled:!Ee.user_id||!Ee.display_name||!Ee.role_title||o.isPending,children:[o.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Add Member"]})]})]})}),e.jsx(Y,{open:!!Q,onOpenChange:()=>ve(null),children:e.jsxs(Z,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Edit: ",Q==null?void 0:Q.display_name]})}),e.jsx(ls,{className:"max-h-[65vh] pr-4",children:e.jsxs(Je,{defaultValue:"basic",className:"w-full",children:[e.jsxs(Ge,{className:"grid w-full grid-cols-4",children:[e.jsx(le,{value:"basic",children:"Basic"}),e.jsx(le,{value:"contact",children:"Contact"}),e.jsx(le,{value:"personal",children:"Personal"}),e.jsx(le,{value:"contract",children:"Contract"})]}
79),e.jsxs(ge,{value:"basic",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Profile Photo"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(us,{className:"h-16 w-16",children:[$.photo_url?e.jsx(js,{src:$.photo_url,className:"object-cover"}):null,e.jsx(ps,{className:"bg-primary/10 text-primary",children:(na=(ta=$.display_name)==null?void 0:ta.slice(0,2))==null?void 0:na.toUpperCase()})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(N,{type:"file",accept:"image/*",onChange:async h=>{var te;const f=(te=h.target.files)==null?void 0:te[0];if(!(!f||!Q))try{const Ue=f.name.split(".").pop(),fe=`${Q.user_id}/${Date.now()}.${Ue}`,{error:ze}=await C.storage.from("team-photos").upload(fe,f,{upsert:!0});if(ze)throw ze;const{data:{publicUrl:Ze}}=C.storage.from("team-photos").getPublicUrl(fe);H(Xe=>({...Xe,photo_url:Ze}))}catch(Ue){w({title:"Upload failed",description:Ue.message,variant:"destructive"})}}}),e.jsx(N,{value:$.photo_url||"",onChange:h=>H(f=>({...f,photo_url:h.target.value})),placeholder:"Or paste image URL"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Display Name"}),e.jsx(N,{value:$.display_name||"",onChange:h=>H(f=>({...f,display_name:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Role / Title"}),e.jsx(N,{value:$.role_title||"",onChange:h=>H(f=>({...f,role_title:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Department"}),e.jsx(N,{value:$.department||"",onChange:h=>H(f=>({...f,department:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Position Title"}),e.jsx(N,{value:$.position_title||"",onChange:h=>H(f=>({...f,position_title:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Display Order"}),e.jsx(N,{type:"number",value:$.display_order||0,onChange:h=>H(f=>({...f,display_order:parseInt(h.target.value)||0}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Joining Date"}),e.jsx(N,{type:"date",value:$.joining_date||"",onChange:h=>H(f=>({...f,joining_date:h.target.value}))})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(u,{children:"Visible on Company Page"}),e.jsx(G,{checked:$.is_visible??!0,onCheckedChange:h=>H(f=>({...f,is_visible:h}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Bio"}),e.jsx(K,{value:$.bio||"",onChange:h=>H(f=>({...f,bio:h.target.value})),rows:3})]})]}),e.jsxs(ge,{value:"contact",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Phone"}),e.jsx(N,{value:$.phone||"",onChange:h=>H(f=>({...f,phone:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Personal Email"}),e.jsx(N,{value:$.personal_email||"",onChange:h=>H(f=>({...f,personal_email:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Company Email"}),e.jsx(N,{value:$.company_email||"",onChange:h=>H(f=>({...f,company_email:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"LinkedIn URL"}),e.jsx(N,{value:$.linkedin_url||"",onChange:h=>H(f=>({...f,linkedin_url:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Facebook URL"}),e.jsx(N,{value:$.facebook_url||"",onChange:h=>H(f=>({...f,facebook_url:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"YouTube URL"}),e.jsx(N,{value:$.youtube_url||"",onChange:h=>H(f=>({...f,youtube_url:h.target.value}))})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx(G,{checked:$.is_founder??!1,onCheckedChange:h=>H(f=>({...f,is_founder:h}))}),e.jsx(u,{children:"Featured as Founder/CEO on Company page"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Gender"}),e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:$.gender||"male",onChange:h=>H(f=>({...f,gender:h.target.value})),children:[e.jsx("option",{value:"male",children:"Male"}),e.jsx("option",{value:"female",children:"Female"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Emergency Contact Name"}),e.jsx(N,{value:$.emergency_contact_name||"",onChange:h=>H(f=>({...f,emergency_contact_name:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Emergency Contact Phone"}),e.jsx(N,{value:$.emergency_contact_phone||"",onChange:h=>H(f=>({...f,emergency_contact_phone:h.target.value}))})]})]}
79),e.jsxs(ge,{value:"personal",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Date of Birth"}),e.jsx(N,{type:"date",value:$.date_of_birth||"",onChange:h=>H(f=>({...f,date_of_birth:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"National ID"}),e.jsx(N,{value:$.national_id||"",onChange:h=>H(f=>({...f,national_id:h.target.value}))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Address"}),e.jsx(N,{value:$.address||"",onChange:h=>H(f=>({...f,address:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"City"}),e.jsx(N,{value:$.city||"",onChange:h=>H(f=>({...f,city:h.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Country"}),e.jsx(N,{value:$.country||"",onChange:h=>H(f=>({...f,country:h.target.value}))})]})]}),e.jsx(ge,{value:"contract",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Contract Start"}),e.jsx(N,{type:"date",value:$.contract_start||"",onChange:h=>H(f=>({...f,contract_start:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Contract End"}),e.jsx(N,{type:"date",value:$.contract_end||"",onChange:h=>H(f=>({...f,contract_end:h.target.value}))})]})]})})]})}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>ve(null),children:"Cancel"}),e.jsxs(v,{onClick:Ka,disabled:c.isPending,children:[c.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Save All Changes"]})]})]})}),e.jsx(Y,{open:!!he,onOpenChange:()=>Ce(null),children:e.jsxs(Z,{className:"max-w-lg max-h-[90vh]",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Process Payment: ",he==null?void 0:he.display_name]})}),e.jsx(ls,{className:"max-h-[60vh] pr-4",children:e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Period"}),e.jsxs(xe,{value:z.period_type,onValueChange:h=>Ie(f=>({...f,period_type:h})),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"monthly",children:"Monthly (Full Month)"}),e.jsx(E,{value:"daily",children:"Daily (Specific Days)"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"From Date"}),e.jsx(N,{type:"date",value:z.period_from,onChange:h=>Ie(f=>({...f,period_from:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"To Date"}),e.jsx(N,{type:"date",value:z.period_to,onChange:h=>Ie(f=>({...f,period_to:h.target.value}))})]})]}),z.period_from&&z.period_to&&e.jsx("p",{className:"text-xs text-muted-foreground",children:z.period_type==="daily"?`${Math.ceil((new Date(z.period_to).getTime()-new Date(z.period_from).getTime())/(1e3*60*60*24))+1} days`:`${R(new Date(z.period_from),"MMM d")} â ${R(new Date(z.period_to),"MMM d, yyyy")}`}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Basic Pay (PKR) *"}),e.jsx(N,{type:"number",value:z.basic_pay,onChange:h=>Ie(f=>({...f,basic_pay:h.target.value})),placeholder:"e.g. 50000"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Bonus (PKR)"}),e.jsx(N,{type:"number",value:z.bonus,onChange:h=>Ie(f=>({...f,bonus:h.target.value})),placeholder:"0"})]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/10 border border-primary/20",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Basic Pay"}),e.jsxs("span",{children:["PKR ",(parseFloat(z.basic_pay)||0).toLocaleString()]})]}),(parseFloat(z.bonus)||0)>0&&e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsx("span",{children:"+ Bonus"}),e.jsxs("span",{children:["PKR ",(parseFloat(z.bonus)||0).toLocaleStr
79ing()]})]}),e.jsx(Be,{className:"my-2"}),e.jsxs("div",{className:"flex justify-between font-bold text-lg",children:[e.jsx("span",{children:"Total"}),e.jsxs("span",{children:["PKR ",Rs.toLocaleString()]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Details / Notes"}),e.jsx(K,{value:z.description,onChange:h=>Ie(f=>({...f,description:h.target.value})),placeholder:"e.g. March 2026 salary + performance bonus",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Date *"}),e.jsx(N,{type:"date",value:z.payment_date,onChange:h=>Ie(f=>({...f,payment_date:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Method"}),e.jsxs(xe,{value:z.payment_method,onValueChange:h=>Ie(f=>({...f,payment_method:h})),children:[e.jsx(me,{children:e.jsx(ue,{placeholder:"Select..."})}),e.jsxs(je,{children:[e.jsx(E,{value:"bank_transfer",children:"Bank Transfer"}),e.jsx(E,{value:"cash",children:"Cash"}),e.jsx(E,{value:"easypaisa",children:"Easypaisa"}),e.jsx(E,{value:"jazzcash",children:"JazzCash"}),e.jsx(E,{value:"cheque",children:"Cheque"})]})]})]})]})]})}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>Ce(null),children:"Cancel"}),e.jsxs(v,{onClick:Va,disabled:!z.basic_pay||x.isPending,children:[x.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Record Payment â PKR ",Rs.toLocaleString()]})]})]})}),e.jsx(Y,{open:!!is,onOpenChange:()=>fs(null),children:e.jsxs(Z,{className:"max-w-lg max-h-[90vh]",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Edit Payment: ",(ra=is==null?void 0:is.member)==null?void 0:ra.display_name]})}),e.jsx(ls,{className:"max-h-[60vh] pr-4",children:e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Period"}),e.jsxs(xe,{value:ae.period_type,onValueChange:h=>$e(f=>({...f,period_type:h})),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"monthly",children:"Monthly (Full Month)"}),e.jsx(E,{value:"daily",children:"Daily (Specific Days)"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"From Date"}),e.jsx(N,{type:"date",value:ae.period_from,onChange:h=>$e(f=>({...f,period_from:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"To Date"}),e.jsx(N,{type:"date",value:ae.period_to,onChange:h=>$e(f=>({...f,period_to:h.target.value}))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Basic Pay (PKR) *"}),e.jsx(N,{type:"number",value:ae.basic_pay,onChange:h=>$e(f=>({...f,basic_pay:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Bonus (PKR)"}),e.jsx(N,{type:"number",value:ae.bonus,onChange:h=>$e(f=>({...f,bonus:h.target.value}))})]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/10 border border-primary/20",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Basic Pay"}),e.jsxs("span",{children:["PKR ",(parseFloat(ae.basic_pay)||0).toLocaleString()]})]}),(parseFloat(ae.bonus)||0)>0&&e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsx("span",{children:"+ Bonus"}),e.jsxs("span",{children:["PKR ",(parseFloat(ae.bonus)||0).toLocaleString()]})]}),e.jsx(Be,{className:"my-2"}),e.jsxs("div",{className:"flex justify-between font-bold text-lg",children:[e.jsx("span",{children:"Total"}),e.jsxs("span",{children:["PKR ",Es.toLocaleString()]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Details / Notes"}),e.jsx(K,{value:ae.description,onChange:h=>$e(f=>({...f,description:h.target.value})),rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Date *"}),e.jsx(N,{type:"date",value:ae.payment_date,onChange:h=>$e(f=>({...f,payment_date:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Payment Method"}),e.jsxs(xe,{value:ae.payment_method,onValueChange:h=>$e(f=>({...f,payment_method:h})),children:[e.jsx(me,{children:e.jsx(ue,{placeholder:"Select..."})}),e.jsxs(je,{children:[e.jsx(E,{value:"bank_transfer",children:"Bank Transfer"}),e.jsx(E,{value:"cash",children:"Cash"}),e.jsx(E,{value:"easypaisa",children:"Easypaisa"}),e.jsx(E,{value:"jazzcash",children:"JazzCash"}),e.jsx(E,{value:"cheque",children:"Cheque"})]})]})]})]})]})}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>fs(null),children:"Cancel"}),e.jsxs(v,{onClick:Ha,disabled:!ae.basic_pay||j.isPending,children:[j.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}
79),"Update Payment â PKR ",Es.toLocaleString()]})]})]})}),e.jsx(Se,{open:!!qs,onOpenChange:()=>Ls(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Payment Record"}),e.jsx(Me,{children:"This will permanently delete this payment record. This action cannot be undone."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:()=>{qs&&(_.mutate(qs),Ls(null))},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete Payment"})]})]})}),e.jsx(Se,{open:!!L,onOpenChange:()=>q(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Remove Team Member"}),e.jsx(Me,{children:"This will remove this person from the team page. They can be re-added later."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:()=>{L&&(r.mutate(L),q(null))},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]})}),e.jsx(Se,{open:!!W,onOpenChange:()=>os(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(ua,{className:"h-5 w-5 text-orange-600"}),W!=null&&W.ban?"Block Account":"Unblock Account"]}),e.jsx(Me,{children:W!=null&&W.ban?`This will block "${(ia=W==null?void 0:W.member)==null?void 0:ia.display_name}" from logging in. They won't be able to access their account until unblocked.`:`This will unblock "${(la=W==null?void 0:W.member)==null?void 0:la.display_name}" and allow them to log in again.`})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsxs(qe,{onClick:()=>{W&&(k.mutate({userId:W.member.user_id,ban:W.ban}),os(null))},className:W!=null&&W.ban?"bg-orange-600 hover:bg-orange-700":"bg-green-600 hover:bg-green-700",children:[k.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),W!=null&&W.ban?"Block Account":"Unblock Account"]})]})]})}),vs&&e.jsx(Sr,{member:vs,onClose:()=>ys(null)}),e.jsx(Y,{open:!!re,onOpenChange:()=>We(null),children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsxs(ee,{children:[re!=null&&re.makeInactive?"Mark as Inactive":"Reactivate",": ",(ca=re==null?void 0:re.member)==null?void 0:ca.display_name]})}),re!=null&&re.makeInactive?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Last working day"}),e.jsx(N,{type:"date",value:Ye.since,onChange:h=>y(f=>({...f,since:h.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Reason *"}),e.jsx(K,{rows:3,value:Ye.reason,onChange:h=>y(f=>({...f,reason:h.target.value})),placeholder:"e.g. Contract expired, resigned, role endedâ¦"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"They will move to the Inactive tab and be hidden from the public company page. Their payment history is kept."})]}):e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"This will move them back to the Active tab. Turn âVisibleâ back on if they should appear on the company page."}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>We(null),children:"Cancel"}),e.jsxs(v,{disabled:(re==null?void 0:re.makeInactive)&&!Ye.reason.trim()||d.isPending,onClick:async()=>{re&&(await d.mutateAsync({id:re.member.id,status:re.makeInactive?"inactive":"active",reason:Ye.reason,since:Ye.since}),We(null))},children:[d.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),re!=null&&re.makeInactive?"Mark Inactive":"Reactivate"]})]})]})}),T&&e.jsx(kr,{member:T,onClose:()=>ke(null)})]})};function kr({member:s,onClose:l}){const{user:a}=rs(),{data:n}=Pa(s.id),{data:i}=Ot(s.id),o=Kt(),[t,m]=b.useState(""),[c,r]=b.useState(new Date().toISOString().split("T")[0]),[d,x]=b.useState(""),j=n!=null&&n.salary_amount?Number(n.salary_amount):null,_=(n==null?void 0:n.salary_currency)||"PKR";return e.jsx(Y,{open:!0,onOpenChange:l,children:e.jsxs(Z,{className:"max-w-lg max-h-[90vh]",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Basic Pay: ",s.display_name]})}),e.jsx(ls,{className:"max-h-[65vh] pr-4",children:e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50 flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Current basic pay"}),e.jsx("span",{className:"font-semibold",children:j!==null?`${_}
79 ${j.toLocaleString()}`:"Not set"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{children:["New Basic Pay (",_,") *"]}),e.jsx(N,{type:"number",value:t,onChange:k=>m(k.target.value),placeholder:"e.g. 75000"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Effective From *"}),e.jsx(N,{type:"date",value:c,onChange:k=>r(k.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Reason / Note"}),e.jsx(K,{rows:2,value:d,onChange:k=>x(k.target.value),placeholder:"e.g. Annual increment, promotion to Senior Engineer"})]}),e.jsx(Be,{}),e.jsxs("h4",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2",children:[e.jsx(nn,{className:"h-3.5 w-3.5"})," Pay Change History"]}),i&&i.length>0?e.jsx("div",{className:"space-y-2",children:i.map(k=>e.jsxs("div",{className:"rounded-md border p-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between font-medium",children:[e.jsxs("span",{children:[k.previous_amount!=null?`${k.currency} ${Number(k.previous_amount).toLocaleString()} â `:"",k.currency," ",Number(k.new_amount).toLocaleString()]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:R(new Date(k.effective_date),"MMM d, yyyy")})]}),k.note&&e.jsx("p",{className:"text-muted-foreground text-xs mt-1",children:k.note})]},k.id))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No pay changes recorded yet."})]})}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:l,children:"Close"}),e.jsxs(v,{disabled:!t||o.isPending,onClick:async()=>{await o.mutateAsync({member_id:s.id,new_amount:parseFloat(t),previous_amount:j,currency:_,effective_date:c,note:d,changed_by:a==null?void 0:a.id}),m(""),x("")},children:[o.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Save New Basic Pay"]})]})]})})}function Sr({member:s,onClose:l}){var n;const{data:a}=Pa(s.id);return e.jsx(Y,{open:!0,onOpenChange:l,children:e.jsxs(Z,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(X,{children:e.jsx(ee,{children:"Team Member Details"})}),e.jsxs(ls,{className:"max-h-[70vh] pr-4",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6 p-4 rounded-lg bg-muted/50",children:[e.jsxs(us,{className:"h-20 w-20",children:[s.photo_url?e.jsx(js,{src:s.photo_url,alt:s.display_name,className:"object-cover"}):null,e.jsx(ps,{className:"bg-primary/10 text-primary text-lg",children:(n=s.display_name)==null?void 0:n.split(" ").map(i=>i[0]).join("").slice(0,2).toUpperCase()})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:s.display_name}),e.jsx("p",{className:"text-muted-foreground",children:s.role_title}),s.department&&e.jsx(D,{variant:"outline",className:"mt-1",children:s.department})]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[s.is_visible&&e.jsx(D,{className:"bg-green-500/10 text-green-600 border-green-500/20",children:"Visible"}),s.is_locked&&e.jsx(D,{className:"bg-red-500/10 text-red-600 border-red-500/20",children:"Locked"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1",children:[e.jsx(Ve,{title:"Role & Assignment"}),e.jsx(Ve,{title:""}),e.jsx(ie,{label:"Position Title",value:s.position_title}),e.jsx(ie,{label:"Display Order",value:`#${s.display_order||0}`}),e.jsx(ie,{label:"Joining Date",value:s.joining_date?R(new Date(s.joining_date),"MMM d, yyyy"):null}),e.jsx(ie,{label:"Contract Start",value:s.contract_start?R(new Date(s.contract_start),"MMM d, yyyy"):null}),e.jsx(ie,{label:"Contract End",value:s.contract_end?R(new Date(s.contract_end),"MMM d, yyyy"):null})]}),e.jsx(Be,{className:"my-4"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1",children:[e.jsx(Ve,{title:"Contact Information"}),e.jsx(Ve,{title:""}),e.jsx(ie,{label:"Personal Email",value:s.personal_email}),e.jsx(ie,{label:"Company Email",value:s.company_email}),e.jsx(ie,{label:"Phone",value:s.phone}),e.jsx(ie,{label:"LinkedIn",value:s.linkedin_url,isLink:!0})]}),e.jsx(Be,{className:"my-4"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1",children:[e.jsx(Ve,{title:"Personal Information"}),e.jsx(Ve,{title:""}),e.jsx(ie,{label:"Date of Birth",value:s.date_of_birth?R(new Date(s.date_of_birth),"MMM d, yyyy"):null}),e.jsx(ie,{label:"National ID",value:s.national_id}),e.jsx(ie,{label:"Address",value:s.address}),e.jsx(ie,{label:"City",value:s.city}),e.jsx(ie,{label:"Country",value:s.country})]}),e.jsx(Be,{className:"my-4"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1",children:[e.jsx(Ve,{title:"Emergency Contact"}),e.jsx(Ve,{title:""}),e.jsx(ie,{label:"Name",value:s.emergency_contact_name}),e.jsx(ie,{label:"Phone",value:s.emergency_contact_phone})]}),s.bio&&e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"my-4"}),e.jsxs("div",{children:[e.jsx(Ve,{title:"Bio"}),e.jsx("p",{className:"text-sm mt-1",children:s.bio})]})]}),e.jsx(Be,{className:"my-4"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-destructive uppercase tracking-wider mb-3",children:"ð° Financial Information (Sensitive)"}),a?e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1",children:[e.jsx(ie,{label:"Bank Name",value:a.bank_name}),e.jsx(ie,{label:"Account Number",value:a.bank_account_number}),e.jsx(ie,{label:"IBAN",value:a.bank_iban}),e.jsx(ie,{label:"Tax ID",value:a.tax_id}),e.jsx(ie,{label:"Salary",value:a.salary_amount?`${a.salary_currency||"PKR"}
79 ${Number(a.salary_amount).toLocaleString()}`:null})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No financial data entered yet."})]})]}),e.jsx(Ne,{children:e.jsx(v,{variant:"outline",onClick:l,children:"Close"})})]})})}function Ve({title:s}){return s?e.jsx("h4",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2 mt-2 col-span-2",children:s}):e.jsx("div",{})}function ie({label:s,value:l,isLink:a}){return e.jsxs("div",{className:"py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s}),e.jsx("div",{className:"text-sm font-medium",children:a&&l?e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline truncate block",children:l}):l||e.jsx("span",{className:"text-muted-foreground",children:"â"})})]})}function Pr(){const[s,l]=b.useState("pending"),{data:a,isLoading:n}=At(s),i=Mt(),[o,t]=b.useState({}),[m,c]=b.useState(null);return n?e.jsx(ne,{className:"h-64"}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(rn,{className:"h-5 w-5"}),"Role Requests"]})}),e.jsxs(F,{children:[e.jsx(Je,{value:s,onValueChange:l,className:"mb-4",children:e.jsxs(Ge,{children:[e.jsx(le,{value:"pending",children:"Pending"}),e.jsx(le,{value:"approved",children:"Approved"}),e.jsx(le,{value:"rejected",children:"Rejected"})]})}),a!=null&&a.length?e.jsx("div",{className:"space-y-4",children:a.map(r=>{var j,_,k,w,S,V,L;const d=xs[r.role],x=m===r.id;return e.jsxs("div",{className:"border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(us,{className:"h-10 w-10",children:[e.jsx(js,{src:((j=r.profile)==null?void 0:j.avatar_url)||void 0}),e.jsx(ps,{children:((k=(_=r.profile)==null?void 0:_.full_name)==null?void 0:k[0])||((S=(w=r.profile)==null?void 0:w.email)==null?void 0:S[0])||"?"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:((V=r.profile)==null?void 0:V.full_name)||"Unknown"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(L=r.profile)==null?void 0:L.email})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:(d==null?void 0:d.color)||"bg-muted",variant:"default",children:(d==null?void 0:d.label)||r.role}),e.jsx("span",{className:"text-xs text-muted-foreground",children:R(new Date(r.created_at),"MMM d, yyyy")})]})]}),r.reason&&e.jsx("p",{className:"text-sm bg-muted/50 rounded p-2",children:r.reason}),r.status==="pending"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(v,{size:"sm",onClick:()=>{i.mutate({requestId:r.id,status:"approved",adminNote:o[r.id],userId:r.user_id,role:r.role})},disabled:i.isPending,className:"gap-1",children:[e.jsx(ws,{className:"h-4 w-4"})," Approve"]}),e.jsxs(v,{size:"sm",variant:"destructive",onClick:()=>{i.mutate({requestId:r.id,status:"rejected",adminNote:o[r.id],userId:r.user_id,role:r.role})},disabled:i.isPending,className:"gap-1",children:[e.jsx(ss,{className:"h-4 w-4"})," Reject"]}),e.jsxs(v,{size:"sm",variant:"ghost",onClick:()=>c(x?null:r.id),className:"gap-1",children:[e.jsx(Ss,{className:"h-4 w-4"})," Note"]})]}),x&&r.status==="pending"&&e.jsx(K,{placeholder:"Optional admin note...",value:o[r.id]||"",onChange:q=>t(Q=>({...Q,[r.id]:q.target.value})),className:"text-sm"}),r.admin_note&&r.status!=="pending"&&e.jsxs("p",{className:"text-sm text-muted-foreground italic",children:["Admin note: ",r.admin_note]})]},r.id)})}):e.jsxs("p",{className:"text-center text-muted-foreground py-8",children:["No ",s," requests"]})]})]})}const Dr=({projectId:s})=>{const{data:l}=Da(s),{data:a}=Fa(),n=Qt(),i=Jt(),[o,t]=b.useState(""),[m,c]=b.useState("member"),r=a==null?void 0:a.filter(d=>!(l!=null&&l.find(x=>x.member_id===d.id)));return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h4",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Le,{className:"h-4 w-4"})," Members"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(xe,{value:o,onValueChange:t,children:[e.jsx(me,{className:"flex-1",children:e.jsx(ue,{placeholder:"Select member"})}),e.jsx(je,{children:r==null?void 0:r.map(d=>e.jsx(E,{value:d.id,children:d.display_name},d.id))})]}),e.jsxs(xe,{value:m,onValueChange:c,children:[e.jsx(me,{className:"w-32",children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"member",children:"Member"}),e.jsx(E,{value:"lead",children:"Lead"})]})]}),e.jsx(v,{size:"sm",onClick:()=>{o&&(n.mutate({project_id:s,member_id:o,role:m}),t(""))},children:e.jsx(we,{className:"h-4 w-4"})})]}),l==null?void 0:l.map(d=>{var x;return e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted/50 rounded",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:(x=d.member)==null?void 0:x.display_name}),e.jsx(D,{variant:"outline",children:d.role})]}),e.jsx(v,{size:"icon",variant:"ghost",onClick:()=>i.mutate({id:d.id,project_id:s}),children:e.jsx(ss,{className:"h-4 w-4"})})]},d.id)})]})},Ar=({projectId:s})=>{const{user:l}=rs(),{data:a}=Gt(s),{data:n}=Da(s),i=Wt(),o=Yt(),[t,m]=b.useState(!1),[c,r]=b.useState({title:"",description:"",assigned_to:"",priority:"medium",due_date:"",points:"10"});return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold flex items-center gap-2",children:[e.jsx(pn,{className:"h-4 w-4"})," Tasks"]}),e.jsxs(v,{size:"sm",variant:"outline",onClick:()=>m(!t),children:[e.jsx(we,{className:"h-4 w-4 mr-1"})," Add Task"]})]}),t&&e.jsx(P,{children:e.jsxs(F,{className:"p-4 space-y-3",children:[e.jsx(N,{placeholder:"Task title",value:c.title,onChange:d=>r(x=>({...x,title:d.target.value}))}),e.jsx(K,{placeholder:"Description",value:c.description,onChange:d=>r(x=>({...x,description:d.target.value}))}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(xe,{value:c.assigned_to,onValueChange:d=>r(x=>({...x,assigned_to:d})),children:[e.jsx(me,{children:e.jsx(ue,{placeholder:"Assign to"})}),e.jsx(je,{children:n==null?void 0:n.map(d=>{var x;return e.jsx(E,{value:d.member_id,children:(x=d.member)==null?void 0:x.display_name},d.member_id)})})]}),e.jsxs(xe,{value:c.priority,onValueChange:d=>r(x=>({...x,priority:d})),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"low",children:"Low"}),e.jsx(E,{value:"medium",children:"Medium"}),e.jsx(E,{value:"high",children:"High"}),e.jsx(E,{value:"urgent",children:"Urgent"})]})]}),e.jsx(N,{type:"date",value:c.due_date,onChange:d=>r(x=>({...x,due_date:d.target.value}))}),e.jsx(N,{type:"number",placeholder:"Points",value:c.points,onChange:d=>r(x=>({...x,points:d.target.value}))})]}),e.jsx(v,{onClick:()=>{c.title&&c.assigned_to&&l&&(i.mutate({project_id:s,assigned_to:c.assigned_to,assigned_by:l.id,title:c.title,de
79scription:c.description||void 0,priority:c.priority,due_date:c.due_date||void 0,points:parseInt(c.points)||10}),r({title:"",description:"",assigned_to:"",priority:"medium",due_date:"",points:"10"}),m(!1))},children:"Create Task"})]})}),a==null?void 0:a.map(d=>{var x;return e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:d.title}),e.jsx(D,{variant:"outline",children:d.priority}),e.jsx(D,{children:d.status})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Assigned to: ",(x=d.assignee)==null?void 0:x.display_name," · ",d.points," pts"]})]}),e.jsxs("div",{className:"flex gap-1",children:[d.status==="completed"&&d.verification_status!=="approved"&&e.jsxs(v,{size:"sm",variant:"outline",onClick:()=>o.mutate({id:d.id,verification_status:"approved",verified_by:l==null?void 0:l.id,verified_at:new Date().toISOString()}),children:[e.jsx(ka,{className:"h-4 w-4 mr-1"})," Verify"]}),d.verification_status==="approved"&&e.jsx(D,{className:"bg-[hsl(var(--brand-green))] text-white",children:"Verified"})]})]},d.id)})]})},Mr=()=>{const{user:s}=rs(),{data:l,isLoading:a}=$t(),n=Vt(),i=Bt(),o=Ht(),[t,m]=b.useState(!1),[c,r]=b.useState({name:"",description:""}),[d,x]=b.useState(null);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2",children:[e.jsx(ds,{className:"h-5 w-5"})," Projects"]}),e.jsxs(Y,{open:t,onOpenChange:m,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{className:"gap-2",children:[e.jsx(we,{className:"h-4 w-4"})," New Project"]})}),e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(ee,{children:"Create Project"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Name"}),e.jsx(N,{value:c.name,onChange:j=>r(_=>({..._,name:j.target.value}))})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description"}),e.jsx(K,{value:c.description,onChange:j=>r(_=>({..._,description:j.target.value}))})]}),e.jsx(v,{onClick:()=>{c.name&&s&&(n.mutate({...c,created_by:s.id}),r({name:"",description:""}),m(!1))},children:"Create"})]})]})]})]}),a?e.jsx("p",{children:"Loading..."}):l==null?void 0:l.map(j=>e.jsxs(P,{className:d===j.id?"ring-2 ring-primary":"",children:[e.jsxs(I,{className:"cursor-pointer",onClick:()=>x(d===j.id?null:j.id),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(U,{className:"text-lg",children:j.name}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{className:"text-sm",children:"Public"}),e.jsx(G,{checked:j.is_public,onCheckedChange:_=>i.mutate({id:j.id,is_public:_})})]}),e.jsx(D,{children:j.status}),e.jsx(v,{size:"icon",variant:"ghost",onClick:_=>{_.stopPropagation(),o.mutate(j.id)},children:e.jsx(pe,{className:"h-4 w-4 text-destructive"})})]})]}),j.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j.description})]}),d===j.id&&e.jsxs(F,{className:"space-y-6",children:[e.jsx(Dr,{projectId:j.id}),e.jsx(Ar,{projectId:j.id})]})]},j.id))]})},Tr=()=>{const{data:s,isLoading:l}=Zt();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2",children:[e.jsx(ts,{className:"h-5 w-5"})," Team Attendance"]}),e.jsx(P,{children:e.jsx(F,{className:"p-0",children:e.jsxs("div",{className:"divide-y",children:[l?e.jsx("p",{className:"p-4",children:"Loading..."}):s==null?void 0:s.map(a=>{var n;return e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:((n=a.member)==null?void 0:n.display_name)||"Unknown"}),e.jsx("span",{className:"text-sm text-muted-foreground ml-3",children:R(new Date(a.date),"EEE, MMM d, yyyy")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[a.check_in&&e.jsxs("span",{className:"text-[hsl(var(--brand-green))]",children:["In: ",R(new Date(a.check_in),"HH:mm")]}),a.check_out&&e.jsxs("span",{className:"text-destructive",children:["Out: ",R(new Date(a.check_out),"HH:mm")]}),e.jsx(D,{children:a.status})]})]},a.id)}),!l&&(!s||s.length===0)&&e.jsx("p",{className:"p-4 text-center text-muted-foreground",children:"No attendance records yet."})]})})})]})},Fr=()=>{const{user:s}=rs(),{data:l}=Xt(),a=en(),n=sn(),[i,o]=b.useState(!1),[t,m]=b.useState({title:"",message:"",priority:"normal"});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2",children:[e.jsx(wa,{className:"h-5 w-5"})," Announcements"]}),e.jsxs(v,{className:"gap-2",onClick:()=>o(!i),children:[e.jsx(we,{className:"h-4 w-4"})," New Announcement"]})]}),i&&e.jsx(P,{children:e.jsxs(F,{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Title"}),e.jsx(N,{value:t.title,onChange:c=>m(r=>({...r,title:c.target.value}))})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Message"}),e.jsx(K,{value:t.message,onChange:c=>m(r=>({...r,message:c.target.value})),rows:3})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Priority"}),e.jsxs(xe,{value:t.priority,onValueChange:c=>m(r=>({...r,priority:c})),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"normal",children:"Normal"}),e.jsx(E,{value:"important",children:"Important"}),e.jsx(E,{value:"urgent",children:"Urgent"})]})]})]}),e.jsx(v,{onClick:()=>{t.title&&t.message&&s&&(a.mutate({...t,created_by:s.id}),m({title:"",message:"",priority:"normal"}),o(!1))},children:"Send Announcement"})]})}),l==null?void 0:l.map(c=>e.jsx(P,{className:c.is_active?"":"opacity-50",children:e.jsxs(F,{className:"p-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold",children:c.title}),e.jsx(D,{variant:c.priority==="urgent"?"destructive":"outline",children:c.priority})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.message}),e.jsx("span",{className:"text-xs text-muted-foreground",children:R(new Date(c.created_at),"MMM d, yyyy HH:mm")}
79)]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{className:"text-sm",children:"Active"}),e.jsx(G,{checked:c.is_active,onCheckedChange:r=>n.mutate({id:c.id,is_active:r})})]})]})},c.id))]})};function qr(){return J({queryKey:["admin-contact-messages"],queryFn:async()=>{const{data:s,error:l}=await C.from("contact_messages").select("*").order("created_at",{ascending:!1});if(l)throw l;return s}})}function Lr(){const s=B();return O({mutationFn:async({id:l,is_read:a})=>{const{error:n}=await C.from("contact_messages").update({is_read:a}).eq("id",l);if(n)throw n},onSuccess:()=>s.invalidateQueries({queryKey:["admin-contact-messages"]})})}function Rr(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("contact_messages").delete().eq("id",l);if(a)throw a},onSuccess:()=>{A.success("Message deleted"),s.invalidateQueries({queryKey:["admin-contact-messages"]})}})}const Er=()=>{const{data:s,isLoading:l}=qr(),a=Lr(),n=Rr(),[i,o]=b.useState(null),[t,m]=b.useState(""),[c,r]=b.useState(""),[d,x]=b.useState(!1),j=w=>{o(w),m("Re: your message to SkilliHire"),r("")},_=async()=>{if(i){if(!c.trim()){A.error("Reply body required");return}x(!0);try{const{error:w}=await C.functions.invoke("send-email",{body:{template:"contact_reply",data:{email:i.email,first_name:i.first_name,reply_subject:t,reply_body:c}}});if(w)throw w;A.success(`Reply sent to ${i.email}`),a.mutate({id:i.id,is_read:!0}),o(null)}catch(w){A.error((w==null?void 0:w.message)||"Failed to send reply")}finally{x(!1)}}},k=(s==null?void 0:s.filter(w=>!w.is_read).length)||0;return l?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(se,{className:"h-6 w-6 animate-spin"})}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(es,{className:"h-5 w-5"}),"Contact Messages",k>0&&e.jsxs(D,{variant:"destructive",className:"ml-2",children:[k," new"]})]})}),e.jsx(F,{children:!s||s.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No messages yet."}):e.jsx("div",{className:"space-y-4",children:s.map(w=>e.jsx(P,{className:`p-4 ${w.is_read?"":"border-primary/50 bg-primary/5"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"font-semibold",children:[w.first_name," ",w.last_name]}),!w.is_read&&e.jsx(D,{variant:"secondary",className:"text-xs",children:"New"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-sm text-muted-foreground mb-2",children:[e.jsx("span",{children:w.email}),w.phone&&e.jsx("span",{children:w.phone}),w.company&&e.jsx("span",{children:w.company}),e.jsx("span",{children:R(new Date(w.created_at),"MMM d, yyyy 'at' h:mm a")})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:w.message})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>j(w),title:"Reply via email",children:e.jsx(ln,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>a.mutate({id:w.id,is_read:!w.is_read}),title:w.is_read?"Mark unread":"Mark read",children:w.is_read?e.jsx(es,{className:"h-4 w-4"}):e.jsx(vn,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>n.mutate(w.id),className:"text-destructive hover:text-destructive",children:e.jsx(pe,{className:"h-4 w-4"})})]})]})},w.id))})}),e.jsx(Y,{open:!!i,onOpenChange:w=>!w&&o(null),children:e.jsxs(Z,{className:"max-w-2xl",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Reply to ",i==null?void 0:i.first_name," ",i==null?void 0:i.last_name]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["To: ",e.jsx("span",{className:"font-medium text-foreground",children:i==null?void 0:i.email})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Subject"}),e.jsx(N,{value:t,onChange:w=>m(w.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Message"}),e.jsx(K,{rows:8,value:c,onChange:w=>r(w.target.value),placeholder:"Type your reply..."})]}),e.jsxs("div",{className:"rounded-md bg-muted/50 p-3 text-xs text-muted-foreground",children:[e.jsx("b",{children:"Original:"})," ",i==null?void 0:i.message]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>o(null),disabled:d,children:"Cancel"}),e.jsxs(v,{onClick:_,disabled:d,children:[d?e.jsx(se,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Js,{className:"h-4 w-4 mr-1"}),"Send Reply"]})]})]})})]})};function Ir(){return J({queryKey:["platform-settings"],queryFn:async()=>{const{data:s,error:l}=await C.from("platform_settings").select("*").order("key");if(l)throw l;return s}})}function Ur(){const s=B(),{user:l}=rs();return O({mutationFn:async({key:a,value:n})=>{if(!l)throw new Error("Not authenticated");const{data:i,error:o}=await C.from("platform_settings").update({value:n,updated_at:new Date().toISOString(),updated_by:l.id}).eq("key",a).select().single();if(o)throw o;return i},onSuccess:(a,n)=>{s.invalidateQueries({queryKey:["platform-settings"]}),s.invalidateQueries({queryKey:["platform-setting",n.key]}),ye({title:"Setting updated",description:`"${n.key}" has been updated.`})},onError:a=>{ye({title:"Failed to update setting",description:a.message,variant:"destructive"})}})}function zr(){const{data:s,isLoading:l}=Ir(),a=Ur(),[n,i]=b.useState({});if(l)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(se,{className:"h-8 w-8 animate-spin"})});const o=x=>{const j=n[x];j!==void 0&&a.mutate({key:x,value:j})},t=(x,j)=>n[x]!==void 0?n[x]:j,m=s==null?void 0:s.find(x=>x.key==="certificate_fee"),c=s==null?void 0:s.find(x=>x.key==="company_intro_video"),r=["nav_show_training","nav_show_courses","nav_show_freelancing"],d={nav_show_training:"Show Training in navigation",nav_show_courses:"Show Courses in mobile bottom nav",nav_show_freelancing:"Show Freelancing in navigation & footer"};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5 text-primary"}),"Navigation Visibility"]})}),e.jsxs(F,{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Show or hide the Training, Courses and Freelancing links in the public site navigation. Existing pages remain accessible by direct URL."}),e.jsx("div",{className:"space-y-4",children:r.map(x=>{const j=s==null?void 0:s.find(k=>k.key===x);if(!j)return null;const _=j.value==="true";return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-2 border-b last:border-0",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:d[x]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:j.description})]}),e.jsx(G,{checked:_,disabled:a.isPending,onCheckedChange:k=>a.mutate({key:x,value:k?"true":"false"})})]},x)})})]})]}),e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx($s,{className:"h-5 w-5 text-primary"}),"Certificate Fee"]})}),e.jsx(F,{children:m&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsxs("div",{className:"flex items-end gap-4",children:[e.jsxs("div",{className:"flex-1 max-w-xs",children:[e.jsx(u,{htmlFor:"cert-fee",children:"Fee Amount (USD)"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx($s,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{id:"cert-fee",type:"number",step:"0.01",min:"0",className:"pl-8",value:t("certificate_fee",m.value),onChange:x=>i(j=>({...j,certificate_fee:x.target.value}))})]})]}),e.jsxs(v,{onClick:()=>o("certificate_fee"),disabled:a.isPending||n.certificate_fee===void 0||n.certificate_fee===m.value,children:[a.isPending?e.jsx(se,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Is,{className:"h-4 w-4 mr-2"}),"Save"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Current fee: ",e.jsxs("strong",{children:["$",m.value]})," â This amount is charged to students when they request a certificate after completing a course."]}
79)]})})]}),e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Ws,{className:"h-5 w-5 text-primary"}),"Company Intro Video (Watch Demo)"]})}),e.jsx(F,{children:c?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:'Paste a YouTube video URL here. This video will play in a popup when visitors click "Watch Demo" on the homepage.'}),e.jsxs("div",{className:"flex items-end gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(u,{htmlFor:"intro-video",children:"YouTube Video URL"}),e.jsx(N,{id:"intro-video",type:"url",placeholder:"https://www.youtube.com/watch?v=...",className:"mt-1",value:t("company_intro_video",c.value),onChange:x=>i(j=>({...j,company_intro_video:x.target.value}))})]}),e.jsxs(v,{onClick:()=>o("company_intro_video"),disabled:a.isPending||n.company_intro_video===void 0||n.company_intro_video===c.value,children:[a.isPending?e.jsx(se,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Is,{className:"h-4 w-4 mr-2"}),"Save"]})]}),c.value&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Current URL: ",e.jsx("strong",{children:c.value})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Setting not found. It will be created automatically."})})]}),e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-5 w-5"}),"All Platform Settings"]})}),e.jsx(F,{children:e.jsxs("div",{className:"space-y-4",children:[s==null?void 0:s.filter(x=>x.key!=="certificate_fee"&&x.key!=="company_intro_video"&&!r.includes(x.key)).map(x=>e.jsxs("div",{className:"flex items-end gap-4 pb-4 border-b last:border-0",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(u,{children:x.key}),e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:x.description}),e.jsx(N,{value:t(x.key,x.value),onChange:j=>i(_=>({..._,[x.key]:j.target.value}))})]}),e.jsx(v,{size:"sm",onClick:()=>o(x.key),disabled:a.isPending||n[x.key]===void 0||n[x.key]===x.value,children:e.jsx(Is,{className:"h-4 w-4"})})]},x.id)),(s==null?void 0:s.filter(x=>x.key!=="certificate_fee"&&x.key!=="company_intro_video"&&!r.includes(x.key)).length)===0&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"No additional settings configured."})]})})]})]})}const Or={pending:"secondary",approved:"default",rejected:"destructive",completed:"outline"};function Kr(){const{data:s,isLoading:l}=cn("admin"),a=dn(),[n,i]=b.useState(null),[o,t]=b.useState(""),[m,c]=b.useState(""),[r,d]=b.useState(""),[x,j]=b.useState("50"),_=S=>{i(S)},k=()=>{n&&a.mutate({id:n,status:"approved",admin_note:o,meeting_url:m||void 0,scheduled_at:r||void 0,fee_amount:parseFloat(x)||50},{onSuccess:()=>{i(null),t(""),c(""),d(""),j("50")}})},w=S=>{a.mutate({id:S,status:"rejected",admin_note:"Request rejected by admin"})};return l?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(se,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs(e.Fragment,{children:[e.jsxs(P,{children:[e.jsxs(I,{children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Ws,{className:"h-5 w-5"})," Video Call Requests"]}),e.jsx(st,{children:"Review and manage student-instructor video call requests"})]}),e.jsx(F,{children:s!=null&&s.length?e.jsx("div",{className:"space-y-4",children:s.map(S=>{var V,L,q,Q,ve,he;return e.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[e.jsxs(us,{className:"h-10 w-10",children:[e.jsx(js,{src:((V=S.student)==null?void 0:V.avatar_url)||void 0}),e.jsx(ps,{children:((q=(L=S.student)==null?void 0:L.full_name)==null?void 0:q[0])||"S"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("p",{className:"font-medium",children:(Q=S.student)==null?void 0:Q.full_name}),e.jsx("span",{className:"text-muted-foreground",children:"â"}),e.jsx("p",{className:"font-medium",children:(ve=S.instructor)==null?void 0:ve.full_name}),e.jsx(D,{variant:Or[S.status]||"secondary",className:"capitalize",children:S.status})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Course: ",(he=S.course)==null?void 0:he.title]}),e.jsx("p",{className:"text-sm mt-1",children:S.reason}),S.admin_note&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1 italic",children:["Admin: ",S.admin_note]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:R(new Date(S.created_at),"PP")})]}),S.status==="pending"&&e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(v,{size:"sm",onClick:()=>_(S.id),disabled:a.isPending,children:[e.jsx(ws,{className:"h-4 w-4 mr-1"})," Approve"]}),e.jsxs(v,{size:"sm",variant:"destructive",onClick:()=>w(S.id),disabled:a.isPending,children:[e.jsx(ss,{className:"h-4 w-4 mr-1"})," Reject"]})]})]},S.id)})}):e.jsx("p",{className:"text-center py-8 text-muted-foreground",children:"No video call requests"})})]}),e.jsx(Y,{open:!!n,onOpenChange:S=>!S&&i(null),children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(ee,{children:"Approve Video Call Request"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Fee Amount ($)"}),e.jsx(N,{type:"number",value:x,onChange:S=>j(S.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Meeting URL"}),e.jsx(N,{placeholder:"https://meet.google.com/...",value:m,onChange:S=>c(S.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Schedule Date & Time"}),e.jsx(N,{type:"datetime-local",value:r,onChange:S=>d(S.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Admin Note"}),e.jsx(K,{placeholder:"Optional note...",value:o,onChange:S=>t(S.target.value)})]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>i(null),children:"Cancel"}),e.jsxs(v,{onClick:k,disabled:a.isPending,children:[a.isPending&&e.jsx(se,{className:"h-4 w-4 mr-2 animate-spin"}),"Confirm Approval"]})]})]})})]})}const $r=()=>{const{toast:s}=Qe(),l=B(),[a,n]=b.useState(null),{data:i,isLoading:o}=J({queryKey:["admin-service-pages"],queryFn:async()=>{const{data:r,error:d}=await C.from("service_pages").select("*").order("display_order");if(d)throw d;return r}}),{data:t}=J({queryKey:["admin-service-page-views"],queryFn:async()=>{const{data:r,error:d}=await C.from("service_page_views").select("service_page_id");if(d)throw d;const x={};return r==null||r.forEach(j=>{x[j.service_page_id]=(x[j.service_page_id]||0)+1}),x}}),m=O({mutationFn:async({id:r,is_published:d})=>{const{error:x}=await C.from("service_pages").update({is_published:d}).eq("id",r);
79if(x)throw x},onSuccess:()=>{l.invalidateQueries({queryKey:["admin-service-pages"]}),s({title:"Updated",description:"Service page status changed."})}}),c=O({mutationFn:async r=>{const{id:d,...x}=r,{error:j}=await C.from("service_pages").update({...x,updated_at:new Date().toISOString()}).eq("id",d);if(j)throw j},onSuccess:()=>{l.invalidateQueries({queryKey:["admin-service-pages"]}),n(null),s({title:"Saved",description:"Service page updated."})}});return o?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h2",{className:"text-xl font-bold",children:["Service Pages (",(i==null?void 0:i.length)||0,")"]})}),e.jsx("div",{className:"space-y-4",children:i==null?void 0:i.map(r=>e.jsx(P,{className:"rounded-xl",children:e.jsxs(F,{className:"p-4 flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold truncate",children:r.title}),e.jsx(D,{variant:r.is_published?"default":"secondary",className:"text-xs",children:r.is_published?"Published":"Draft"})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:r.seo_description}),e.jsxs("div",{className:"flex gap-4 mt-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["/services/",r.slug]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ts,{className:"h-3 w-3"}),(t==null?void 0:t[r.id])||0," views"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:r.is_published,onCheckedChange:d=>m.mutate({id:r.id,is_published:d})}),e.jsxs(Y,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"sm",onClick:()=>n({...r}),children:e.jsx(Fs,{className:"h-4 w-4"})})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Edit: ",r.title]})}),(a==null?void 0:a.id)===r.id&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Title"}),e.jsx(N,{value:a.title,onChange:d=>n({...a,title:d.target.value})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Tagline"}),e.jsx(N,{value:a.tagline||"",onChange:d=>n({...a,tagline:d.target.value})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Hero Description"}),e.jsx(K,{value:a.hero_description||"",onChange:d=>n({...a,hero_description:d.target.value}),rows:3})]}),e.jsxs("div",{children:[e.jsx(u,{children:"SEO Title"}),e.jsx(N,{value:a.seo_title||"",onChange:d=>n({...a,seo_title:d.target.value})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"SEO Description"}),e.jsx(K,{value:a.seo_description||"",onChange:d=>n({...a,seo_description:d.target.value}),rows:2})]}),e.jsxs("div",{children:[e.jsx(u,{children:"SEO Keywords (comma separated)"}),e.jsx(N,{value:(a.seo_keywords||[]).join(", "),onChange:d=>n({...a,seo_keywords:d.target.value.split(",").map(x=>x.trim()).filter(Boolean)})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"CTA Title"}),e.jsx(N,{value:a.cta_title||"",onChange:d=>n({...a,cta_title:d.target.value})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"CTA Description"}),e.jsx(K,{value:a.cta_description||"",onChange:d=>n({...a,cta_description:d.target.value}),rows:2})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Display Order"}),e.jsx(N,{type:"number",value:a.display_order,onChange:d=>n({...a,display_order:parseInt(d.target.value)})})]}),e.jsx(v,{onClick:()=>c.mutate(a),disabled:c.isPending,className:"w-full",children:c.isPending?"Saving...":"Save Changes"})]})]})]}),e.jsx("a",{href:`/services/${r.slug}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(He,{className:"h-4 w-4"})})})]})]})},r.id))})]})},Vr=()=>{const{toast:s}=Qe(),l=B(),{data:a,isLoading:n}=J({queryKey:["admin-freelancing-pages"],queryFn:async()=>{const{data:t,error:m}=await C.from("freelancing_category_pages").select("*").order("display_order");if(m)throw m;return t}}),{data:i}=J({queryKey:["admin-freelancing-page-views"],queryFn:async()=>{const{data:t,error:m}=await C.from("freelancing_page_views").select("page_id");if(m)throw m;const c={};return t==null||t.forEach(r=>{c[r.page_id]=(c[r.page_id]||0)+1}),c}}),o=O({mutationFn:async({id:t,is_published:m})=>{const{error:c}=await C.from("freelancing_category_pages").update({is_published:m}).eq("id",t);if(c)throw c},onSuccess:()=>
79{l.invalidateQueries({queryKey:["admin-freelancing-pages"]}),s({title:"Updated"})}});return n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-bold",children:["Freelancing Category Pages (",(a==null?void 0:a.length)||0,")"]}),a==null?void 0:a.map(t=>e.jsx(P,{className:"rounded-xl",children:e.jsxs(F,{className:"p-4 flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold truncate",children:t.title}),e.jsx(D,{variant:t.is_published?"default":"secondary",className:"text-xs",children:t.is_published?"Published":"Draft"})]}),e.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["/freelancing/category/",t.slug]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ts,{className:"h-3 w-3"}),(i==null?void 0:i[t.id])||0," views"]})]})]}),e.jsx(G,{checked:t.is_published,onCheckedChange:m=>o.mutate({id:t.id,is_published:m})}),e.jsx("a",{href:`/freelancing/category/${t.slug}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(He,{className:"h-4 w-4"})})})]})},t.id))]})},Br=()=>{const{toast:s}=Qe(),l=B(),{data:a,isLoading:n}=J({queryKey:["admin-community-pages"],queryFn:async()=>{const{data:t,error:m}=await C.from("community_feature_pages").select("*").order("display_order");if(m)throw m;return t}}),{data:i}=J({queryKey:["admin-community-page-views"],queryFn:async()=>{const{data:t,error:m}=await C.from("community_page_views").select("page_id");if(m)throw m;const c={};return t==null||t.forEach(r=>{c[r.page_id]=(c[r.page_id]||0)+1}),c}}),o=O({mutationFn:async({id:t,is_published:m})=>{const{error:c}=await C.from("community_feature_pages").update({is_published:m}).eq("id",t);if(c)throw c},onSuccess:()=>{l.invalidateQueries({queryKey:["admin-community-pages"]}),s({title:"Updated"})}});return n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-bold",children:["Community Feature Pages (",(a==null?void 0:a.length)||0,")"]}),a==null?void 0:a.map(t=>e.jsx(P,{className:"rounded-xl",children:e.jsxs(F,{className:"p-4 flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold truncate",children:t.title}),e.jsx(D,{variant:t.is_published?"default":"secondary",className:"text-xs",children:t.is_published?"Published":"Draft"})]}),e.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["/community/",t.slug]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ts,{className:"h-3 w-3"}),(i==null?void 0:i[t.id])||0," views"]})]})]}),e.jsx(G,{checked:t.is_published,onCheckedChange:m=>o.mutate({id:t.id,is_published:m})}),e.jsx("a",{href:`/community/${t.slug}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(He,{className:"h-4 w-4"})})})]})},t.id))]})},Hr=()=>{const{toast:s}=Qe(),l=B(),{data:a,isLoading:n}=J({queryKey:["admin-industry-pages"],queryFn:async()=>{const{data:t,error:m}=await C.from("industry_pages").select("*").order("display_order");if(m)throw m;return t}}),{data:i}=J({queryKey:["admin-industry-page-views"],queryFn:async()=>{const{data:t,error:m}=await C.from("industry_page_views").select("industry_page_id");if(m)throw m;const c={};return t==null||t.forEach(r=>{c[r.industry_page_id]=(c[r.industry_page_id]||0)+1}),c}}),o=O({mutationFn:async({id:t,is_published:m})=>{const{error:c}=await C.from("industry_pages").update({is_published:m}).eq("id",t);if(c)throw c},onSuccess:()=>{l.invalidateQueries({queryKey:["admin-industry-pages"]}),s({title:"Updated"})}});return n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-bold",children:["Industry Pages (",(a==null?void 0:a.length)||0,")"]}),a==null?void 0:a.map(t=>e.jsx(P,{className:"rounded-xl",children:e.jsxs(F,{className:"p-4 flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold truncate",children:t.title}),e.jsx(D,{variant:t.is_published?"default":"secondary",className:"text-xs",children:t.is_published?"Published":"Draft"})]}),e.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["/industries/",t.slug]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ts,{className:"h-3 w-3"}),(i==null?void 0:i[t.id])||0," views"]})]})]}),e.jsx(G,{checked:t.is_published,onCheckedChange:m=>o.mutate({id:t.id,is_published:m})}),e.jsx("a",{href:`/industries/${t.slug}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(He,{className:"h-4 w-4"})})})]})},t.id))]})};function Qr(s,l){return J({queryKey:["admin-enrollments",s,l],queryFn:async()=>{const{data:a,error:n}=await C.from("enrollments").select(` 80 *, 81 user:profiles!enrollments_user_id_fkey(full_name, email), 82 course:courses!enrollments_course_id_fkey(title) 83 `).order("enrolled_at",{ascending:!1}).limit(200);if(n)throw n;let i=a;if(s.trim()){const o=s.toLowerCase();i=i.filter(t=>{var m,c,r,d,x,j;return((c=(m=t.user)==null?void 0:m.full_name)==null?void 0:c.toLowerCase().includes(o))||((d=(r=t.user)==null?void 0:r.email)==null?void 0:d.toLowerCase().includes(o))||((j=(x=t.course)==null?void 0:x.title)==null?void 0:j.toLowerCase().includes(o))})}return l!=="all"&&(i=i.filter(o=>o.payment_status===l)),i}})}function Jr(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("enrollments").delete().eq("id",l);if(a)throw a},onSuccess:()=>{A.success("Enrollment deleted"),s.invalidateQueries({queryKey:["admin-enrollments"]})},onError:l=>A.error(l.message)})}function Gr(){const[s,l]=b.useState(""),[a,n]=b.useState("all"),[i,o]=b.useState(null),{data:t,isLoading:m}=Qr(s,a),c=Jr();return m?e.jsx(ne,{className:"h-64"}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5"}),"Enrollments Management (",(t==null?void 0:t.length)||0,")"]})}),e.jsxs(F,{children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search by student or course...",value:s,onChange:r=>l(r.target.value),className:"pl-10"})]}),e.jsxs(xe,{value:a,onValueChange:n,children:[e.jsx(me,{className:"w-[180px]",children:e.jsx(ue,{})}),e.jsxs(je,{children:[e.jsx(E,{value:"all",children:"All Statuses"}),e.jsx(E,{value:"completed",children:"Completed"}),e.jsx(E,{value:"pending",children:"Pending"}),e.jsx(E,{value:"free",children:"Free"})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Student"}),e.jsx(g,{children:"Course"}),e.jsx(g,{children:"Progress"}),e.jsx(g,{children:"Payment"}),e.jsx(g,{children:"Enrolled"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:t!=null&&t.length?t.map(r=>{var d,x,j;return e.jsxs(M,{children:[e.jsx(p,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:((d=r.user)==null?void 0:d.full_name)||"Unknown"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(x=r.user)==null?void 0:x.email})]})}),e.jsx(p,{className:"text-sm max-w-[200px] truncate",children:(j=r.course)==null?void 0:j.title}),e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-16 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full",style:{width:`${r.progress_percentage||0}%`}})}),e.jsxs("span",{className:"text-xs",children:[r.progress_percentage||0,"%"]})]})}),e.jsxs(p,{children:[e.jsx(D,{variant:r.payment_status==="completed"?"default":"secondary",className:"text-xs",children:r.payment_status||"free"}),r.payment_amount?e.jsxs("span",{className:"text-xs text-muted-foreground ml-1",children:["$",r.payment_amount]}):null]}),e.jsx(p,{className:"text-xs text-muted-foreground",children:R(new Date(r.enrolled_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsx(v,{variant:"ghost",size:"icon",className:"text-destructive",onClick:()=>o(r.id),children:e.jsx(pe,{className:"h-4 w-4"})})})]},r.id)}):e.jsx(M,{children:e.jsx(p,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No enrollments found"})})})]})}),e.jsx(Se,{open:!!i,onOpenChange:()=>o(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Enrollment?"}),e.jsx(Me,{children:"This will permanently remove this enrollment record. The student will lose access to the course."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:()=>{i&&c.mutate(i),o(null)},className:"bg-destructive text-destructive-foreground",children:"Delete"})]})]})})]})]})}function Wr(){return J({queryKey:["admin-certificates"],queryFn:async()=>{const{data:s,error:l}=await C.from("certificates").select(` 84 *, 85 user:profiles!certificates_user_id_fkey(full_name, email), 86 course:courses!certificates_course_id_fkey(title) 87 `).order("issued_at",{ascending:!1}).limit(200);if(l)throw l;return s}})}function Yr(){return J({queryKey:["admin-certificate-payments"],queryFn:async()=>{const{data:s,error:l}=await C.from("certificate_payments").select(` 88 *, 89 user:profiles!certificate_payments_user_id_fkey(full_name, email), 90 course:courses!certificate_payments_course_id_fkey(title) 91 `).order("created_at",{ascending:!1}).limit(200);if(l)throw l;return s}})}function Zr(){const[s,l]=b.useState(""),{data:a,isLoading:n}=Wr(),{data:i,isLoading:o}=Yr(),t=a==null?void 0:a.filter(r=>{var x,j,_,k,w,S,V;if(!s.trim())return!0;const d=s.toLowerCase();return((j=(x=r.user)==null?void 0:x.full_name)==null?void 0:j.toLowerCase().includes(d))||((k=(_=r.user)==null?void 0:_.email)==null?void 0:k.toLowerCase().includes(d))||((w=r.certificate_number)==null?void 0:w.toLowerCase().includes(d))||((V=(S=r.course)==null?void 0:S.title)==null?void 0:V.toLowerCase().includes(d))}),m=i==null?void 0:i.filter(r=>{var x,j,_,k,w,S;if(!s.trim())return!0;const d=s.toLowerCase();return((j=(x=r.user)==null?void 0:x.full_name)==null?void 0:j.toLowerCase().includes(d))||((k=(_=r.user)==null?void 0:_.email)==null?void 0:k.toLowerCase().includes(d))||((S=(w=r.course)==null?void 0:w.title)==null?void 0:S.toLowerCase().includes(d))});if(n||o)return e.jsx(ne,{className:"h-64"});const c=(i==null?void 0:i.filter(r=>r.status==="completed").reduce((r,d)=>r+(d.amount||0),0))||0;return e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Cs,{className:"h-5 w-5"}),"Certificates & Payments"]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs(D,{variant:"outline",className:"gap-1",children:[e.jsx(Cs,{className:"h-3 w-3"})," ",(a==null?void 0:a.length)||0," Certificates"]}),e.jsxs(D,{variant:"outline",className:"gap-1",children:[e.jsx(Qs,{className:"h-3 w-3"})," $",c.toFixed(2)," Revenue"]})]})]})}),e.jsxs(F,{children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search by student, course, or certificate number...",value:s,onChange:r=>l(r.target.value),className:"pl-10"})]}),e.jsxs(Je,{defaultValue:"certificates",children:[e.jsxs(Ge,{children:[e.jsxs(le,{value:"certificates",children:["Certificates (",(t==null?void 0:t.length)||0,")"]}),e.jsxs(le,{value:"payments",children:["Payments (",(m==null?void 0:m.length)||0,")"]})]}),e.jsx(ge,{value:"certificates",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Student"}),e.jsx(g,{children:"Course"}),e.jsx(g,{children:"Certificate #"}),e.jsx(g,{children:"Payment"}),e.jsx(g,{children:"Issued"})]})}),e.jsx(oe,{children:t!=null&&t.length?t.map(r=>{var d,x,j;return e.jsxs(M,{children:[e.jsxs(p,{children:[e.jsx("p",{className:"font-medium text-sm",children:((d=r.user)==null?void 0:d.full_name)||"Unknown"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(x=r.user)==null?void 0:x.email})]}),e.jsx(p,{className:"text-sm max-w-[200px] truncate",children:(j=r.course)==null?void 0:j.title}),e.jsx(p,{className:"text-sm font-mono",children:r.certificate_number}),e.jsx(p,{children:e.jsx(D,{variant:r.payment_status==="paid"?"default":"secondary",className:"text-xs",children:r.payment_status||"pending"})}),e.jsx(p,{className:"text-xs text-muted-foreground",children:R(new Date(r.issued_at),"MMM d, yyyy")})]},r.id)}):e.jsx(M,{children:e.jsx(p,{colSpan:5,className:"text-center text-muted-foreground py-8",children:"No certificates found"})})})]})})}),e.jsx(ge,{value:"payments",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Student"}),e.jsx(g,{children:"Course"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Method"}),e.jsx(g,{children:"Date"})]})}),e.jsx(oe,{children:m!=null&&m.length?m.map(r=>{var d,x,j;return e.jsxs(M,{children:[e.jsxs(p,{children:[e.jsx("p",{className:"font-medium text-sm",children:((d=r.user)==null?void 0:d.full_name)||"Unknown"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(x=r.user)==null?void 0:x.email})]}),e.jsx(p,{className:"text-sm max-w-[200px] truncate",children:(j=r.course)==null?void 0:j.title}),e.jsxs(p,{className:"font-semibold text-sm",children:["$",r.amount]}),e.jsx(p,{children:e.jsx(D,{variant:r.status==="completed"?"default":"secondary",className:"text-xs",children:r.status})}),e.jsx(p,{className:"text-sm",children:r.payment_method||"â"}),e.jsx(p,{className:"text-xs text-muted-foreground",children:R(new Date(r.created_at),"MMM d, yyyy")})]},r.id)}):e.jsx(M,{children:e.jsx(p,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No payments found"})})})]})})})]})]})]})}function Xr(){return J({queryKey:["admin-service-inquiries"],queryFn:async()=>{const{data:s,error:l}=await C.from("service_inquiries").select("*").order("created_at",{ascending:!1}).limit(200);if(l)throw l;return s}})}function ei(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("service_inquiries").update({is_read:!0}).eq("id",l);if(a)throw a},onSuccess:()=>s.invalidateQueries({queryKey:["admin-service-inquiries"]})})}function si(){const[s,l]=b.useState(""),[a,n]=b.useState(null),{data:i,isLoading:o}=Xr(),t=ei(),m=i==null?void 0:i.filter(r=>{var x,j,_,k;if(!s.trim())return!0;const d=s.toLowerCase();return((x=r.name)==null?void 0:x.toLowerCase().includes(d))||((j=r.email)==null?void 0:j.toLowerCase().includes(d))||((_=r.company)==null?void 0:_.toLowerCase().includes(d))||((k=r.message)==null?void 0:k.toLowerCase().includes(d))}),c=(i==null?void 0:i.filter(r=>!r.is_read).length)||0;return o?e.jsx(ne,{className:"h-64"}):e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Ss,{className:"h-5 w-5"}),"Service Inquiries (",(i==null?void 0:i.length)||0,")"]}),c>0&&e.jsxs(D,{variant:"destructive",children:[c," Unread"]})]})}),e.jsxs(F,{children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search inquiries...",value:s,onChange:r=>l(r.target.value),className:"pl-10"})]}),e.jsx("div",{className:"overflow-x-auto",childr
91en:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Company"}),e.jsx(g,{children:"Budget"}),e.jsx(g,{children:"Timeline"}),e.jsx(g,{children:"Date"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:m!=null&&m.length?m.map(r=>e.jsxs(M,{className:r.is_read?"":"bg-primary/5",children:[e.jsx(p,{className:"font-medium text-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[!r.is_read&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"}),r.name]})}),e.jsx(p,{className:"text-sm",children:r.email}),e.jsx(p,{className:"text-sm",children:r.company||"â"}),e.jsx(p,{className:"text-sm",children:r.budget_range||"â"}),e.jsx(p,{className:"text-sm",children:r.timeline||"â"}),e.jsx(p,{className:"text-xs text-muted-foreground",children:R(new Date(r.created_at),"MMM d, yyyy")}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>{n(r),r.is_read||t.mutate(r.id)},children:e.jsx(Ke,{className:"h-4 w-4"})}),!r.is_read&&e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>t.mutate(r.id),children:e.jsx(ka,{className:"h-4 w-4"})})]})})]},r.id)):e.jsx(M,{children:e.jsx(p,{colSpan:7,className:"text-center text-muted-foreground py-8",children:"No inquiries found"})})})]})}),e.jsx(Y,{open:!!a,onOpenChange:()=>n(null),children:e.jsxs(Z,{className:"max-w-lg",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Service Inquiry from ",a==null?void 0:a.name]})}),a&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Email"}),e.jsx("p",{className:"font-medium",children:a.email})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Phone"}),e.jsx("p",{className:"font-medium",children:a.phone||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Company"}),e.jsx("p",{className:"font-medium",children:a.company||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Budget Range"}),e.jsx("p",{className:"font-medium",children:a.budget_range||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Timeline"}),e.jsx("p",{className:"font-medium",children:a.timeline||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"Date"}),e.jsx("p",{className:"font-medium",children:R(new Date(a.created_at),"MMM d, yyyy HH:mm")})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground text-xs mb-1",children:"Message"}),e.jsx("p",{className:"bg-muted/50 p-3 rounded-lg whitespace-pre-wrap",children:a.message})]})]})]})})]})]})}function ai(){return J({queryKey:["admin-community-events"],queryFn:async()=>{const{data:s,error:l}=await C.from("community_events").select("*").order("event_date",{ascending:!1}).limit(200);if(l)throw l;const{data:a}=await C.from("community_event_registrations").select("event_id"),n={};return(a||[]).forEach(i=>{n[i.event_id]=(n[i.event_id]||0)+1}),(s||[]).map(i=>({...i,registration_count:n[i.id]||0}))}})}function ti(){const s=B();return O({mutationFn:async({id:l,is_active:a})=>{const{error:n}=await C.from("community_events").update({is_active:a}).eq("id",l);if(n)throw n},onSuccess:()=>s.invalidateQueries({queryKey:["admin-community-events"]})})}function ni(){const s=B();return O({mutationFn:async l=>{const{error:a}=await C.from("community_events").delete().eq("id",l);if(a)throw a},onSuccess:()=>{A.success("Event deleted"),s.invalidateQueries({queryKey:["admin-community-events"]})},onError:l=>A.error(l.message)})}function ri(){const[s,l]=b.useState(""),[a,n]=b.useState(null),{data:i,isLoading:o}=ai(),t=ti(),m=ni(),c=i==null?void 0:i.filter(d=>{var j,_,k;if(!s.trim())return!0;const x=s.toLowerCase();return((j=d.title)==null?void 0:j.toLowerCase().includes(x))||((_=d.speaker_name)==null?void 0:_.toLowerCase().includes(x))||((k=d.event_type)==null?void 0:k.toLowerCase().includes(x))});if(o)return e.jsx(ne,{className:"h-64"});const r=(i==null?void 0:i.filter(d=>new Date(d.event_date)>new Date&&d.is_active).length)||0;return e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(ts,{className:"h-5 w-5"}),"Community Events (",(i==null?void 0:i.length)||0,")"]}),e.jsxs(D,{variant:"outline",children:[r," Upcoming"]})]})}),e.jsxs(F,{children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search events...",value:s,onChange:d=>l(d.target.value),className:"pl-10"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Event"}),e.jsx(g,{children:"Type"}),e.jsx(g,{children:"Speaker"}),e.jsx(g,{children:"Date"}),e.jsx(g,{children:"Registrations"}),e.jsx(g,{children:"Active"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(oe,{children:c!=null&&c.length?c.map(d=>{const x=new Date(d.event_date)<new Date;return e.jsxs(M,{className:x?"opacity-60":"",children:[e.jsx(p,{className:"font-medium text-sm max-w-[200px] truncate",children:d.title}),e.jsx(p,{children:e.jsx(D,{variant:"outline",className:"text-xs capitalize",children:d.event_type})}),e.jsx(p,{className:"text-sm",children:d.speaker_name||"â"}),e.jsxs(p,{className:"text-xs text-muted-foreground",children:[R(new Date(d.event_date),"MMM d, yyyy HH:mm"),x&&e.jsx(D,{variant:"secondary",className:"ml-1 text-[10px]",children:"Past"})]}),e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Le,{className:"h-3 w-3"}),d.registration_count,d.max_attendees&&e.jsxs("span",{className:"text-muted-foreground",children:["/ ",d.max_attendees]})]})}),e.jsx(p,{children:e.jsx(G,{checked:d.is_active,onCheckedChange:j=>t.mutate({id:d.id,is_active:j})})}),e.jsx(p,{className:"text-right",children:e.jsx(v,{variant:"ghost",size:"icon",className:"text-destructive",onClick:()=>n(d.id),children:e.jsx(pe,{className:"h-4 w-4"})})})]},d.id)}):e.jsx(M,{children:e.jsx(p,{colSpan:7,className:"text-center text-muted-foreground py-8",children:"No events found"})})})]})}),e.jsx(Se,{open:!!a,onOpenChange:()=>n(null),children:e.jsxs(Pe,{children:[e.jsxs(De,{children:[e.jsx(Ae,{children:"Delete Event?"}),e.jsx(Me,{children:"This will permanently delete this event and all registrations."})]}),e.jsxs(Te,{children:[e.jsx(Fe,{children:"Cancel"}),e.jsx(qe,{onClick:()=>{a&&m.mutate(a),n(null)},className:"bg-destructive text-destructive-foreground",children:"Delete"})]})]})})]})]})}const ii={slug:"",title:"",nav_label:"",nav_href:"",nav_visible:!1,nav_order:100,hero_title:"",hero_description:"",content:"",is_published:!1,seo_title:"",seo_description:""},li=()=>{const{data:s,isLoading:l}=at(),a=tt(),n=nt(),i=rt(),[o,t]=b.useState(null),[m,c]=b.useState(null),r=j=>{a.mutate({id:j.id,nav_visible:!j.nav_visible})},d=()=>
91{if(!o)return;const{id:j,created_at:_,updated_at:k,...w}=o;a.mutate({id:j,...w},{onSuccess:()=>t(null)})},x=()=>{m&&n.mutate(m,{onSuccess:()=>c(null)})};return l?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(j=>e.jsx(ne,{className:"h-24"},j))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(Aa,{className:"h-5 w-5"}),"Navbar & Page Manager"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Toggle navbar links on/off and manage page content"})]}),e.jsxs(Y,{open:!!m,onOpenChange:j=>!j&&c(null),children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{onClick:()=>c({...ii}),size:"sm",children:[e.jsx(we,{className:"h-4 w-4 mr-2"}),"Add Page"]})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsx(ee,{children:"Create New Page"})}),m&&e.jsx(Na,{page:m,onChange:c,onSave:x,saving:n.isPending})]})]})]}),e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{className:"text-base",children:"Quick Navbar Visibility"})}),e.jsx(F,{children:e.jsx("div",{className:"space-y-3",children:s==null?void 0:s.map(j=>e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-border last:border-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{checked:j.nav_visible,onCheckedChange:()=>r(j)}),e.jsx("span",{className:"font-medium",children:j.nav_label}),e.jsx(D,{variant:j.nav_visible?"default":"secondary",className:"text-xs",children:j.nav_visible?"Visible":"Hidden"}),e.jsx(D,{variant:j.is_published?"default":"outline",className:"text-xs",children:j.is_published?"Published":"Draft"})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("code",{className:"text-xs text-muted-foreground bg-muted px-2 py-1 rounded",children:j.nav_href})})]},j.id))})})]}),e.jsx("div",{className:"grid gap-4",children:s==null?void 0:s.map(j=>e.jsx(P,{children:e.jsx(F,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ks,{className:"h-4 w-4 text-primary"}),e.jsx("h4",{className:"font-semibold",children:j.title}),e.jsx(D,{variant:j.is_published?"default":"outline",className:"text-xs",children:j.is_published?"Published":"Draft"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-1",children:["Slug: ",e.jsx("code",{className:"bg-muted px-1 rounded",children:j.slug})," | Nav: ",e.jsx("code",{className:"bg-muted px-1 rounded",children:j.nav_href})," | Order: ",j.nav_order]}),j.hero_description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2 mt-1",children:j.hero_description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>r(j),title:j.nav_visible?"Hide from navbar":"Show in navbar",children:j.nav_visible?e.jsx(Ke,{className:"h-4 w-4"}):e.jsx(un,{className:"h-4 w-4"})}),e.jsxs(Y,{open:(o==null?void 0:o.id)===j.id,onOpenChange:_=>!_&&t(null),children:[e.jsx(_e,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>t({...j}),children:e.jsx(Fs,{className:"h-4 w-4"})})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsxs(ee,{children:["Edit Page: ",j.title]})}),o&&e.jsx(Na,{page:o,onChange:_=>t(_),onSave:d,saving:a.isPending})]})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive",onClick:()=>{confirm(`Delete "${j.title}"?`)&&i.mutate(j.id)},children:e.jsx(pe,{className:"h-4 w-4"})})]})]})})},j.id))})]})},Na=({page:s,onChange:l,onSave:a,saving:n})=>{const i=(o,t)=>l({...s,[o]:t});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Title"}),e.jsx(N,{value:s.title,onChange:o=>i("title",o.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Slug"}),e.jsx(N,{value:s.slug,onChange:o=>i("slug",o.target.value),placeholder:"e.g. scholarships-visas"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Nav Label"}),e.jsx(N,{value:s.nav_label,onChange:o=>i("nav_label",o.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Nav Href"}
91),e.jsx(N,{value:s.nav_href,onChange:o=>i("nav_href",o.target.value),placeholder:"e.g. /scholarships-visas"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Nav Order"}),e.jsx(N,{type:"number",value:s.nav_order,onChange:o=>i("nav_order",parseInt(o.target.value))})]}),e.jsxs("div",{className:"flex items-center gap-6 pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:s.nav_visible,onCheckedChange:o=>i("nav_visible",o)}),e.jsx(u,{children:"Show in Navbar"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:s.is_published,onCheckedChange:o=>i("is_published",o)}),e.jsx(u,{children:"Published"})]})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Hero Title"}),e.jsx(N,{value:s.hero_title||"",onChange:o=>i("hero_title",o.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Hero Description"}),e.jsx(K,{value:s.hero_description||"",onChange:o=>i("hero_description",o.target.value),rows:2})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Page Content (HTML)"}),e.jsx(K,{value:s.content||"",onChange:o=>i("content",o.target.value),rows:8,placeholder:"Write HTML content for this page..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"SEO Title"}),e.jsx(N,{value:s.seo_title||"",onChange:o=>i("seo_title",o.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"SEO Description"}),e.jsx(N,{value:s.seo_description||"",onChange:o=>i("seo_description",o.target.value)})]})]}),e.jsx(v,{onClick:a,disabled:n,className:"w-full",children:n?"Saving...":"Save Page"})]})},ci=()=>{const[s,l]=b.useState(""),[a,n]=b.useState(!1),[i,o]=b.useState(""),[t,m]=b.useState(""),[c,r]=b.useState(""),[d,x]=b.useState(""),[j,_]=b.useState(!1),{data:k,isLoading:w}=J({queryKey:["newsletter-subscribers"],queryFn:async()=>{const{data:q,error:Q}=await C.from("newsletter_subscribers").select("*").order("subscribed_at",{ascending:!1});if(Q)throw Q;return q}}),S=k==null?void 0:k.filter(q=>{var Q,ve,he;return((Q=q.full_name)==null?void 0:Q.toLowerCase().includes(s.toLowerCase()))||((ve=q.email)==null?void 0:ve.toLowerCase().includes(s.toLowerCase()))||((he=q.country)==null?void 0:he.toLowerCase().includes(s.toLowerCase()))}),V=()=>{if(!(S!=null&&S.length))return;const q=["Name,Email,Country,Subscribed At,Active",...S.map(Ce=>`"${Ce.full_name}","${Ce.email}","${Ce.country}","${new Date(Ce.subscribed_at).toLocaleDateString()}","${Ce.is_active}"`)].join(` 92`),Q=new Blob([q],{type:"text/csv"}),ve=URL.createObjectURL(Q),he=document.createElement("a");he.href=ve,he.download="newsletter-subscribers.csv",he.click(),URL.revokeObjectURL(ve),A.success("CSV exported!")},L=async()=>{if(!i.trim()||!t.trim()){A.error("Subject and body are required");return}_(!0);try{const{data:q,error:Q}=await C.functions.invoke("send-newsletter",{body:{subject:i,bodyHtml:t,ctaLabel:c||void 0,ctaUrl:d||void 0}});if(Q)throw Q;A.success(`Newsletter sent to ${(q==null?void 0:q.sent)??0} subscribers${q!=null&&q.failed?` (${q.failed} failed)`:""}`),n(!1),o(""),m(""),r(""),x("")}catch(q){A.error((q==null?void 0:q.message)||"Failed to send newsletter")}finally{_(!1)}};return e.jsxs(P,{children:[e.jsx(I,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(es,{className:"h-5 w-5 text-primary"}),e.jsx(U,{children:"Newsletter Subscribers"}),e.jsx(D,{variant:"secondary",children:(S==null?void 0:S.length)??0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Search...",value:s,onChange:q=>l(q.target.value),className:"pl-9 w-56"})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:V,children:[e.jsx(Zs,{className:"h-4 w-4 mr-1"})," Export"]}),e.jsxs(Y,{open:a,onOpenChange:n,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{size:"sm",children:[e.jsx(Js,{className:"h-4 w-4 mr-1"})," Send Newsletter"]})}),e.jsxs(Z,{className:"max-w-2xl",children:[e.jsx(X,{children:e.jsx(ee,{children:"Send Newsletter"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Subject"}),e.jsx(N,{value:i,onChange:q=>o(q.target.value),placeholder:"This month at SkilliHire ð"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Body (HTML allowed)"}),e.jsx(K,{rows:10,value:t,onChange:q=>m(q.target.value),placeholder:"<p>Here's what's new...</p>"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Wrapped automatically in the SkilliHire branded template with logo & footer."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"CTA Label (optional)"}),e.jsx(N,{value:c,onChange:q=>r(q.target.value),placeholder:"Explore Courses"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"CTA URL (optional)"}),e.jsx(N,{value:d,onChange:q=>x(q.target.value),placeholder:"https://www.skillihire.com/courses"})]})]})]}),e.jsxs(Ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>n(!1),disabled:j,children:"Cancel"}),e.jsxs(v,{onClick:L,disabled:j,children:[j?e.jsx(se,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Js,{className:"h-4 w-4 mr-1"}),"Send to ",(k==null?void 0:k.filter(q=>q.is_active).length)??0," subscribers"]}
92)]})]})]})]})]})}),e.jsx(F,{children:w?e.jsx("p",{className:"text-muted-foreground py-8 text-center",children:"Loading..."}):S!=null&&S.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Email"}),e.jsx(g,{children:"Country"}),e.jsx(g,{children:"Subscribed"}),e.jsx(g,{children:"Status"})]})}),e.jsx(oe,{children:S.map(q=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:q.full_name}),e.jsx(p,{children:q.email}),e.jsx(p,{children:q.country}),e.jsx(p,{children:new Date(q.subscribed_at).toLocaleDateString()}),e.jsx(p,{children:e.jsx(D,{variant:q.is_active?"default":"secondary",children:q.is_active?"Active":"Inactive"})})]},q.id))})]})}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Le,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No subscribers yet"})]})})]})},di=()=>{const{data:s,isLoading:l}=on(),{data:a,isLoading:n}=hn(),{data:i}=xn(),o=B(),[t,m]=b.useState({tier_name:"",resume_count:"",price:"",display_order:""}),c=async()=>{if(!t.tier_name||!t.resume_count||!t.price){ye({title:"Fill all required fields",variant:"destructive"});return}const{error:x}=await C.from("resume_pricing").insert({tier_name:t.tier_name,resume_count:parseInt(t.resume_count),price:parseFloat(t.price),display_order:parseInt(t.display_order)||0});x?ye({title:"Error adding tier",variant:"destructive"}):(ye({title:"Pricing tier added!"}),m({tier_name:"",resume_count:"",price:"",display_order:""}),o.invalidateQueries({queryKey:["admin-resume-pricing"]}))},r=async(x,j)=>{await C.from("resume_pricing").update({is_active:!j}).eq("id",x),o.invalidateQueries({queryKey:["admin-resume-pricing"]}),o.invalidateQueries({queryKey:["resume-pricing"]})},d=(i==null?void 0:i.filter(x=>x.payment_status==="completed").reduce((x,j)=>x+Number(j.amount),0))||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-4",children:[e.jsx(P,{children:e.jsxs(F,{className:"p-4 text-center",children:[e.jsx(Oe,{className:"h-6 w-6 mx-auto text-primary mb-1"}),e.jsx("p",{className:"text-2xl font-bold",children:(s==null?void 0:s.length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Resumes"})]})}),e.jsx(P,{children:e.jsxs(F,{className:"p-4 text-center",children:[e.jsx(Le,{className:"h-6 w-6 mx-auto text-blue-600 mb-1"}),e.jsx("p",{className:"text-2xl font-bold",children:(i==null?void 0:i.length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Purchases"})]})}),e.jsx(P,{children:e.jsxs(F,{className:"p-4 text-center",children:[e.jsx($s,{className:"h-6 w-6 mx-auto text-green-600 mb-1"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",d.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Revenue"})]})}),e.jsx(P,{children:e.jsxs(F,{className:"p-4 text-center",children:[e.jsx(Gs,{className:"h-6 w-6 mx-auto text-orange-600 mb-1"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pricing Tiers"})]})})]}),e.jsxs(Je,{defaultValue:"pricing",children:[e.jsxs(Ge,{children:[e.jsx(le,{value:"pricing",children:"Pricing Tiers"}),e.jsx(le,{value:"resumes",children:"All Resumes"}),e.jsx(le,{value:"purchases",children:"Purchases"})]}),e.jsxs(ge,{value:"pricing",className:"space-y-4",children:[e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{className:"text-lg",children:"Add Pricing Tier"})}),e.jsx(F,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Name"}),e.jsx(N,{value:t.tier_name,onChange:x=>m({...t,tier_name:x.target.value}),placeholder:"Pro"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Resume Count"}),e.jsx(N,{type:"number",value:t.resume_count,onChange:x=>m({...t,resume_count:x.target.value}),placeholder:"10"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Price ($)"}),e.jsx(N,{type:"number",step:"0.01",value:t.price,onChange:x=>m({...t,price:x.target.value}),placeholder:"1.99"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Order"}),e.jsx(N,{type:"number",value:t.display_order,onChange:x=>m({...t,display_order:x.target.value}),placeholder:"0"})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(v,{onClick:c,className:"w-full",children:"Add Tier"})})]})})]}),e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{className:"text-lg",children:"Current Pricing"})}),e.jsx(F,{children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"Resumes"}),e.jsx(g,{children:"Price"}),e.jsx(g,{children:"Order"}),e.jsx(g,{children:"Active"})]})}),e.jsx(oe,{children:a==null?void 0:a.map(x=>e.jsxs(M,{children:[e.jsx(p,{className:"font-medium",children:x.tier_name}),e.jsx(p,{children:x.resume_count}),e.jsxs(p,{children:["$",Number(x.price).toFixed(2)]}),e.jsx(p,{children:x.display_order}),e.jsx(p,{children:e.jsx(G,{checked:x.is_active,onCheckedChange:()=>r(x.id,x.is_active)})})]},x.id))})]})})]})]}),e.jsx(ge,{value:"resumes",children:e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{className:"text-lg",children:"All Generated Resumes"})}),e.jsx(F,{children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"User"}
92),e.jsx(g,{children:"Name on Resume"}),e.jsx(g,{children:"Type"}),e.jsx(g,{children:"ATS Score"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Created"})]})}),e.jsxs(oe,{children:[s==null?void 0:s.map(x=>{var j,_,k;return e.jsxs(M,{children:[e.jsx(p,{className:"text-sm",children:((j=x.profiles)==null?void 0:j.full_name)||((_=x.profiles)==null?void 0:_.email)}),e.jsx(p,{children:((k=x.resume_data)==null?void 0:k.full_name)||"â"}),e.jsx(p,{children:e.jsx(D,{variant:"outline",className:"text-xs",children:x.resume_type})}),e.jsx(p,{children:x.ats_score?`${x.ats_score}/100`:"â"}),e.jsx(p,{children:e.jsx(D,{variant:"secondary",className:"text-xs",children:x.status})}),e.jsx(p,{className:"text-xs",children:new Date(x.created_at).toLocaleDateString()})]},x.id)}),!(s!=null&&s.length)&&e.jsx(M,{children:e.jsx(p,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No resumes yet"})})]})]})})]})}),e.jsx(ge,{value:"purchases",children:e.jsxs(P,{children:[e.jsx(I,{children:e.jsx(U,{className:"text-lg",children:"Purchase History"})}),e.jsx(F,{children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(M,{children:[e.jsx(g,{children:"User"}),e.jsx(g,{children:"Tier"}),e.jsx(g,{children:"Credits"}),e.jsx(g,{children:"Amount"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Date"})]})}),e.jsxs(oe,{children:[i==null?void 0:i.map(x=>{var j,_,k;return e.jsxs(M,{children:[e.jsx(p,{className:"text-sm",children:((j=x.profiles)==null?void 0:j.full_name)||((_=x.profiles)==null?void 0:_.email)}),e.jsx(p,{children:((k=x.resume_pricing)==null?void 0:k.tier_name)||"â"}),e.jsx(p,{children:x.resumes_purchased}),e.jsxs(p,{children:["$",Number(x.amount).toFixed(2)]}),e.jsx(p,{children:e.jsx(D,{variant:x.payment_status==="completed"?"default":"secondary",className:"text-xs",children:x.payment_status})}),e.jsx(p,{className:"text-xs",children:new Date(x.created_at).toLocaleDateString()})]},x.id)}),!(i!=null&&i.length)&&e.jsx(M,{children:e.jsx(p,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No purchases yet"})})]})]})})]})})]})]})};function oi(){const s=B(),[l,a]=b.useState(!1),[n,i]=b.useState(null),{data:o}=J({queryKey:["admin-scholarships"],queryFn:async()=>{const{data:c,error:r}=await C.from("scholarships").select("*").order("created_at",{ascending:!1});if(r)throw r;return c}}),t=O({mutationFn:async c=>{if(c.id){const{error:r}=await C.from("scholarships").update(c).eq("id",c.id);if(r)throw r}else{const{id:r,...d}=c,{error:x}=await C.from("scholarships").insert(d);if(x)throw x}},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-scholarships"]}),a(!1),i(null),ye({title:"Saved"})},onError:c=>ye({title:"Error",description:c.message,variant:"destructive"})}),m=O({mutationFn:async c=>{const{error:r}=await C.from("scholarships").delete().eq("id",c);if(r)throw r},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-scholarships"]}),ye({title:"Deleted"})}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["Scholarships (",(o==null?void 0:o.length)||0,")"]}),e.jsxs(Y,{open:l,onOpenChange:c=>{a(c),c||i(null)},children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{size:"sm",children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Add"]})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsxs(ee,{children:[n?"Edit":"Add"," Scholarship"]})}),e.jsx(hi,{initial:n,onSave:c=>t.mutate(c),saving:t.isPending})]})]})]}),e.jsx("div",{className:"space-y-2",children:o==null?void 0:o.map(c=>e.jsx(P,{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:c.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.provider," · ",c.country," · ",c.degree_level]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:c.is_published?"default":"secondary",children:c.is_published?"Published":"Draft"}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>{i(c),a(!0)},children:e.jsx(Xs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>m.mutate(c.id),children:e.jsx(pe,{className:"h-4 w-4 text-destructive"})})]})]})},c.id))})]})}function hi({initial:s,onSave:l,saving:a}){const[n,i]=b.useState({id:(s==null?void 0:s.id)||void 0,title:(s==null?void 0:s.title)||"",provider:(s==null?void 0:s.provider)||"",country:(s==null?void 0:s.country)||"",field_of_study:(s==null?void 0:s.field_of_study)||"",degree_level:(s==null?void 0:s.degree_level)||"any",funding_type:(s==null?void 0:s.funding_type)||"full",amount:(s==null?void 0:s.amount)||"",deadline:s!=null&&s.deadline?s.deadline.slice(0,10):"",description:(s==null?void 0:s.description)||"",eligibility:(s==null?void 0:s.eligibility)||"",application_url:(s==null?void 0:s.application_url)||"",is_featured:(s==null?void 0:s.is_featured)||!1,is_published:(s==null?void 0:s.is_published)??!0}),o=(t,m)=>i(c=>({...c,[t]:m}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Title *"}),e.jsx(N,{value:n.title,onChange:t=>o("title",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Provider *"}
92),e.jsx(N,{value:n.provider,onChange:t=>o("provider",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Country *"}),e.jsx(N,{value:n.country,onChange:t=>o("country",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Field of Study"}),e.jsx(N,{value:n.field_of_study,onChange:t=>o("field_of_study",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Degree Level"}),e.jsxs(xe,{value:n.degree_level,onValueChange:t=>o("degree_level",t),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsx(je,{children:["any","bachelors","masters","phd","postdoc"].map(t=>e.jsx(E,{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Funding Type"}),e.jsxs(xe,{value:n.funding_type,onValueChange:t=>o("funding_type",t),children:[e.jsx(me,{children:e.jsx(ue,{})}),e.jsx(je,{children:["full","partial","tuition","stipend"].map(t=>e.jsx(E,{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Amount"}),e.jsx(N,{value:n.amount,onChange:t=>o("amount",t.target.value),placeholder:"e.g. $30,000/year"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Deadline"}),e.jsx(N,{type:"date",value:n.deadline,onChange:t=>o("deadline",t.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description *"}),e.jsx(K,{value:n.description,onChange:t=>o("description",t.target.value),rows:3})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Eligibility"}),e.jsx(K,{value:n.eligibility,onChange:t=>o("eligibility",t.target.value),rows:2})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Application URL"}),e.jsx(N,{value:n.application_url,onChange:t=>o("application_url",t.target.value)})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:n.is_published,onCheckedChange:t=>o("is_published",t)}),e.jsx(u,{children:"Published"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:n.is_featured,onCheckedChange:t=>o("is_featured",t)}),e.jsx(u,{children:"Featured"})]})]}),e.jsx(v,{onClick:()=>l({...n,deadline:n.deadline?new Date(n.deadline).toISOString():null}),disabled:a||!n.title||!n.provider||!n.country||!n.description,children:a?"Saving...":"Save"})]})}function xi(){const s=B(),[l,a]=b.useState(!1),[n,i]=b.useState(null),{data:o}=J({queryKey:["admin-universities"],queryFn:async()=>{const{data:c,error:r}=await C.from("universities").select("*").order("created_at",{ascending:!1});if(r)throw r;return c}}),t=O({mutationFn:async c=>{if(c.id){const{error:r}=await C.from("universities").update(c).eq("id",c.id);if(r)throw r}else{const{id:r,...d}=c,{error:x}=await C.from("universities").insert(d);if(x)throw x}},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-universities"]}),a(!1),i(null),ye({title:"Saved"})},onError:c=>ye({title:"Error",description:c.message,variant:"destructive"})}),m=O({mutationFn:async c=>{const{error:r}=await C.from("universities").delete().eq("id",c);if(r)throw r},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-universities"]}),ye({title:"Deleted"})}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["Universities (",(o==null?void 0:o.length)||0,")"]}),e.jsxs(Y,{open:l,onOpenChange:c=>{a(c),c||i(null)},children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{size:"sm",children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Add"]})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsxs(ee,{children:[n?"Edit":"Add"," University"]})}),e.jsx(mi,{initial:n,onSave:c=>t.mutate(c),saving:t.isPending})]})]})]}),e.jsx("div",{className:"space-y-2",children:o==null?void 0:o.map(c=>e.jsx(P,{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:c.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.city?`${c.city}, `:"",c.country,c.ranking?` · QS #${c.ranking}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:c.is_published?"default":"secondary",children:c.is_published?"Published":"Draft"}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>{i(c),a(!0)},children:e.jsx(Xs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>m.mutate(c.id),children:e.jsx(pe,{className:"h-4 w-4 text-destructive"})})]})]})},c.id))})]})}function mi({initial:s,onSave:l,saving:a}){const[n,i]=b.useState({id:(s==null?void 0:s.id)||void 0,name:(s==null?void 0:s.name)||"",country:(s==null?void 0:s.country)||"",city:(s==null?void 0:s.city)||"",ranking:(s==null?void 0:s.ranking)||"",website_url:(s==null?void 0:s.website_url)||"",description:(s==null?void 0:s.description)||"",tuition_range:(s==null?void 0:s.tuition_range)||"",admission_requirements:(s==null?void 0:s.admission_requirements)||"",is_featured:(s==null?void 0:s.is_featured)||!1,is_published:(s==null?void 0:s.is_published)??!0}),o=(t,m)=>i(c=>({...c,[t]:m}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Name *"}),e.jsx(N,{value:n.name,onChange:t=>o("name",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Country *"}),e.jsx(N,{value:n.country,onChange:t=>o("country",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"City"}),e.jsx(N,{value:n.city,onChange:t=>o("city",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"QS Ranking"}),e.jsx(N,{type:"number",value:n.ranking,onChange:t=>o("ranking",t.target.value?parseInt(t.target.value):"")})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Website URL"}),e.jsx(N,{value:n.website_url,onChange:t=>o("website_url",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Tuition Range"}),e.jsx(N,{value:n.tuition_range,onChange:t=>o("tuition_range",t.target.value),placeholder:"e.g. $10,000-$25,000/year"})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description"}),e.jsx(K,{value:n.description,onChange:t=>o("description",t.target.value),rows:3})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Admission Requirements"}),e.jsx(K,{value:n.admission_requirements,onChange:t=>o("admission_requirements",t.target.value),rows:2})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:n.is_published,onCheckedChange:t=>o("is_published",t)}),e.jsx(u,{children:"Published"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:n.is_featured,onCheckedChange:t=>o("is_featured",t)}),e.jsx(u,{children:"Featured"})]})]}),e.jsx(v,{onClick:()=>l({...n,ranking:n.ranking||null}),disabled:a||!n.name||!n.country,children:a?"Saving...":"Save"})]})}function ui(){const s=B(),[l,a]=b.useState(!1),[n,i]=b.useState(null),{data:o}=J({queryKey:["admin-visa-guides"],queryFn:async()=>{const{data:c,error:r}=await C.from("visa_guides").select("*").order("created_at",{ascending:!1});if(r)throw r;return c}}),t=O({mutationFn:async c=>{if(c.id){const{error:r}=await C.from("visa_guides").update(c).eq("id",c.id);if(r)throw r}else{const{id:r,...d}=c,{error:x}=await C.from("visa_guides").insert(d);if(x)throw x}},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-visa-guides"]}),a(!1),i(null),ye({title:"Saved"})},onError:c=>ye({title:"Error",description:c.message,variant:"destructive"})}),m=O({mutationFn:async c=>{const{error:r}=await C.from("visa_guides").delete().eq("id",c);if(r)throw r},onSuccess:()=>{s.invalidateQueries({queryKey:["admin-visa-guides"]}),ye({title:"Deleted"})}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["Visa Guides (",(o==null?void 0:o.length)||0,")"]}),e.jsxs(Y,{open:l,onOpenChange:c=>{a(c),c||i(null)},children:[e.jsx(_e,{asChild:!0,children:e.jsxs(v,{size:"sm",children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Add"]})}),e.jsxs(Z,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(X,{children:e.jsxs(ee,{children:[n?"Edit":"Add"," Visa Guide"]})}),e.jsx(ji,{initial:n,onSave:c=>t.mutate(c),saving:t.isPending})]})]})]}),e.jsx("div",{className:"space-y-2",children:o==null?void 0:o.map(c=>e.jsx(P,{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:c.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.country," · ",c.visa_type]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:c.is_published?"default":"secondary",children:c.is_published?"Published":"Draft"}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>{i(c),a(!0)},children:e.jsx(Xs,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>m.mutate(c.id),children:e.jsx(pe,{className:"h-4 w-4 text-destructive"})})]})]})},c.id))})]})}function ji({initial:s,onSave:l,saving:a}){const[n,i]=b.useState({id:(s==null?void 0:s.id)||void 0,country:(s==null?void 0:s.country)||"",visa_type:(s==null?void 0:s.visa_type)||"",title:(s==null?void 0:s.title)||"",description:(s==null?void 0:s.description)||"",processing_time:(s==null?void 0:s.processing_time)||"",fees:(s==null?void 0:s.fees)||"",application_url:(s==null?void 0:s.application_url)||"",tips:(s==null?void 0:s.tips)||"",is_published:(s==null?void 0:s.is_published)??!0}),o=(t,m)=>i(c=>({...c,[t]:m}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Title *"}),e.jsx(N,{value:n.title,onChange:t=>o("title",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Country *"}),e.jsx(N,{value:n.country,onChange:t=>o("country",t.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Visa Type *"}
92),e.jsx(N,{value:n.visa_type,onChange:t=>o("visa_type",t.target.value),placeholder:"e.g. Student Visa (Subclass 500)"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Processing Time"}),e.jsx(N,{value:n.processing_time,onChange:t=>o("processing_time",t.target.value),placeholder:"e.g. 4-6 weeks"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Fees"}),e.jsx(N,{value:n.fees,onChange:t=>o("fees",t.target.value),placeholder:"e.g. AUD $710"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Application URL"}),e.jsx(N,{value:n.application_url,onChange:t=>o("application_url",t.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description"}),e.jsx(K,{value:n.description,onChange:t=>o("description",t.target.value),rows:3})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Tips"}),e.jsx(K,{value:n.tips,onChange:t=>o("tips",t.target.value),rows:2})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{checked:n.is_published,onCheckedChange:t=>o("is_published",t)}),e.jsx(u,{children:"Published"})]}),e.jsx(v,{onClick:()=>l(n),disabled:a||!n.title||!n.country||!n.visa_type,children:a?"Saving...":"Save"})]})}const pi=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h2",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(cs,{className:"h-6 w-6"})," Scholarships & Visas Management"]}),e.jsxs(Je,{defaultValue:"scholarships",children:[e.jsxs(Ge,{children:[e.jsxs(le,{value:"scholarships",className:"gap-1.5",children:[e.jsx(cs,{className:"h-4 w-4"}),"Scholarships"]}),e.jsxs(le,{value:"universities",className:"gap-1.5",children:[e.jsx(ks,{className:"h-4 w-4"}),"Universities"]}),e.jsxs(le,{value:"visa-guides",className:"gap-1.5",children:[e.jsx(Oe,{className:"h-4 w-4"}),"Visa Guides"]})]}),e.jsx(ge,{value:"scholarships",children:e.jsx(oi,{})}),e.jsx(ge,{value:"universities",children:e.jsx(xi,{})}),e.jsx(ge,{value:"visa-guides",children:e.jsx(ui,{})})]})]}),gi={users:rr,"role-requests":Pr,settings:zr,team:Cr,projects:Mr,attendance:Tr,announcements:Fr,courses:or,enrollments:Gr,certificates:Zr,"video-calls":Kr,applications:On,posts:Kn,"content-calendar":Wn,categories:Yn,jobs:er,freelancing:pr,"community-events":ri,messages:Er,"service-inquiries":si,newsletter:ci,"service-pages":$r,"industry-pages":Hr,"freelancing-pages":Vr,"community-pages":Br,"managed-pages":li,resume:di,scholarships:pi},ul=()=>{const{user:s}=rs(),l=it(),{data:a,isLoading:n}=pt(),[i,o]=b.useState("users");if(!s)return l("/login"),null;if(n)return e.jsx("div",{className:"min-h-screen py-12",children:e.jsxs("div",{className:"container mx-auto px-4 lg:px-8 max-w-6xl",children:[e.jsx(ne,{className:"h-10 w-64 mb-8"}),e.jsx(ne,{className:"h-96"})]})});if(!a)return e.jsx("div",{className:"min-h-screen py-12",children:e.jsx("div",{className:"container mx-auto px-4 lg:px-8 max-w-4xl text-center",children:e.jsxs(P,{className:"p-12",children:[e.jsx(Vs,{className:"h-16 w-16 mx-auto text-muted-foreground mb-4"}),e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Admin Access Required"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You don't have permission to access the admin dashboard."}),e.jsx(v,{asChild:!0,children:e.jsxs(ms,{to:"/",children:[e.jsx(lt,{className:"h-4 w-4 mr-2"}),"Go Home"]})})]})})});const t=gi[i];return e.jsx("div",{className:"min-h-screen pt-24 pb-12",children:e.jsxs("div",{className:"container mx-auto px-4 lg:px-8 max-w-[1400px]",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-primary to-primary/60 flex items-center justify-center",children:e.jsx(Vs,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Super Admin Dashboard"}),e.jsx("p",{className:"text-muted-foreground",children:"Complete platform oversight & management"})]})]}),e.jsx(zn,{}),e.jsxs("div",{className:"mt-6 flex flex-col lg:flex-row gap-6",children:[e.jsx(In,{activeTab:i,onTabChange:o}),e.jsx("main",{className:"flex-1 min-w-0",children:t&&e.jsx(t,{})})]})]})})};export{ul 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.