1import{u as Vs,a as kr,r as m,j as e,L as Ss,C as wa,g as fs,b as Sr,s as na,c as Ar,d as Xt,W as Pr,S as Ea,O as Tr,R as pe,e as yn,f as W,h as se,i as ae,k as je,l as Q,m as Ha,B as u,A as ta,n as He,o as ce,p as Wa,D as Fe,q as di,E as Fs,t as ze,v as Ee,w as De,x as ps,y as oa,z as zs,M as ms,U as Gs,I as E,F as Xa,G as Za,H as hs,J as x,K as Oe,N as Fa,P as us,Q as lt,T as v,V as jt,X as Ke,Y as et,Z as ct,_ as Es,$ as Ge,a0 as Re,a1 as Ce,a2 as Ts,a3 as st,a4 as mi,a5 as Ot,a6 as ui,a7 as Rt,a8 as It,a9 as Fr,aa as xi,ab as $t,ac as zr,ad as Er,ae as Dr,af as Lr,ag as Mr,ah as qr,ai as Or,aj as Rr,ak as Ir,al as ve,am as $r}from"./index-qrsRjyQ8.js";import{u as Br,S as Ur,a as Gr,b as Nn,D as Vr,c as Qr,d as bn,e as Kr,f as Hr,g as Wr,h as Yr,C as Jr,i as Xr,j as Zr,k as el,l as sl,m as al,n as tl,o as nl,p as il,F as da,q as Zt,B as pa,r as hi,U as rl,M as en,T as Da,s as gs,t as ga,K as pi,v as gi,w as ji,x as fi,y as Xe,z as ll,A as cl,E as ol,G as dl,H as ml,I as ul,L as ft,J as Ba,N as xl,O as hl,P as Pa,Q as pl,R as Bt,V as gl,W as jl,X as vi,Y as fl,Z as vl,_ as _n,$ as yl,a0 as La,a1 as ja,a2 as Nl,a3 as Ma,a4 as at,a5 as qa,a6 as yi,a7 as bl,a8 as _l,a9 as Ni,aa as wl,ab as bi,ac as Ut,ad as Gt,ae as Ie,af as Rs,ag as $s,ah as ye,ai as Cl,aj as ee,ak as kl,al as Sl,am as Le,an as fa,ao as $e,ap as Be,aq as le,ar as T,as as Ue,at as C,au as Oa,av as Ra,aw as va,ax as Ia,ay as Cs,az as Is,aA as _i,aB as Al,aC as ot,aD as dt,aE as Ns,aF as mt,aG as Pl,aH as ut,aI as xt,aJ as Tl,aK as Fl,aL as zl,aM as El,aN as Dl,aO as ke,aP as Se,aQ as Ae,aR as Pe,aS as X,aT as Ll,aU as wi,aV as Ml,aW as ia,aX as ra,aY as ql,aZ as wn,a_ as Vt,a$ as Ci,b0 as la,b1 as Ol,b2 as Rl,b3 as js,b4 as ds,b5 as bs,b6 as Ve,b7 as Il,b8 as Ps,b9 as Qs,ba as Ks,bb as Ye,bc as Je,bd as ca,be as ki,bf as $l,bg as sn,bh as an,bi as Bl,bj as Ul,bk as Gl,bl as Vl,bm as vt,bn as Ya,bo as xs,bp as Ql,bq as Kl,br as Hl,bs as Cn,bt as kn,bu as Sn,bv as An,bw as Pn,bx as Tn,by as Fn,bz as zn,bA as Ua,bB as Wl,bC as En,bD as Yl,bE as ma,bF as Jl,bG as Xl,bH as Zl,bI as ec,bJ as Dn,bK as sc,bL as Si,bM as ac,bN as Ai,bO as tc,bP as nc,bQ as ic,bR as tn,bS as rc,bT as ss,bU as as,bV as ts,bW as ns,bX as is,bY as rs,bZ as ls,b_ as cs,b$ as ya,c0 as lc,c1 as cc,c2 as oc,c3 as dc,c4 as mc,c5 as uc,c6 as xc,c7 as tt,c8 as hc,c9 as pc,ca as yt,cb as gc,cc as Nt,cd as jc,ce as fc,cf as vc,cg as yc,ch as Ln,ci as Pi,cj as Nc,ck as bc,cl as _c,cm as wc,cn as Cc,co as Mn,cp as kc,cq as Sc,cr as ht,cs as Ac,ct as Pc,cu as Tc,cv as Fc,cw as nn,cx as zc,cy as Ec,cz as Dc,cA as Lc,cB as Mc,cC as qc,cD as Oc,cE as Rc,cF as Ic,cG as $c,cH as Qt,cI as Bc,cJ as Uc,cK as Gc,cL as nt,cM as qn,cN as Vc,cO as Qc,cP as On,cQ as Js,cR as Xs,cS as Zs,cT as ea,cU as sa,cV as Rn,cW as Kt,cX as bt,cY as Kc,cZ as Hc,c_ as rn,c$ as Wc,d0 as Yc,d1 as Ht,d2 as Jc,d3 as Xc,d4 as Zc,d5 as eo,d6 as so,d7 as In,d8 as ao,d9 as to,da as no,db as io,dc as ro}from"./SocCodeForm-CTX6fOB4.js";function lo({items:a=[]}){const s=Vs(),t=kr(),[n,i]=m.useState({}),{state:c,isMobile:r,setOpenMobile:o}=Br(),l=c==="collapsed"&&!r,[_,h]=m.useState(l);m.useEffect(()=>{if(l===_)return;const b=setTimeout(()=>h(l),200);return()=>clearTimeout(b)},[l,_]),m.useEffect(()=>{const b=a.find(P=>{var z;return P.isActive||((z=P.items)==null?void 0:z.some(p=>p.url!=="#"&&t.pathname.startsWith(p.url)))});b&&i(P=>P[b.title]?P:{...P,[b.title]:!0})},[a,t.pathname]);const N=()=>{r&&o(!1)},g=b=>b!=="#"&&t.pathname===b;return e.jsx(Ur,{children:e.jsx(Gr,{children:a.map(b=>{var z;const P=!!((z=b.items)!=null&&z.length);return P&&_?e.jsx(Nn,{children:e.jsxs(Vr,{children:[e.jsx(Qr,{asChild:!0,children:e.jsxs(bn,{className:"cursor-pointer","aria-label":b.title,children:[b.icon&&e.jsx(b.icon,{}),e.jsx("span",{children:b.title})]})}),e.jsxs(Kr,{side:"right",align:"start",sideOffset:8,className:"min-w-52 max-h-[70vh] overflow-y-auto",children:[e.jsx(Hr,{className:"truncate",children:b.title}),e.jsx(Wr,{}),b.items.map(p=>e.jsx(Yr,{asChild:!0,className:g(p.url)?"bg-accent":void 0,children:e.jsx(Ss,{to:p.url,onClick:N,children:p.title})},p.title))]})]})},b.title):e.jsx(Jr,{open:n[b.title]||!1,onOpenChange:p=>i(M=>({...M,[b.title]:p})),asChild:!0,className:"group/collapsible bg-primary",children:e.jsxs(Nn,{children:[e.jsx(Xr,{asChild:!0,className:"cursor-pointer",children:e.jsxs(bn,{tooltip:b.title,onClick:()=>{b.url&&b.url!=="#"&&(s(b.url),P||N())},children:[b.icon&&e.jsx(b.icon,{}),e.jsx("span",{children:b.title}),P?e.jsx(wa,{className:`ml-auto transition-transform duration-200 ${n[b.title]?"rotate-90":""}`}):null]})}),P?e.jsx(Zr,{children:e.jsx(el,{children:b.items.map(p=>e.jsx(sl,{children:e.jsx(al,{asChild:!0,isActive:g(p.url),className:"text-white hover:text-primary transition-colors duration-200",children:e.jsxs(Ss,{to:p.url,className:"flex items-center gap-2 w-full py-1.5",onClick:N,children:[e.jsx("div",{className:"w-4 h-4 flex items-center justify-center shrink-0",children:"â¢"}),e.jsx("span",{className:"truncate",children:p.title})]})})},p.title))})}):null]})},b.title)})})})}const co=async()=>{var a,s;try{const t=fs("token","admin");if(!t)return console.error("No admin auth token found"),!1;const i=await Sr.get("http://localhost:8000/api/admin/auth/refresh-authorization",{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(((a=i.data)==null?void 0:a.status)==="OK"&&((s=i.data)!=null&&s.data)){const c=i.data.data;return(c.navigation_menu||c.admin_menu_list)&&(na("navigation_menu",c.navigation_menu||c.admin_menu_list,"admin"),na("admin_menu_list",c.navigation_menu||c.admin_menu_list,"admin")),c.menu_keys&&na("menu_keys",c.menu_keys,"admin"),c.permission_keys&&na("permission_keys",c.permission_keys,"admin"),c.encrypted_auth_data&&na("encrypted_auth_data",c.encrypted_auth_data,"admin"),window.dispatchEvent(new Event("storage")),window.dispatchEvent(new CustomEvent("adminAuthorizationUpdated",{detail:{menuKeys:c.menu_keys,permissionKeys:c.permission_keys,navigationMenu:c.navigation_menu||c.admin_menu_list}})),console.log("V2 Admin Authorization data refreshed successfully"),!0}return!1}catch(t){return console.error("Failed to refresh admin authorization data:",t),!1}},oo={Building2:Xe,ShieldUser:fi,Settings2:ji,CalendarCheck:gi,Key:pi,HelpCircle:ga,Users:gs,Ticket:Da,MessageSquare:en,Star:Ea,UserPlus:rl,BarChart3:hi,Briefcase:pa,Database:Zt,FileText:da};function mo({...a}){const s=Ar(),{t}=Xt("global"),[n,i]=m.useState([]);m.useEffect(()=>{const r=()=>{console.log("ð Loading admin menu from localStorage...");const l=fs("navigation_menu","admin"),_=fs("admin_menu_list","admin"),h=l||_;if(console.log("ð¦ localStorage check:",{v2Menu:l?`${l.length} items`:"not found",legacyMenu:_?`${_.length} items`:"not found",usingMenu:h?"server menu":"fallback"}),h&&Array.isArray(h))try{const N=h.map(g=>{const b={...g,title:g.label||g.name,icon:oo[g.icon]||ga,url:g.route?`/admin-dashboard/${g.route}`:g.url?`/admin-dashboard/${g.url}`:"#"},P=g.features||g.feature_groups||g.items;return P&&Array.isArray(P)&&(b.items=P.map(z=>{var p;return{title:z.label||z.title||z.name,url:z.route?`/admin-dashboard/${z.route}`:z.url?`/admin-dashboard/${z.url}`:"#",items:(p=z.features||z.items)==null?void 0:p.map(M=>({title:M.label||M.title||M.name,url:M.route?`/admin-dashboard/${M.route}`:M.url?`/admin-dashboard/${M.url}`:"#"}))}})),b});i(N||[])}catch(N){console.error("â Error processing admin menu list:",N),i([])}else console.warn("â ï¸ No admin menu found in localStorage, using hardcoded fallback"),i([{title:t("admin-sidebar.userManagement","User Management"),url:"#",icon:gs,items:[{title:t("admin-sidebar.addAdmin","Add Admin"),url:"/admin-dashboard/users/add"},{title:t("admin-sidebar.adminList","Admin List"),url:"/admin-dashboard/users"}
1,{title:t("admin-sidebar.activityLog","Activity Log"),url:"/admin-dashboard/activity-log"}]},{title:t("admin-sidebar.organizationSection","Organization Section"),url:"#",icon:Xe,items:[{title:t("admin-sidebar.addOrganization","Add Organization"),url:"/admin-dashboard/organizations/add"},{title:t("admin-sidebar.allOrganizations","All Organizations"),url:"/admin-dashboard/organizations"}]},{title:t("admin-sidebar.rolesPermissions","Roles & Permissions"),url:"#",icon:fi,items:[{title:t("admin-sidebar.manageRoles","Manage Roles"),url:"/admin-dashboard/access-control/roles"}]},{title:t("admin-sidebar.subscriptionManagement","Subscription Management"),url:"/admin-dashboard/subscription",icon:gi},{title:t("admin-sidebar.couponManagement","Coupon Management"),url:"/admin-dashboard/coupons",icon:Da},{title:t("admin-sidebar.licenseManagement","License Management"),url:"#",icon:pi,items:[{title:t("admin-sidebar.allLicenses","All Licenses"),url:"/admin-dashboard/licenses"},{title:t("admin-sidebar.expiredLicenses","Expired Licenses"),url:"/admin-dashboard/licenses/expired"},{title:t("admin-sidebar.revenueAnalytics","Revenue Analytics"),url:"/admin-dashboard/licenses/revenue"}]},{title:t("admin-sidebar.reports","Reports"),url:"#",icon:hi,items:[{title:t("admin-sidebar.organizationReports","Organization Reports"),url:"/admin-dashboard/reports/organizations"},{title:t("admin-sidebar.revenueReports","Revenue Reports"),url:"/admin-dashboard/reports/revenue"}]},{title:t("admin-sidebar.recruitment","Recruitment"),url:"/admin-dashboard/recruitment",icon:pa},{title:t("admin-sidebar.helpSupport","Help & Support"),url:"/admin-dashboard/support",icon:ga},{title:t("admin-sidebar.contactSubmissions","Contact Submissions"),url:"/admin-dashboard/contact-submissions",icon:en},{title:t("admin-sidebar.customerFeedback","Customer Feedback"),url:"/admin-dashboard/customer-feedback",icon:Ea},{title:t("admin-sidebar.marketingContent","Marketing & Content"),url:"#",icon:da,items:[{title:t("admin-sidebar.blogPosts","Blog Posts"),url:"/admin-dashboard/settings/blog-posts"},{title:t("admin-sidebar.leadSubmissions","Lead Submissions"),url:"/admin-dashboard/lead-submissions"},{title:t("admin-sidebar.marketingContentEditor","Marketing Content"),url:"/admin-dashboard/settings/marketing-content"},{title:t("admin-sidebar.platformComparison","Platform Comparison"),url:"/admin-dashboard/settings/platform-comparison"},{title:t("admin-sidebar.pricingComparison","Pricing Comparison"),url:"/admin-dashboard/settings/pricing-comparison"}]},{title:t("admin-sidebar.settings","Settings"),url:"#",icon:ji,items:[{title:t("admin-sidebar.configurations","Configurations"),url:"/admin-dashboard/settings/configurations"},{title:t("admin-sidebar.changePassword","Change Password"),url:"/admin-dashboard/settings/change-password"},{title:t("admin-sidebar.policySetup","Policy Setup"),url:"/admin-dashboard/settings/site-pages"},{title:t("admin-sidebar.socCodes","SOC Codes"),url:"/admin-dashboard/settings/soc-codes"},{title:t("admin-sidebar.emailLogs","Email Logs"),url:"/admin-dashboard/settings/email-logs"},{title:t("admin-sidebar.videoTutorials","Video Tutorials"),url:"/admin-dashboard/support/video-tutorials"},{title:t("admin-sidebar.faqs","FAQs"),url:"/admin-dashboard/support/faqs"}]}])};r(),co();const o=()=>{console.log("Storage event detected, reloading admin menu list..."),r()};return window.addEventListener("storage",o),()=>{window.removeEventListener("storage",o)}},[t]);const c={navMain:n};return e.jsxs(tl,{collapsible:"icon",className:"bg-primary",...a,side:s==="ar"?"right":"left",children:[e.jsx("div",{className:"bg-primary shrink-0",children:e.jsx(Ss,{to:"/admin-dashboard",className:"flex items-center justify-center overflow-hidden p-4 group-data-[collapsible=icon]:p-1.5",children:e.jsx("img",{src:Pr.logo,alt:"Logo",className:"w-auto max-w-full object-contain h-12 md:h-14 lg:h-16 group-data-[collapsible=icon]:h-7"})})}),e.jsx(nl,{className:"bg-primary group-data-[collapsible=icon]:overflow-y-auto group-data-[collapsible=icon]:overflow-x-hidden",children:e.jsx(lo,{items:c.navMain}
vendor: 10,434 bytes, lines 1-2
1)}),e.jsx(il,{})]})}const uo=1024;function xo(){return typeof window>"u"?!0:window.innerWidth>=uo}function ho(){return e.jsxs(ll,{defaultOpen:xo(),className:"h-svh max-h-svh overflow-hidden",children:[e.jsx(mo,{}),e.jsx(cl,{className:"h-full min-h-0",children:e.jsx(Tr,{})})]})}var po=["type","layout","connectNulls","ref"],go=["key"];function Na(a){"@babel/helpers - typeof";return Na=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Na(a)}function $n(a,s){if(a==null)return{};var t=jo(a,s),n,i;if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(a);for(i=0;i<c.length;i++)n=c[i],!(s.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(a,n)&&(t[n]=a[n])}return t}function jo(a,s){if(a==null)return{};var t={};for(var n in a)if(Object.prototype.hasOwnProperty.call(a,n)){if(s.indexOf(n)>=0)continue;t[n]=a[n]}return t}function za(){return za=Object.assign?Object.assign.bind():function(a){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(a[n]=t[n])}return a},za.apply(this,arguments)}function Bn(a,s){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);s&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),t.push.apply(t,n)}return t}function ys(a){for(var s=1;s<arguments.length;s++){var t=arguments[s]!=null?arguments[s]:{};s%2?Bn(Object(t),!0).forEach(function(n){As(a,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(t)):Bn(Object(t)).forEach(function(n){Object.defineProperty(a,n,Object.getOwnPropertyDescriptor(t,n))})}return a}function ha(a){return No(a)||yo(a)||vo(a)||fo()}function fo(){throw new TypeError(`Invalid attempt to spread non-iterable instance. 2In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vo(a,s){if(a){if(typeof a=="string")return Wt(a,s);var t=Object.prototype.toString.call(a).slice(8,-1);if(t==="Object"&&a.constructor&&(t=a.constructor.name),t==="Map"||t==="Set")return Array.from(a);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Wt(a,s)}}function yo(a){if(typeof Symbol<"u"&&a[Symbol.iterator]!=null||a["@@iterator"]!=null)return Array.from(a)}function No(a){if(Array.isArray(a))return Wt(a)}function Wt(a,s){(s==null||s>a.length)&&(s=a.length);for(var t=0,n=new Array(s);t<s;t++)n[t]=a[t];return n}function bo(a,s){if(!(a instanceof s))throw new TypeError("Cannot call a class as a function")}function Un(a,s){for(var t=0;t<s.length;t++){var n=s[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(a,Fi(n.key),n)}}function _o(a,s,t){return s&&Un(a.prototype,s),t&&Un(a,t),Object.defineProperty(a,"prototype",{writable:!1}),a}function wo(a,s,t){return s=it(s),Co(a,Ti()?Reflect.construct(s,t||[],it(a).constructor):s.apply(a,t))}function Co(a,s){if(s&&(Na(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ko(a)}function ko(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Ti(){try{var a=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Ti=function(){return!!a})()}function it(a){return it=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},it(a)}function So(a,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(s&&s.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),s&&Yt(a,s)}function Yt(a,s){return Yt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,i){return n.__proto__=i,n},Yt(a,s)}function As(a,s,t){return s=Fi(s),s in a?Object.defineProperty(a,s,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[s]=t,a}function Fi(a){var s=Ao(a,"string");return Na(s)=="symbol"?s:s+""}function Ao(a,s){if(Na(a)!="object"||!a)return a;var t=a[Symbol.toPrimitive];if(t!==void 0){var n=t.call(a,s);if(Na(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(a)}var ba=function(a){function s(){var t;bo(this,s);for(var n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];return t=wo(this,s,[].concat(i)),As(t,"state",{isAnimationFinished:!0,totalLength:0}),As(t,"generateSimpleStrokeDasharray",function(r,o){return"".concat(o,"px ").concat(r-o,"px")}),As(t,"getStrokeDasharray",function(r,o,l){var _=l.reduce(function(M,A){return M+A});if(!_)return t.generateSimpleStrokeDasharray(o,r);for(var h=Math.floor(r/_),N=r%_,g=o-r,b=[],P=0,z=0;P<l.length;z+=l[P],++P)if(z+l[P]>N){b=[].concat(ha(l.slice(0,P)),[N-z]);break}var p=b.length%2===0?[0,g]:[g];return[].concat(ha(s.repeat(l,h)),ha(b),p).map(function(M){return"".concat(M,"px")}).join(", ")}),As(t,"id",fl("recharts-line-")),As(t,"pathRef",function(r){t.mainCurve=r}),As(t,"handleAnimationEnd",function(){t.setState({isAnimationFinished:!0}),t.props.onAnimationEnd&&t.props.onAnimationEnd()}),As(t,"handleAnimationStart",function(){t.setState({isAnimationFinished:!1}),t.props.onAnimationStart&&t.props.onAnimationStart()}),t}return So(s,a),_o(s,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();this.setState({totalLength:n})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var n=this.getTotalLength();n!==this.state.totalLength&&this.setState({totalLength:n})}}},{key:"getTotalLength",value:function(){var n=this.mainCurve;try{return n&&n.getTotalLength&&n.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(n,i){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var c=this.props,r=c.points,o=c.xAxis,l=c.yAxis,_=c.layout,h=c.children,N=ml(h,ul);if(!N)return null;var g=function(z,p){return{x:z.x,y:z.y,value:z.value,errorVal:vi(z.payload,p)}},b={clipPath:n?"url(#clipPath-".concat(i,")"):null};return pe.createElement(ft,b,N.map(function(P){return pe.cloneElement(P,{key:"bar-".concat(P.props.dataKey),data:r,xAxis:o,yAxis:l,layout:_,dataPointFormatter:g})}))}},{key:"renderDots",value:function(n,i,c){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var o=this.props,l=o.dot,_=o.points,h=o.dataKey,N=Ba(this.props,!1),g=Ba(l,!0),b=_.map(function(z,p){var M=ys(ys(ys({key:"dot-".concat(p),r:3},N),g),{},{index:p,cx:z.x,cy:z.y,value:z.value,dataKey:h,payload:z.payload,points:_});return s.renderDotItem(l,M)}),P={clipPath:n?"url(#clipPath-".concat(i?"":"dots-").concat(c,")"):null};return pe.createElement(ft,za({className:"recharts-line-dots",key:"dots"},P),b)}},{key:"renderCurveStatically",value:function(n,i,c,r){var o=this.props,l=o.type,_=o.layout,h=o.connectNulls;o.ref;var N=$n(o,po),g=ys(ys(ys({},Ba(N,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:i?"url(#clipPath-".concat(c,")"):null,points:n},r),{},{type:l,layout:_,connectNulls:h});return pe.createElement(xl,za({},g,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(n,i){var c=this,r=this.props,o=r.points,l=r.strokeDasharray,_=r.isAnimationActive,h=r.animationBegin,N=r.animationDuration,g=r.animationEasing,b=r.animationId,P=r.animateNewValues,z=r.width,p=r.height,M=this.state,A=M.prevPoints,O=M.totalLength;return pe.createElement(hl,{begin:h,duration:N,isActive:_,easing:g,from:{t:0},to:{t:1},key:"line-".concat(b),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(k){var j=k.t;if(A){var S=A.length/o.length,d=o.map(function(F,K){var q=Math.floor(K*S);if(A[q]){var U=A[q],re=Pa(U.x,F.x),te=Pa(U.y,F.y);return ys(ys({},F),{},{x:re(j),y:te(j)})}if(P){var G=Pa(z*2,F.x),w=Pa(p/2,F.y);return ys(ys({},F),{},{x:G(j),y:w(j)})}return ys(ys({},F),{},{x:F.x,y:F.y})});return c.renderCurveStatically(d,n,i)}var L=Pa(0,O),I=L(j),B;if(l){var y="".concat(l).split(/[,\s]+/gim).map(function(F){return parseFloat(F)});B=c.getStrokeDasharray(I,O,y)}else B=c.generateSimpleStrokeDasharray(O,I);return c.renderCurveStatically(o,n,i,{strokeDasharray:B})})}},{key:"renderCurve",value:function(n,i){var c=this.props,r=c.points,o=c.isAnimationActive,l=this.state,_=l.prevPoints,h=l.totalLength;return o&&r&&r.length&&(!_&&h>0||!pl(_,r))?this.renderCurveWithAnimation(n,i):this.renderCurveStatically(r,n,i)}},{key:"render",value:function(){var n,i=this.props,c=i.hide,r=i.dot,o=i.points,l=i.className,_=i.xAxis,h=i.yAxis,N=i.top,g=i.left,b=i.width,P=i.height,z=i.isAnimationActive,p=i.id;if(c||!o||!o.length)return null;var M=this.state.isAnimationFinished,A=o.length===1,O=yn("recharts-line",l),k=_&&_.allowDataOverflow,j=h&&h.allowDataOverflow,S=k||j,d=Bt(p)?this.id:p,L=(n=Ba(r,!1))!==null&&n!==void 0?n:{r:3,strokeWidth:2},I=L.r,B=I===void 0?3:I,y=L.strokeWidth,F=y===void 0?2:y,K=gl(r)?r:{},q=K.clipDot,U=q===void 0?!0:q,re=B*2+F;return pe.createElement(ft,{className:O},k||j?pe.createElement("defs",null,pe.createElement("clipPath",{id:"clipPath-".concat(d)},pe.createElement("rect",{x:k?g:g-b/2,y:j?N:N-P/2,width:k?b:b*2,height:j?P:P*2})),!U&&pe.createElement("clipPath",{id:"clipPath-dots-".concat(d)},pe.createElement("rect",{x:g-re/2,y:N-re/2,width:b+re,height:P+re}))):null,!A&&this.renderCurve(S,d),this.renderErrorBar(S,d),(A||r)&&this.renderDots(S,U,d),(!z||M)&&jl.renderCallByParent(this.props,o))}}],[{key:"getDerivedStateFromProps",value:function(n,i){return n.animationId!==i.prevAnimationId?{prevAnimationId:n.animationId,curPoints:n.points,prevPoints:i.curPoints}:n.points!==i.curPoints?{curPoints:n.points}:null}},{key:"repeat",value:function(n,i){for(var c=n.length%2!==0?[].concat(ha(n),[0]):n,r=[],o=0;o<i;++o)r=[].concat(ha(r),ha(c));return r}},{key:"renderDotItem",value:function(n,i){var c;if(pe.isValidElement(n))c=pe.cloneElement(n,i);else if(ol(n))c=n(i);else{var r=i.key,o=$n(i,go),l=yn("recharts-line-dot",typeof n!="boolean"?n.className:"");c=pe.createElement(dl,za({key:r},o,{className:l}))}return c}}])}(m.PureComponent);As(ba,"displayName","Line");As(ba,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendT
2ype:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!vl.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});As(ba,"getComposedData",function(a){var s=a.props,t=a.xAxis,n=a.yAxis,i=a.xAxisTicks,c=a.yAxisTicks,r=a.dataKey,o=a.bandSize,l=a.displayedData,_=a.offset,h=s.layout,N=l.map(function(g,b){var P=vi(g,r);return h==="horizontal"?{x:_n({axis:t,ticks:i,bandSize:o,entry:g,index:b}),y:Bt(P)?null:n.scale(P),value:P,payload:g}:{x:Bt(P)?null:t.scale(P),y:_n({axis:n,ticks:c,bandSize:o,entry:g,index:b}),value:P,payload:g}});return ys({points:N,layout:h},_)});var Po=yl({chartName:"LineChart",GraphicalChild:ba,axisComponents:[{axisType:"xAxis",AxisComp:La},{axisType:"yAxis",AxisComp:ja}],formatAxisMap:Nl});function To({data:a,title:s="Revenue Overview",description:t="Monthly revenue and growth rate"}){return e.jsxs(W,{className:"min-w-0 overflow-hidden transition-all duration-200 hover:shadow-md lg:col-span-4",children:[e.jsxs(se,{children:[e.jsx(ae,{children:s}),e.jsx(je,{children:t})]}),e.jsx(Q,{className:"min-w-0 px-0 sm:px-2",children:e.jsx("div",{className:"h-[240px] w-full min-w-0 sm:h-[300px]",children:e.jsx(Ma,{width:"100%",height:"100%",debounce:200,children:e.jsxs(Po,{data:a,margin:{top:5,right:12,left:0,bottom:5},children:[e.jsx(at,{strokeDasharray:"3 3"}),e.jsx(La,{dataKey:"name"}),e.jsx(ja,{yAxisId:"left"}),e.jsx(ja,{yAxisId:"right",orientation:"right"}),e.jsx(qa,{contentStyle:{backgroundColor:"var(--background)",borderColor:"var(--border)",borderRadius:"var(--radius)",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.1)"}}),e.jsx(yi,{}),e.jsx(ba,{yAxisId:"left",type:"monotone",dataKey:"revenue",stroke:"var(--chart-1)",strokeWidth:2,activeDot:{r:8},animationDuration:1e3}),e.jsx(ba,{yAxisId:"right",type:"monotone",dataKey:"growth",stroke:"var(--chart-2)",strokeWidth:2,animationDuration:1500})]})})})})]})}const Ga=["#8884d8","#82ca9d","#ffc658","#ff7f50","#a4de6c","#d0ed57","#8dd1e1","#d885f0"];function Fo({data:a,title:s="Subscription Plans",description:t="Distribution by plan type",labelKey:n="value",total:i}){const c=m.useMemo(()=>i??a.reduce((r,o)=>r+o.value,0),[a,i]);return e.jsxs(W,{className:"flex min-w-0 flex-col overflow-hidden",children:[e.jsxs(se,{className:"items-center pb-0",children:[e.jsx(ae,{children:s}),e.jsx(je,{children:t})]}),e.jsxs(Q,{className:"flex min-w-0 flex-col items-center justify-center gap-4 pb-0",children:[e.jsx("div",{className:"mx-auto h-[180px] w-full min-w-0 sm:h-[200px]",children:e.jsx(Ma,{width:"100%",height:"100%",debounce:200,children:e.jsxs(bl,{children:[e.jsx(qa,{contentStyle:{backgroundColor:"var(--background)",borderColor:"var(--border)",borderRadius:"var(--radius)",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.1)"}}),e.jsxs(_l,{data:a,dataKey:"value",nameKey:"name",innerRadius:60,outerRadius:80,strokeWidth:5,children:[a.map((r,o)=>e.jsx(Ni,{fill:Ga[o%Ga.length]},`cell-${o}`)),e.jsx(wl,{content:({viewBox:r})=>r&&"cx"in r&&"cy"in r?e.jsxs("text",{x:r.cx,y:r.cy,textAnchor:"middle",dominantBaseline:"middle",children:[e.jsx("tspan",{x:r.cx,y:r.cy,className:"fill-foreground text-2xl font-bold",children:c.toLocaleString()}),e.jsx("tspan",{x:r.cx,y:(r.cy||0)+20,className:"fill-muted-foreground text-xs",children:n})]}):null})]})]})})}),e.jsx("div",{className:"flex w-full shrink-0 flex-wrap justify-center gap-x-3 gap-y-1.5 text-xs sm:text-sm",children:a.map((r,o)=>e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("div",{className:"h-2.5 w-2.5 shrink-0 rounded-full",style:{backgroundColor:Ga[o%Ga.length]}}),e.jsx("span",{className:"truncate text-muted-foreground",children:r.name})]},r.name))})]}),e.jsxs(Ha,{className:"flex-col gap-2 pt-4 text-center text-xs sm:text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium leading-none",children:["Trending up by 5.2% this month ",e.jsx(bi,{className:"h-4 w-4 shrink-0"})]}),e.jsx("div",{className:"leading-none text-muted-foreground",children:"Showing total for the last 6 months"})]})]})}function zo({data:a,title:s="Company Growth",description:t="New companies over time"}){return e.jsxs(W,{className:"min-w-0 overflow-hidden transition-all duration-200 hover:shadow-md lg:col-span-4",children:[e.jsxs(se,{children:[e.jsx(ae,{children:s}),e.jsx(je,{children:t})]}),e.jsx(Q,{className:"min-w-0 px-0 sm:px-2",children:e.jsx("div",{className:"h-[240px] w-full min-w-0 sm:h-[300px]",children:e.jsx(Ma,{width:"100%",height:"100%",debounce:200,children:e.jsxs(Ut,{data:a,margin:{top:5,right:12,left:0,bottom:5},children:[e.jsx(at,{strokeDasharray:"3 3"}),e.jsx(La,{dataKey:"name"}),e.jsx(ja,{}),e.jsx(qa,{contentStyle:{backgroundColor:"var(--background)",borderColor:"var(--border)",borderRadius:"var(--radius)",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.1)"}}),e.jsx(yi,{}),e.jsx(Gt,{dataKey:"companies",fill:"var(--chart-3)",barSize:30,radius:[4,4,0,0],animationDuration:1200,className:"transition-all duration-300 hover:opacity-80"})]})})})})]})}function Eo({activities:a}){const s=t=>{switch(t){case"plus":return e.jsx(Ie,{className:"h-5 w-5 text-primary"});case"credit-card":return e.jsx($s,{className:"h-5 w-5 text-primary"});case"users":return e.jsx(gs,{className:"h-5 w-5 text-primary"});case"calendar":return e.jsx(Rs,{className:"h-5 w-5 text-primary"});default:return e.jsx(Ie,{className:"h-5 w-5 text-primary"})}};return e.jsxs(W,{className:"min-w-0 transition-all duration-200 hover:shadow-md lg:col-span-3",children:[e.jsxs(se,{className:"flex flex-row items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"Recent Activities"}),e.jsx(je,{children:"Latest company and subscription changes"})]}),e.jsx(Ss,{to:"/admin-dashboard/activity-log",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto text-xs font-medium shrink-0",children:["See all ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]}),e.jsx(Q,{children:e.jsx("div",{className:"space-y-4 max-h-[300px] overflow-y-auto pr-1",children:a.map(t=>e.jsxs("div",{className:"flex items-start group transition-all duration-200",children:[e.jsx("div",{className:"flex shrink-0 items-center justify-center w-10 h-10 rounded-full bg-primary/10 group-hover:bg-primary/15 transition-colors duration-200",children:s(t.icon)}),e.jsxs("div",{className:"ml-3 sm:ml-4 min-w-0 space-y-1 break-words whitespace-pre-wrap",children:[e.jsx("p",{className:"text-sm font-medium break-words",children:t.title}),e.jsxs("p",{className:"text-sm text-muted-foreground break-words whitespace-pre-wrap",children:[t.description," ⢠",t.time]})]})]},t.id))})})]})}const Do=fs("token"),Lo=He.injectEndpoints({endpoints:a=>({getAdminDashboardOverview:a.query({query:({period:s})=>({url:"/admin/dashboard/overview",method:"GET",params:{period:s},headers:{Authorization:`Bearer ${Do}`}}),providesTags:["adminDashboard"]})})}),{useGetAdminDashboardOverviewQuery:Mo}=Lo,qo=He.injectEndpoints({endpoints:a=>({getAdminAllApplicants:a.query({query:s=>({url:"/admin/applicants",method:"GET",params:{...s.term&&{term:s.term},...s.gender&&{gender:s.gender},...s.page&&{page:s.page},per_page:s.per_page??15}}),providesTags:["adminRecruitment"]}),getAdminRecruitmentStats:a.query({query:()=>({url:"/admin/recruitment/stats",method:"GET"}),providesTags:["adminRecruitment"]}),getAdminAllJobPostings:a.query({query:s=>({url:"/admin/job-postings",method:"GET",params:{...s.status&&{status:s.status},...s.term&&{term:s.term},...s.page&&{page:s.page},...s.organization_id&&{organization_id:s.organization_id},per_page:s.per_page??15}}),providesTags:["adminRecruitment"]})}),overrideExisting:!1}),{useGetAdminAllApplicantsQuery:zi,useGetAdminAllJobPostingsQuery:Oo,useGetAdminRecruitmentStatsQuery:Ro}=qo,es=fs("token"),Io=He.injectEndpoints({endpoints:a=>({getAllLicenses:a.query({query:({status:s,search:t})=>{const n={};return es&&(n.Authorization=`Bearer ${es}`),{url:"/admin/licenses",method:"GET",params:{status:s,search:t},headers:n}},providesTags:["adminLicenses"]}),getExpiredLicenses:a.query({query:({search:s}
2)=>{const t={};return es&&(t.Authorization=`Bearer ${es}`),{url:"/admin/licenses/expired",method:"GET",params:{search:s},headers:t}},providesTags:["adminExpiredLicenses"]}),getRevenueAnalytics:a.query({query:s=>{const t={};return es&&(t.Authorization=`Bearer ${es}`),{url:"/admin/analytics/revenue",method:"GET",params:s!=null&&s.year?{year:s.year}:void 0,headers:t}},transformResponse:s=>s.data,providesTags:["adminRevenueAnalytics"]}),downloadRevenueReport:a.mutation({query:({year:s})=>{const t={Accept:"application/pdf"};return es&&(t.Authorization=`Bearer ${es}`),{url:"/admin/reports/revenue/pdf",method:"GET",params:{period:"year",start_date:`${s}-01-01`,end_date:`${s}-12-31`},headers:t}}}),sendReminderEmail:a.mutation({query:s=>{const t={};return es&&(t.Authorization=`Bearer ${es}`),{url:`/admin/licenses/${s}/send-reminder`,method:"POST",headers:t}},invalidatesTags:["adminExpiredLicenses","adminLicenses"]}),extendGracePeriod:a.mutation({query:({licenseId:s,additional_days:t})=>{const n={};return es&&(n.Authorization=`Bearer ${es}`),{url:`/admin/licenses/${s}/extend-grace`,method:"POST",data:{additional_days:t},headers:n}},invalidatesTags:["adminExpiredLicenses","adminLicenses","adminRevenueAnalytics"]}),manualRenewal:a.mutation({query:({licenseId:s,payment_frequency:t,amount:n,notes:i,apply_coupon:c})=>{const r={};return es&&(r.Authorization=`Bearer ${es}`),{url:`/admin/licenses/${s}/manual-renewal`,method:"POST",body:{payment_frequency:t,...n!==void 0?{amount:n}:{},notes:i,apply_coupon:c??!0},headers:r}},invalidatesTags:["adminExpiredLicenses","adminLicenses","adminRevenueAnalytics"]}),getLicenseDetails:a.query({query:s=>{const t={};return es&&(t.Authorization=`Bearer ${es}`),{url:`/admin/licenses/${s}`,method:"GET",headers:t}},providesTags:(s,t,n)=>[{type:"adminLicenses",id:n}]}),unlockLicense:a.mutation({query:({licenseId:s,...t})=>{const n={};return es&&(n.Authorization=`Bearer ${es}`),{url:`/admin/licenses/${s}/unlock`,method:"POST",body:t,headers:n}},invalidatesTags:["adminExpiredLicenses","adminLicenses","adminRevenueAnalytics"]})})}),{useGetAllLicensesQuery:Ei,useGetExpiredLicensesQuery:$o,useGetRevenueAnalyticsQuery:Bo,useDownloadRevenueReportMutation:Uo,useSendReminderEmailMutation:Di,useExtendGracePeriodMutation:Go,useManualRenewalMutation:Vo,useGetLicenseDetailsQuery:Qo,useUnlockLicenseMutation:Ko}=Io,Ms=fs("token"),Ho=He.injectEndpoints({endpoints:a=>({getAdminSupportTickets:a.query({query:({status:s,priority:t,search:n,page:i=1,per_page:c=15})=>{const r={};return Ms&&(r.Authorization=`Bearer ${Ms}`),{url:"/admin/support-tickets",method:"GET",params:{status:s,priority:t,search:n,page:i,per_page:c},headers:r}},providesTags:["supportTickets"]}),getSupportTicketStats:a.query({query:()=>{const s={};return Ms&&(s.Authorization=`Bearer ${Ms}`),{url:"/admin/support-tickets/stats",method:"GET",headers:s}},providesTags:["supportTickets"]}),getAdminSupportTicket:a.query({query:s=>{const t={};return Ms&&(t.Authorization=`Bearer ${Ms}`),{url:`/admin/support-tickets/${s}`,method:"GET",headers:t}},providesTags:(s,t,n)=>[{type:"supportTickets",id:n}]}),updateTicketStatus:a.mutation({query:({id:s,data:t})=>{const n={};return Ms&&(n.Authorization=`Bearer ${Ms}`),{url:`/admin/support-tickets/${s}/status`,method:"PUT",body:t,headers:n}},invalidatesTags:["supportTickets"]}),deleteTicket:a.mutation({query:s=>{const t={};return Ms&&(t.Authorization=`Bearer ${Ms}`),{url:`/admin/support-tickets/${s}`,method:"DELETE",headers:t}},invalidatesTags:["supportTickets"]})})}),{useGetAdminSupportTicketsQuery:Wo,useGetSupportTicketStatsQuery:Li,useUpdateTicketStatusMutation:Yo}=Ho,Jo=He.injectEndpoints({endpoints:a=>({getAdminUsers:a.query({query:({page:s=1,per_page:t=15,search:n=""})=>({url:"/admin/users",params:{page:s,per_page:t,search:n}}),transformResponse:s=>{const t=(s==null?void 0:s.data)??s;return Array.isArray(t)?{data:t}:{data:(t==null?void 0:t.data)??[],meta:{current_page:(t==null?void 0:t.current_page)??1,last_page:(t==null?void 0:t.last_page)??1,per_page:(t==null?void 0:t.per_page)??15,total:(t==null?void 0:t.total)??0}}},providesTags:["AdminUsers"]}),getAdminUser:a.query({query:s=>({url:`/admin/users/${s}`}),providesTags:(s,t,n)=>[{type:"AdminUsers",id:n}]}),createAdminUser:a.mutation({query:s=>({url:"/admin/users",method:"POST",body:s}),invalidatesTags:["AdminUsers"]}),updateAdminUser:a.mutation({query:({id:s,data:t})=>({url:`/admin/users/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>["AdminUsers",{type:"AdminUsers",id:n}]}),deleteAdminUser:a.mutation({query:s=>({url:`/admin/users/${s}`,method:"DELETE"}),invalidatesTags:["AdminUsers"]}),getSystemRoles:a.query({query:()=>({url:"/admin/system-roles/roles"}),providesTags:["SystemRoles"]})})}),{useGetAdminUsersQuery:ln,useCreateAdminUserMutation:Xo,useUpdateAdminUserMutation:Zo,useDeleteAdminUserMutation:ed,useGetSystemRolesQuery:Mi}=Jo,sd=He.injectEndpoints({endpoints:a=>({getContactSubmissions:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.status&&n.push(`status=${encodeURIComponent(s.status)}`),s!=null&&s.search&&n.push(`search=${encodeURIComponent(s.search)}`),{url:`/admin/contact-submissions?${n.join("&")}`,method:"GET"}},providesTags:["contact-submissions"]}),getContactSubmissionStats:a.query({query:()=>({url:"/admin/contact-submissions/stats",method:"GET"}),providesTags:["contact-submissions"]}),getContactSubmission:a.query({query:s=>({url:`/admin/contact-submissions/${s}`,method:"GET"}),providesTags:["contact-submissions"]}),updateContactSubmissionStatus:a.mutation({query:({id:s,body:t})=>({url:`/admin/contact-submissions/${s}/status`,method:"PUT",body:t}),invalidatesTags:["contact-submissions"]}),deleteContactSubmission:a.mutation({query:s=>({url:`/admin/contact-submissions/${s}`,method:"DELETE"}),invalidatesTags:["contact-submissions"]})}),overrideExisting:!0}),{useGetContactSubmissionsQuery:ad,useGetContactSubmissionStatsQuery:qi,useUpdateContactSubmissionStatusMutation:td,useDeleteContactSubmissionMutation:nd}=sd;function id(){var L,I,B,y;const[a]=m.useState("monthly"),{data:s,isLoading:t,isError:n}=Mo({period:a}),{data:i}=zi({page:1,per_page:1}),c=((L=i==null?void 0:i.meta)==null?void 0:L.total)??0,{data:r}=Ei({}),{data:o}=Li(),{data:l}=ln({page:1,per_page:1}),{data:_}=qi(),h=((I=r==null?void 0:r.statistics)==null?void 0:I.total)??0,N=(o==null?void 0:o.total)??0,g=((B=l==null?void 0:l.meta)==null?void 0:B.total)??0,b=((y=_==null?void 0:_.data)==null?void 0:y.total)??0;if(t)return e.jsx(ye,{title:"Dashboard",subtitle:"",link:"/admin-dashboard",children:e.jsx("main",{className:"flex flex-1 flex-col gap-4 p-3 sm:p-4 md:gap-8 md:p-8",children:e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-3",children:[e.jsx(ce,{className:"w-10 h-10 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading dashboard data..."})]})})});if(n||!s)return e.jsx(ye,{title:"Dashboard",subtitle:"",link:"/admin-dashboard",children:e.jsx("main",{className:"flex flex-1 flex-col gap-4 p-3 sm:p-4 md:gap-8 md:p-8",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-lg text-muted-foreground",children:"No data available"})})})});const{stats:P,revenueData:z,companyGrowthData:p,subscriptionData:M,recentActivities:A,operationalStats:O}=s,k=O==null?void 0:O.subscriptions,j=O==null?void 0:O.deletion_requests,S=P.filter(F=>!["Active Accounts","Growth Rate"].includes(F.title)),d=["from-indigo-100 to-indigo-50 dark:from-indigo-900 dark:to-indigo-800","from-pink-100 to-pink-50 dark:from-pink-900 dark:to-pink-800","from-teal-100 to-teal-50 dark:from-teal-900 dark:to-teal-800","from-yellow-100 to-yellow-50 dark:from-yellow-900 dark:to-yellow-800"];return e.jsx(ye,{title:"Dashboard",subtitle:"",link:"/admin-dashboard",children:e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col gap-4 p-3 sm:p-4 md:gap-8 animate-in fade-in-50 duration-500",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4",children:[S.map((F,K)=>{const q=F.trend==="up"?bi:Cl;return e.jsx(Wa.div,{initial:{opacity:0,y:20}
2,animate:{opacity:1,y:0},transition:{delay:K*.1,duration:.5},children:e.jsxs(W,{className:`@container/card group transition-shadow duration-300 hover:shadow-xl bg-gradient-to-t ${d[K]} border border-border hover:border-primary/70 h-full`,children:[e.jsxs(se,{className:"relative",children:[e.jsx(je,{children:F.title}),e.jsx(ae,{className:"text-2xl font-semibold tabular-nums",children:F.value}),e.jsx("div",{className:"absolute right-4 top-4",children:e.jsxs(ee,{variant:"outline",className:"flex gap-1 rounded-lg text-xs text-muted-foreground",children:[e.jsx(q,{className:"size-3"}),F.change]})})]}),e.jsxs(Ha,{className:"flex-col items-start gap-1 text-sm",children:[e.jsxs("div",{className:"line-clamp-1 flex gap-2 font-medium",children:[F.subtext," ",e.jsx(q,{className:"size-4"})]}),e.jsx("div",{className:"text-muted-foreground",children:F.description})]})]})},K)}),e.jsx(Wa.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2,duration:.5},children:e.jsxs(W,{className:`group transition-shadow duration-300 hover:shadow-xl bg-gradient-to-t ${d[2]} border border-border hover:border-primary/70 h-full`,children:[e.jsxs(se,{className:"relative",children:[e.jsx(je,{children:"Total Subscriptions"}),e.jsx(ae,{className:"text-2xl font-semibold tabular-nums",children:h}),e.jsx("div",{className:"absolute right-4 top-4",children:e.jsx($s,{className:"w-5 h-5 text-teal-600"})})]}),e.jsxs(Ha,{className:"flex-col items-start gap-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:"All licences"}),e.jsx("div",{className:"text-muted-foreground",children:"Across all organisations"}),e.jsx(Ss,{to:"/admin-dashboard/licenses",className:"mt-1",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto text-xs font-medium",children:["View licences ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]})}),e.jsx(Wa.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.3,duration:.5},children:e.jsxs(W,{className:`group transition-shadow duration-300 hover:shadow-xl bg-gradient-to-t ${d[3]} border border-border hover:border-primary/70 h-full`,children:[e.jsxs(se,{className:"relative",children:[e.jsx(je,{children:"Total Supports"}),e.jsx(ae,{className:"text-2xl font-semibold tabular-nums",children:N}),e.jsx("div",{className:"absolute right-4 top-4",children:e.jsx(kl,{className:"w-5 h-5 text-yellow-600"})})]}),e.jsxs(Ha,{className:"flex-col items-start gap-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:"Support tickets raised"}),e.jsx("div",{className:"text-muted-foreground",children:"All statuses combined"}),e.jsx(Ss,{to:"/admin-dashboard/support",className:"mt-1",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto text-xs font-medium",children:["View tickets ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]})})]}),e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-7",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:col-span-3",children:[e.jsxs(W,{className:"border-l-4 border-l-blue-500 hover:shadow-lg transition-all duration-300",children:[e.jsxs(se,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total Applicants"}),e.jsx(gs,{className:"w-5 h-5 text-blue-500"})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-3xl font-bold",children:c}),e.jsx(je,{className:"mt-1",children:"Registered applicant users in system"}),e.jsx(Ss,{to:"/admin-dashboard/recruitment",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto mt-2 text-xs font-medium",children:["View all recruitment data",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]}),e.jsxs(W,{className:"border-l-4 border-l-amber-500 hover:shadow-lg transition-all duration-300",children:[e.jsxs(se,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Contact Messages"}),e.jsx(en,{className:"w-5 h-5 text-amber-500"})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-3xl font-bold",children:b}),e.jsx(je,{className:"mt-1",children:"Total contact form submissions"}),e.jsx(Ss,{to:"/admin-dashboard/contact-submissions",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto mt-2 text-xs font-medium",children:["View submissions ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]}),e.jsxs(W,{className:"border-l-4 border-l-purple-500 hover:shadow-lg transition-all duration-300",children:[e.jsxs(se,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Admin Users"}),e.jsx(Sl,{className:"w-5 h-5 text-purple-500"})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-3xl font-bold",children:g}),e.jsx(je,{className:"mt-1",children:"Registered admin accounts"}),e.jsx(Ss,{to:"/admin-dashboard/users",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto mt-2 text-xs font-medium",children:["View users ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]}),e.jsxs(W,{className:"border-l-4 border-l-red-500 hover:shadow-lg transition-all duration-300",children:[e.jsxs(se,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Deletion Requests"}),e.jsx(Le,{className:"w-5 h-5 text-red-500"})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-3xl font-bold",children:(j==null?void 0:j.organizations_pen
2ding)??0}),e.jsx(je,{className:"mt-1",children:"Marked for Deletion"}),e.jsx(Ss,{to:"/admin-dashboard/organizations/pending-deletions",children:e.jsxs(u,{variant:"link",size:"sm",className:"p-0 h-auto mt-2 text-xs font-medium",children:["Review ",e.jsx(ta,{className:"w-3 h-3 ml-1"})]})})]})]})]}),e.jsx("div",{className:"min-w-0 lg:col-span-4",children:e.jsx(Fo,{data:M,title:"Plans Overview",description:"Customer subscriptions",labelKey:"Subscriptions",total:h})})]}),e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-7",children:[e.jsx("div",{className:`min-w-0 ${k||j?"lg:col-span-4":"lg:col-span-7"}`,children:e.jsx(To,{data:z})}),(k||j)&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:col-span-3",children:[e.jsxs(W,{className:`h-full flex flex-col border-l-4 border-l-amber-500 ${((k==null?void 0:k.cancelling)??0)>0?"ring-1 ring-amber-200":""}`,children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-xs font-medium text-muted-foreground",children:"Cancelling"})}),e.jsxs(Q,{className:"flex-1 flex flex-col justify-center",children:[e.jsx("div",{className:"text-2xl font-bold text-amber-600",children:(k==null?void 0:k.cancelling)??0}),e.jsx(je,{className:"mt-1 text-xs",children:"Ending at period end"})]})]}),e.jsxs(W,{className:`h-full flex flex-col border-l-4 border-l-orange-500 ${((k==null?void 0:k.in_grace_period)??0)>0?"ring-1 ring-orange-200":""}`,children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-xs font-medium text-muted-foreground",children:"In Grace Period"})}),e.jsxs(Q,{className:"flex-1 flex flex-col justify-center",children:[e.jsx("div",{className:"text-2xl font-bold text-orange-600",children:(k==null?void 0:k.in_grace_period)??0}),e.jsx(je,{className:"mt-1 text-xs",children:"Expired, still reachable"})]})]}),e.jsxs(W,{className:"h-full flex flex-col border-l-4 border-l-red-500",children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-xs font-medium text-muted-foreground",children:"Expired"})}),e.jsxs(Q,{className:"flex-1 flex flex-col justify-center",children:[e.jsx("div",{className:"text-2xl font-bold text-red-600",children:(k==null?void 0:k.expired)??0}),e.jsx(je,{className:"mt-1 text-xs",children:"Past their expiry date"})]})]}),e.jsxs(W,{className:"h-full flex flex-col border-l-4 border-l-slate-400",children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-xs font-medium text-muted-foreground",children:"Accounts Deleted"})}),e.jsxs(Q,{className:"flex-1 flex flex-col justify-center",children:[e.jsx("div",{className:"text-2xl font-bold text-slate-600",children:(j==null?void 0:j.organizations_deleted)??0}),e.jsx(je,{className:"mt-1 text-xs",children:"Removed organisations"})]})]})]})]}),e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-7 items-start",children:[e.jsx(zo,{data:p}),e.jsx(Eo,{activities:A})]})]})})}const aa=()=>({token:fs("token","admin")}),rd=He.injectEndpoints({endpoints:a=>({getOrganizationsWithSubscriptions:a.query({query:({page:s=1,status:t="active",search:n,license_status:i,package_name:c,per_page:r=15})=>{const{token:o}=aa(),l={};o&&(l.Authorization=`Bearer ${o}`);const _=new URLSearchParams;return _.set("page",String(s)),_.set("status",t),_.set("per_page",String(r)),n&&_.set("search",n),i&&_.set("license_status",i),c&&_.set("package_name",c),{url:`/organizations-with-subscriptions?${_.toString()}`,method:"GET",headers:l}},transformResponse:s=>({...s,data:s.data.map(n=>{var i;return n.license&&(n.subscription={id:n.license.id,status:n.license.status,starts_at:n.license.starts_at,expires_at:n.license.expires_at,payment_frequency:n.license.payment_frequency,price:n.license.price!==void 0?Number(n.license.price):void 0,free_trial_days:n.license.free_trial_days,applied_coupon:n.license.applied_coupon??null,package:n.license.package||n.license.subscription_package||((i=n.current_subscription)==null?void 0:i.package)}),n})}),providesTags:[{type:"organizations",id:"LIST"}]}),getOrganization:a.query({query:s=>{const{token:t}=aa();return{url:`/admin/organizations/${s}`,method:"GET",headers:{Authorization:`Bearer ${t}`}}},transformResponse:s=>{const t=s.data;return t!=null&&t.license&&(t.subscription={id:t.license.id,status:t.license.status,starts_at:t.license.starts_at,expires_at:t.license.expires_at,payment_frequency:t.license.payment_frequency,price:t.license.price!==void 0?Number(t.license.price):void 0,cancel_at_period_end:!!t.license.cancel_at_period_end,free_trial_days:t.license.free_trial_days,applied_coupon:t.license.applied_coupon??null,package:t.license.package}),s},providesTags:(s,t,n)=>[{type:"organizations",id:n}]}),cancelOrganizationSubscription:a.mutation({query:s=>{const{token:t}=aa();return{url:`/admin/organizations/${s}/cancel-subscription`,method:"POST",headers:{Authorization:`Bearer ${t}`}}},invalidatesTags:(s,t,n)=>[{type:"organizations",id:"LIST"},{type:"organizations",id:n}]}),getPendingDeletionOrganizations:a.query({query:()=>{const{token:s}=aa();return{url:"/admin/organizations/pending-deletion",method:"GET",headers:{Authorization:`Bearer ${s}`}}}
2,providesTags:[{type:"organizations",id:"PENDING_DELETION"}]}),restoreOrganization:a.mutation({query:s=>{const{token:t}=aa();return{url:`/admin/organizations/${s}/restore`,method:"POST",headers:{Authorization:`Bearer ${t}`}}},invalidatesTags:[{type:"organizations",id:"LIST"},{type:"organizations",id:"PENDING_DELETION"}]}),forceDeleteOrganization:a.mutation({query:s=>{const{token:t}=aa();return{url:`/admin/organizations/${s}/force-delete`,method:"DELETE",headers:{Authorization:`Bearer ${t}`}}},invalidatesTags:[{type:"organizations",id:"LIST"},{type:"organizations",id:"PENDING_DELETION"}]}),createOrganization:a.mutation({query:s=>{const{token:t}=aa(),n={};return t&&(n.Authorization=`Bearer ${t}`),{url:"/organizations/admin",method:"POST",headers:n,body:s}},invalidatesTags:[{type:"organizations",id:"LIST"}]})})}),{useGetOrganizationsWithSubscriptionsQuery:cn,useGetPendingDeletionOrganizationsQuery:ld,useRestoreOrganizationMutation:cd,useForceDeleteOrganizationMutation:od,useCreateOrganizationMutation:dd}=rd,Va=a=>{if(!a)return"-";const s=a.match(/^(\d{4})-(\d{2})-(\d{2})/);if(s){const[,n,i,c]=s;return new Date(Number(n),Number(i)-1,Number(c)).toLocaleDateString()}const t=new Date(a);return Number.isNaN(t.getTime())?a:t.toLocaleDateString()},_t=a=>{var t;const s=(t=a==null?void 0:a.package)==null?void 0:t.max_employees;return s==null||s===0?null:s},md=a=>a==="yearly"?"Yearly":"Monthly",ud=a=>{var l,_;const s=a==null?void 0:a.applied_coupon,t=(s==null?void 0:s.payment_frequency)??(a==null?void 0:a.payment_frequency),n=t==="yearly"?(l=a==null?void 0:a.package)==null?void 0:l.price_yearly:(_=a==null?void 0:a.package)==null?void 0:_.price_monthly,i=(s==null?void 0:s.original_amount)??(n!=null?Number(n):null),c=(s==null?void 0:s.paid_amount)??((a==null?void 0:a.price)!=null?Number(a.price):null),r=(s==null?void 0:s.discount_amount)??(i!=null&&c!=null?Math.max(0,i-c):null),o=i!=null&&c!=null&&r!=null&&r>0&&c<i;return{frequency:t,periodLabel:md(t),originalAmount:i,paidAmount:c,discountAmount:r,hasDiscount:o,couponCode:(s==null?void 0:s.code)??null}};function xd(){const{t:a}=Xt("global"),[s,t]=pe.useState(1),n=Vs(),[i,c]=pe.useState(!1),[r,o]=pe.useState(""),[l,_]=pe.useState("all"),[h,N]=pe.useState("all"),[g,b]=pe.useState(""),{data:P,isLoading:z,error:p,refetch:M}=cn({page:s,per_page:15,search:r.trim()||void 0,status:l,license_status:h!=="all"?h:void 0,package_name:g.trim()||void 0}),A=(P==null?void 0:P.data)||[],O=(P==null?void 0:P.last_page)||1,k=j=>{var K,q;if(!j)return{text:"No Subscription",color:"bg-gray-100 text-gray-800"};if((K=j.package)!=null&&K.is_free)return{text:"Free",color:"bg-blue-100 text-blue-800"};const S=new Date,d=j.expires_at?new Date(j.expires_at):null,L=d?d<S:!1,I=j.free_trial_days??((q=j.package)==null?void 0:q.free_trial_days)??0,B=j.starts_at?new Date(j.starts_at):null,y=B&&I?new Date(B.getTime()+I*24*60*60*1e3):null;return j.status!=="suspended"&&!!y&&S<y?{text:"Free Trial",color:"bg-purple-100 text-purple-800"}:j.status==="expired"||L?{text:"Expired",color:"bg-red-100 text-red-800"}:j.status==="active"?{text:"Paid",color:"bg-green-100 text-green-800"}:j.status==="inactive"?{text:"Inactive",color:"bg-yellow-100 text-yellow-800"}:{text:j.status,color:"bg-blue-100 text-blue-800"}};return z?e.jsx(ye,{title:"Organization",subtitle:"",link:"/admin-dashboard/organizations",children:e.jsx("div",{className:"p-4",children:e.jsx(W,{className:"shadow-xl rounded-2xl border border-muted",children:e.jsx(Q,{className:"p-40 text-center",children:"Loading organizations..."})})})}):p?e.jsx(ye,{title:"Organization",subtitle:"",link:"/admin-dashboard/organizations",children:e.jsx("div",{className:"p-4",children:e.jsx(W,{className:"shadow-xl rounded-2xl border border-muted",children:e.jsx(Q,{className:"p-40 text-center text-red-500",children:"Error loading organizations"})})})}):e.jsx(ye,{title:"Organization",subtitle:"",link:"/admin-dashboard/organizations",children:e.jsxs("div",{className:"p-4 lg:p-6",children:[e.jsxs(W,{className:"shadow-xl rounded-2xl border border-muted",children:[e.jsx(se,{className:"pb-4",children:e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:justify-between md:items-start",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(ae,{className:"text-xl font-semibold text-primary break-words",children:a("organizations.title")}),e.jsx(je,{className:"break-words",children:a("organizations.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(u,{variant:"outline",onClick:()=>c(!0),children:[e.jsx(fa,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsx(u,{variant:"outline",onClick:()=>M(),children:"Refresh"}),e.jsxs(u,{className:"bg-primary hover:bg-primary/90",onClick:()=>n("/admin-dashboard/organizations/add"),children:[e.jsx(Xe,{className:"h-4 w-4 mr-2"}),"Add Organization"]})]})]})}),e.jsx(Q,{className:"overflow-x-auto",children:e.jsxs($e,{className:"text-sm min-w-full",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.logo")}),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.name")}
2),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.registrationNumber","Reg. Number")}),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.email","Email")}),e.jsx(T,{className:"whitespace-nowrap hidden sm:table-cell",children:a("organizations.fields.contactNumber")}),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.subscription","Subscription")}),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.employees","Employees")}),e.jsx(T,{className:"whitespace-nowrap",children:a("organizations.fields.actions","Actions")})]})}),e.jsx(Ue,{children:A.length>0?A.map((j,S)=>{var B,y,F,K,q,U,re,te,G,w,Y,ue,J,ge,he,me,Z,ne,_e,qe,fe,Qe;const d=k(j.subscription),L=ud(j.subscription),I=L.frequency!=="yearly";return e.jsxs(le,{className:"hover:bg-muted/40",children:[e.jsx(C,{children:e.jsxs(Oa,{className:"h-10 w-10",children:[e.jsx(Ra,{src:va((B=j.logo)==null?void 0:B.url)||void 0,alt:j.name}),e.jsx(Ia,{children:e.jsx(Xe,{className:"h-6 w-6"})})]})}),e.jsx(C,{className:"font-medium",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold max-w-[200px] overflow-hidden text-ellipsis break-all",children:j.name}),e.jsx("div",{className:"text-xs text-muted-foreground sm:hidden",children:j.contact_number})]})}),e.jsx(C,{className:"whitespace-nowrap font-mono text-xs text-muted-foreground",children:j.registration_number||"-"}),e.jsx(C,{className:"max-w-[220px] truncate text-muted-foreground",children:j.organization_email||j.login_email||"N/A"}),e.jsx(C,{className:"hidden sm:table-cell",children:j.contact_number}),e.jsx(C,{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"px-2 py-1 text-xs rounded-full bg-muted w-fit",children:((F=(y=j.subscription)==null?void 0:y.package)==null?void 0:F.name)||"No Subscription"}),e.jsx("div",{className:"text-xs",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${d.color}`,children:d.text}),((K=j.subscription)==null?void 0:K.expires_at)&&e.jsxs("span",{className:"text-muted-foreground",children:[new Date(j.subscription.expires_at)<new Date?"Expired":"Expires"," ",Va(j.subscription.expires_at)]})]})})]})}),e.jsxs(C,{children:[e.jsxs("div",{className:"text-sm font-semibold tabular-nums",children:[j.active_employee_count??0,e.jsxs("span",{className:"text-muted-foreground font-normal",children:["/",_t(j.subscription)??"â"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["active",j.total_employee_count!=null?` · ${j.total_employee_count} total`:""]})]}),e.jsx(C,{children:e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs(Fe,{children:[e.jsx(di,{asChild:!0,children:e.jsx(u,{variant:"ghost",size:"sm",children:e.jsx(Fs,{className:"h-4 w-4"})})}),e.jsxs(ze,{className:"max-w-5xl max-h-[90vh] overflow-y-auto overflow-x-hidden p-0",children:[e.jsx(Ee,{className:"px-6 pt-6 pb-3",children:e.jsxs(De,{className:"flex items-center gap-3 text-xl",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Xe,{className:"h-5 w-5 text-primary"})}),j.name]})}),e.jsxs("div",{className:"px-6 pb-5",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-muted/40 rounded-xl border",children:[e.jsxs(Oa,{className:"h-16 w-16 ring-2 ring-primary/20",children:[e.jsx(Ra,{src:va((q=j.logo)==null?void 0:q.url)||void 0,alt:j.name}),e.jsx(Ia,{className:"bg-primary/10",children:e.jsx(Xe,{className:"h-8 w-8 text-primary"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-lg font-bold truncate",children:j.name}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:j.organization_email||j.login_email}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded-full font-medium ${d.color}`,children:[d.text==="Active"?e.jsx(ps,{className:"h-3 w-3"}):d.text==="Expired"?e.jsx(oa,{className:"h-3 w-3"}):e.jsx(zs,{className:"h-3 w-3"}),d.text]}),((re=(U=j.subscription)==null?void 0:U.package)==null?void 0:re.name)&&e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary font-medium",children:j.subscription.package.name}),((G=(te=j.subscription)==null?void 0:te.applied_coupon)==null?void 0:G.code)&&e.jsxs("span",{className:"px-2 py-0.5 text-xs rounded-full bg-amber-100 text-amber-800 font-medium inline-flex items-center gap-1",children:[e.jsx(Da,{className:"h-3 w-3"}),j.subscription.applied_coupon.code]}),L.hasDiscount&&e.jsxs("span",{className:"px-2 py-0.5 text-xs rounded-full bg-green-100 text-green-800 font-medium",children:["Paid ",Cs(L.paidAmount)]})]})]})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-4 space-y-3 mt-4",children:[e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-2 text-muted-foreground uppercase tracking-wide",children:[e.jsx(Xe,{className:"h-4 w-4"})," Organisation"]}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Registration No."}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.registration_number||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Organization Email"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.organization_email||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Login Email"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.login_email||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Contact"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.contact_number||"-"})]})]})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-4 space-y-3 my-4",children:[e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-2 text-muted-foreground uppercase tracking-wide",children:[e.jsx(Gs,{className:"h-4 w-4"})," Owner / Admin"]}),j.owner?e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Name"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:[j.owner.first_name,j.owner.last_name].filter(
2Boolean).join(" ")||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Email"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.owner.email||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Phone"}),e.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:j.owner.phone||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gs,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium w-24 shrink-0",children:"Username"}),e.jsx("span",{className:"text-muted-foreground font-mono text-xs bg-muted px-1.5 py-0.5 rounded truncate flex-1 min-w-0",children:j.owner.username||"-"})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No owner information available"})]}),j.subscription&&e.jsxs("div",{className:"md:col-span-2 rounded-xl border bg-card p-4 space-y-3",children:[e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-2 text-muted-foreground uppercase tracking-wide",children:[e.jsx($s,{className:"h-4 w-4"})," Subscription"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Package"}),e.jsx("p",{className:"font-semibold text-sm",children:((w=j.subscription.package)==null?void 0:w.name)||"-"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Status"}),e.jsx("span",{className:`inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full ${d.color}`,children:d.text})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(gs,{className:"h-3 w-3"})," Max Employees"]}),e.jsx("p",{className:"font-semibold text-sm flex items-center gap-1",children:_t(j.subscription)?e.jsxs("span",{children:[e.jsx("span",{className:"text-base",children:j.active_employee_count??0}),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["/",_t(j.subscription)]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground font-normal",children:"active"})]}):e.jsxs(e.Fragment,{children:[e.jsx(_i,{className:"h-4 w-4"})," Unlimited"]})}),j.total_employee_count!=null&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[j.total_employee_count," total employees"]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Rs,{className:"h-3 w-3"})," Starts"]}),e.jsx("p",{className:"font-semibold text-sm",children:Va(j.subscription.starts_at)})]}),j.subscription.expires_at&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Rs,{className:"h-3 w-3"})," Expires"]}),e.jsx("p",{className:"font-semibold text-sm",children:Va(j.subscription.expires_at)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Al,{className:"h-3 w-3"})," Free Trial"]}),e.jsx("p",{className:"font-semibold text-sm",children:(ue=(Y=j==null?void 0:j.subscription)==null?void 0:Y.package)!=null&&ue.is_free?"N/A":j.subscription.free_trial_days??((J=j.subscription.package)==null?void 0:J.free_trial_days)?`${j.subscription.free_trial_days??((ge=j.subscription.package)==null?void 0:ge.free_trial_days)} days`:"None"})]}),(j.subscription.applied_coupon||L.hasDiscount)&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 sm:col-span-2 lg:col-span-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-2 flex items-center gap-1",children:[e.jsx(Da,{className:"h-3 w-3"}),(he=j.subscription.applied_coupon)!=null&&he.code?"Applied Coupon & Paid Amount":"Discounted Paid Amount"]}),((me=j.subscription.applied_coupon)==null?void 0:me.code)&&e.jsx("p",{className:"font-semibold text-sm font-mono",children:j.subscription.applied_coupon.code}),((Z=j.subscription.applied_coupon)==null?void 0:Z.name)&&j.subscription.applied_coupon.name!==j.subscription.applied_coupon.code&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:j.subscription.applied_coupon.name}),L.hasDiscount&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-3 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[L.periodLabel," catalogue price"]}),e.jsx("p",{className:"font-medium line-through text-muted-foreground",children:Cs(L.originalAmount)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paid amount"}),e.jsx("p",{className:"font-semibold text-green-700",children:Cs(L.paidAmount)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Discount applied"}),e.jsx("p",{className:"font-medium text-amber-700",children:Cs(L.discountAmount)})]})]}),((ne=j.subscription.applied_coupon)==null?void 0:ne.applied_at)&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Applied ",Va(j.subscription.applied_coupon.applied_at)]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Monthly Price"}),L.hasDiscount&&I?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-through",children:Cs((_e=j.subscription.package)==null?void 0:_e.price_monthly)}),e.jsxs("p",{className:"font-semibold text-sm text-green-700",children:["Paid ",Cs(L.paidAmount)]})]}):e.jsx("p",{className:"font-semibold text-sm",children:Cs((qe=j.subscription.package)==null?void 0:qe.price_monthly)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Yearly Price"}),L.hasDiscount&&!I?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-through",children:Cs((fe=j.subscription.package)==null?void 0:fe.price_yearly)}),e.jsxs("p",{className:"font-semibold text-sm text-green-700",children:["Paid ",Cs(L.paidAmount)]})]}):e.jsx("p",{className:"font-semibold text-sm",children:Cs((Qe=j.subscription.package)==null?void 0:Qe.price_yearly)})]})]})]})]})]})]})})})]},j.id||S)}):e.jsx(le,{children:e.jsx(C,{colSpan:8,className:"text-center p-40 text-muted-foreground",children:a("organizations.noData","No organizations foun
2d.")})})})]})}),O>1&&e.jsx("div",{className:"mt-6 flex justify-center sm:justify-end px-4",children:e.jsx(ot,{children:e.jsxs(dt,{children:[e.jsx(Ns,{children:e.jsx(mt,{href:"#",onClick:j=>{j.preventDefault(),t(S=>Math.max(S-1,1))},className:s===1?"pointer-events-none opacity-50":""})}),Array.from({length:O}).map((j,S)=>{const d=S+1,L=d===1||d===O||d>=s-1&&d<=s+1,I=d===s-2&&d>2,B=d===s+2&&d<O-1;return I||B?e.jsx(Ns,{children:e.jsx(Pl,{})},`ellipsis-${S}`):L?e.jsx(Ns,{children:e.jsx(ut,{href:"#",isActive:s===d,onClick:y=>{y.preventDefault(),t(d)},children:d})},d):null}),e.jsx(Ns,{children:e.jsx(xt,{href:"#",onClick:j=>{j.preventDefault(),t(S=>Math.min(S+1,O))},className:s===O?"pointer-events-none opacity-50":""})})]})})})]}),e.jsx(Tl,{open:i,onOpenChange:c,children:e.jsxs(Fl,{side:"right",className:"w-full sm:max-w-md overflow-y-auto",children:[e.jsxs(zl,{children:[e.jsxs(El,{className:"flex items-center gap-2",children:[e.jsx(fa,{className:"h-4 w-4"})," Filters"]}),e.jsx(Dl,{children:"Filter by organization details and subscription data."})]}),e.jsxs("div",{className:"space-y-5 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Search"}),e.jsx(E,{placeholder:"Name, email, phone, registration, package...",value:r,onChange:j=>{t(1),o(j.target.value)}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Organization Status"}),e.jsxs(ke,{value:l,onValueChange:j=>{t(1),_(j)},children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"All statuses"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All"}),e.jsx(X,{value:"active",children:"Active"}),e.jsx(X,{value:"inactive",children:"Inactive"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Subscription Status"}),e.jsxs(ke,{value:h,onValueChange:j=>{t(1),N(j)},children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"All subscription statuses"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All"}),e.jsx(X,{value:"active",children:"Active"}),e.jsx(X,{value:"expiring_soon",children:"Expiring Soon"}),e.jsx(X,{value:"expired",children:"Expired"}),e.jsx(X,{value:"suspended",children:"Suspended"}),e.jsx(X,{value:"free_plan",children:"Free Plan"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Package Name"}),e.jsx(E,{placeholder:"Search package...",value:g,onChange:j=>{t(1),b(j.target.value)}})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(u,{variant:"outline",className:"flex-1",onClick:()=>{t(1),o(""),_("all"),N("all"),b("")},children:"Clear"}),e.jsx(u,{className:"flex-1",onClick:()=>c(!1),children:"Done"})]})]})]})})]})})}const Ys=fs("token"),hd=He.injectEndpoints({endpoints:a=>({getAllFeatures:a.query({query:()=>({url:"/subscription-features",method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),transformResponse:s=>(console.log("Raw features response:",s),s&&s.data&&Array.isArray(s.data)?s.data:Array.isArray(s)?s:[]),providesTags:["subscription-features"]}),getModuleFeatureTree:a.query({query:()=>({url:"/modules/feature-tree",method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),transformResponse:s=>(console.log("Raw module feature tree response:",s),s&&s.data&&Array.isArray(s.data)?s.data:Array.isArray(s)?s:[]),providesTags:["module-feature-tree"]}),getPackageEditTree:a.query({query:s=>({url:`/modules/feature-tree-for-package${s?`?package_id=${s}`:""}`,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),transformResponse:s=>(console.log("Raw package edit tree response:",s),s&&s.data&&Array.isArray(s.data)?s.data:Array.isArray(s)?s:[]),providesTags:["module-feature-tree"]}),getMenuFeatureTree:a.query({query:()=>({url:"/modules/menu-tree",method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),transformResponse:s=>(console.log("Raw menu feature tree response:",s),s&&s.data&&Array.isArray(s.data)?s.data:Array.isArray(s)?s:[]),providesTags:["menu-feature-tree"]}),getAllSubscriptions:a.query({query:()=>({url:"/subscription-packages",method:"GET",headers:{"Content-Type":"application/json"}}),transformResponse:s=>(console.log("Raw subscription packages response:",s),s&&s.data&&Array.isArray(s.data)?s.data:Array.isArray(s)?s:[]),providesTags:["subscription"]}),addSubscription:a.mutation({query:s=>({url:"/admin/subscription-packages",method:"POST",data:s,headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),invalidatesTags:["subscription"]}),editSubscription:a.mutation({query:({id:s,subscriptionData:t})=>({url:`/admin/subscription-packages/${s}`,method:"PUT",data:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),invalidatesTags:["subscription"]}),updatePackagePrice:a.mutation({query:({id:s,...t})=>({url:`/admin/subscription-packages/${s}/price`,method:"PUT",data:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),invalidatesTags:["subscription"]}),deleteSubscription:a.mutation({query:s=>({url:`/admin/subscription-packages/${s}`,method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ys}`}}),invalidatesTags:["subscription"]})})}),{useGetModuleFeatureTreeQuery:pd,useGetAllSubscriptionsQuery:on,useAddSubscriptionMutation:gd,useEditSubscriptionMutation:jd,useUpdatePackagePriceMutation:fd,useDeleteSubscriptionMutation:vd}=hd,yd=lt({name:Ke().min(1,"Organization name is required").max(255,"Organization name must be less than 255 characters"),registration_number:Ke().min(1,"Registration number is required").max(50,"Registration number must be less than 50 characters"),organization_email:Ke().email("Valid organization email is required").max(255,"Email must be less than 255 characters").optional().or(et("")),login_email:Ke().min(1,"Login email is required").email("Valid login email is required").max(255,"Email must be less than 255 characters"),username:Ke().min(3,"Username must be at least 3 characters").max(50,"Username must be less than 50 characters").regex(/^[a-z0-9_-]+$/,"Username must contain only lowercase letters, numbers, hyphens, and underscores"),contact_number:Ke().min(1,"Contact number is required").max(15,"Contact number must be less than 15 characters"),coupon_code:Ke().optional().or(et("")),password:Ke().min(6,"Password must be at least 6 characters"),employee_first_name:Ke().min(1,"Employee first name is required").max(255,"First Name must be less than 255 characters"),employee_last_name:Ke().min(1,"Employee last name is required").max(255,"Last Name must be less than 255 characters"),employee_position:Ke().min(1,"Employee position is required").max(255,"Employee position must be less than 255 characters"),subscription_package_id:Ke().min(1,"Subscription package is required"),period:jt(["monthly","yearly"],{required_error:"Billing period is required"}).optional(),payment_method:jt(["stripe","bank_transfer","cash","cheque"],{required_error:"Payment method is required"}).optional(),payment_status:jt(["pending","paid"],{required_error:"Payment status is required"}).optional()}
2),Nd=[{value:"stripe",label:"Stripe (Online)",icon:$s,description:"Online card payment"},{value:"bank_transfer",label:"Bank Transfer",icon:Xe,description:"Direct bank transfer"},{value:"cash",label:"Cash",icon:Vt,description:"Cash payment"},{value:"cheque",label:"Cheque",icon:wi,description:"Payment by cheque"}],bd=[{value:"pending",label:"Pending",icon:zs,color:"bg-amber-100 text-amber-700 border-amber-200"},{value:"paid",label:"Paid",icon:ps,color:"bg-green-100 text-green-700 border-green-200"}];function _d(){const a=Vs(),[s,{isLoading:t}]=dd(),[n]=Ll(),{data:i=[],isLoading:c,error:r}=on();pe.useEffect(()=>{console.log("Subscription packages:",i),console.log("Packages error:",r)},[i,r]);const[o,l]=pe.useState(null),[_,h]=pe.useState("monthly"),[N,g]=pe.useState("stripe"),[b,P]=pe.useState("pending"),z=pe.useMemo(()=>i.filter(J=>{const ge=Array.isArray(J.feature_keys)?J.feature_keys.length:0,he=Array.isArray(J.features)?J.features.length:0,me=Array.isArray(J.modules)?J.modules.length:0;return ge>0||he>0||me>0}),[i]),p=i.length>0&&z.length<i.length,M=(o==null?void 0:o.is_free)===!0,{register:A,handleSubmit:O,setValue:k,watch:j,formState:{errors:S}}=Xa({resolver:Za(yd),defaultValues:{period:"monthly",payment_method:"stripe",payment_status:"pending"}}),d=j("subscription_package_id");pe.useEffect(()=>{if(!d){l(null);return}const J=z.find(ge=>ge.id===d);l(J??null)},[z,d]);const L=J=>{const ge=new Date;return J==="yearly"?Ol(ge,1):Rl(ge,1)},I=j("coupon_code"),[B,y]=pe.useState(null),[F,K]=pe.useState(!1),[q,U]=pe.useState(null),te=o?((J,ge)=>{const he=Number(ge==="yearly"?J.price_yearly:J.price_monthly);return J.discount_percentage&&J.discount_percentage>0&&(!J.discount_expires_at||new Date(J.discount_expires_at)>new Date)&&(ge==="monthly"?J.discount_applies_to_monthly!==!1:J.discount_applies_to_yearly===!0)?Math.max(0,he-he*(J.discount_percentage??0)/100):he})(o,_):0,G=()=>{const J=Number(te??0);if(!B)return J;const ge=Number(B.final_amount??NaN);if(!Number.isNaN(ge))return Math.max(0,ge);const he=Number(B.discount_amount??0),me=Number(B.discount_value??0);let Z=J;return B.type==="percentage"?Z-=Z*me/100:Z-=he,Math.max(0,Z)};pe.useEffect(()=>{y(null),U(null)},[I,d,_]);const w=async()=>{var he;if(!o){v.error("Please select a subscription package first.");return}const J=I==null?void 0:I.trim().toUpperCase();if(!J){v.error("Enter a coupon code to apply.");return}U(null),K(!0),y(null);const ge=(o==null?void 0:o.id)??d;if(!ge){v.error("Please select a valid subscription package first."),K(!1);return}try{const me=await n({code:J,packageId:ge,period:_,amount:te}).unwrap();if(!me.success){const Z=me.message||"Invalid coupon code.";U(Z),v.error(Z);return}y({coupon_code:J,coupon_name:me.data.coupon_name,type:me.data.type,discount_value:Number(me.data.discount_value??0),original_amount:Number(me.data.original_amount??te),discount_amount:Number(me.data.discount_amount??0),final_amount:Number(me.data.final_amount??0),period:me.data.period,package_id:me.data.package_id}),v.success(`Coupon applied: saved £${Number(me.data.discount_amount).toFixed(2)}`)}catch(me){console.error("Coupon validation failed:",me);const Z=((he=me==null?void 0:me.data)==null?void 0:he.message)||(me==null?void 0:me.message)||"Failed to validate coupon.";U(Z),v.error(Z)}finally{K(!1)}},Y=L(_),ue=async J=>{var ge,he,me;try{const Z=L(J.period??"monthly"),ne={...J,organization_email:J.organization_email||void 0,expiry_date:us(Z,"yyyy-MM-dd"),coupon_code:(B==null?void 0:B.coupon_code)||((ge=J.coupon_code)==null?void 0:ge.trim().toUpperCase())||void 0};M&&(delete ne.payment_method,delete ne.payment_status),await s(ne).unwrap(),v.success("Organization created successfully!"),a("/admin-dashboard/organizations")}catch(Z){const ne=((he=Z==null?void 0:Z.data)==null?void 0:he.message)||"Failed to create organization",_e=(me=Z==null?void 0:Z.data)==null?void 0:me.errors;if(_e&&typeof _e=="object"){const qe=Object.values(_e).flat().join(", ");v.error(`${ne}: ${qe}`)}else v.error(ne)}};return e.jsx(ye,{title:"Organization",subtitle:"Add Organization",link:"/admin-dashboard/organizations",children:e.jsx("div",{className:"p-4 w-full",children:e.jsxs("form",{onSubmit:O(ue),className:"space-y-6",children:[e.jsxs(hs,{className:"w-full shadow-lg rounded-xl border border-muted",children:[e.jsx(se,{className:"pb-4 bg-gradient-to-r from-primary/5 to-primary/10 rounded-t-xl pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Xe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(ae,{className:"text-lg font-semibold",children:"Organization Information"}),e.jsx(je,{children:"Basic details about the organization"})]})]})}),e.jsx(Q,{className:"pb-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"name",className:"flex items-center gap-2",children:[e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground"}),"Organization Name *"]}),e.jsx(E,{id:"name",placeholder:"Enter organization name",...A("name"),className:"h-11"}),S.name&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.name.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"registration_number",className:"flex items-center gap-2",children:[e.jsx(wi,{className:"h-4 w-4 text-muted-foreground"}),"Registration Number *"]}),e.jsx(E,{id:"registration_number",placeholder:"Enter registration number",...A("registration_number"),className:"h-11"}),S.registration_number&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.registration_number.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"organization_email",className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground"}),"Organization Email"]}),e.jsx(E,{id:"organization_email",type:"email",placeholder:"Enter organization email",...A("organization_email"),className:"h-11"}),S.organization_email&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.organization_email.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"contact_number",className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4 text-muted-foreground"}),"Contact Number *"]}),e.jsx(E,{id:"contact_number",placeholder:"Enter contact number",...A("contact_number"),className:"h-11"}),S.contact_number&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.contact_number.message]})]})]})})]}),e.jsxs(hs,{className:"w-full shadow-lg rounded-xl border border-muted",children:[e.jsx(se,{className:"pb-4 bg-gradient-to-r from-blue-500/5 to-blue-500/10 rounded-t-xl pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-500/10 rounded-lg",children:e.jsx(Gs,{className:"h-5 w-5 text-blue-500"})}),e.jsxs("div",{children:[e.jsx(ae,{className:"text-lg font-semibold",children:"Admin User Details"}),e.jsx(je,{children:"Primary administrator for this organization"})]})]})}),e.jsx(Q,{className:"pb-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"employee_first_name",className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-4 w-4 text-muted-foreground"}),"First Name *"]}),e.jsx(E,{id:"employee_first_name",placeholder:"Enter first name",...A("employee_first_name"),className:"h-11"}),S.employee_first_name&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.employee_first_name.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"employee_last_name",className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-4 w-4 text-muted-foreground"}),"Last Name *"]}),e.jsx(E,{id:"employee_last_name",placeholder:"Enter last name",...A("employee_last_name"),className:"h-11"}),S.employee_last_name&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.employee_last_name.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"employee_position",className:"flex items-center gap-2",children:[e.jsx(Ml,{className:"h-4 w-4 text-muted-foreground"}),"Position *"]}),e.jsx(E,{id:"employee_position",placeholder:"Enter position",...A("employee_position"),className:"h-11"}),S.employee_position&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.employee_position.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"login_email",className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground"}),"Login Email *"]}),e.jsx(E,{id:"login_email",type:"email",placeholder:"Enter login email",...A("login_email"),className:"h-11"}),S.login_email&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.login_email.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"username",className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-4 w-4 text-muted-foreground"}),"Username *"]}),e.jsx(E,{id:"username",placeholder:"Enter username",...A("username"),className:"h-11"}),S.username&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.username.message]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"password",className:"flex items-center gap-2",children:[e.jsx(Fa,{className:"h-4 w-4 text-muted-foreground"}),"Password *"]}),e.jsx(E,{id:"password",type:"password",placeholder:"Enter password",...A("password"),className:"h-11"}),S.password&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.password.message]})]})]})})]}),e.jsxs(hs,{className:"w-full shadow-lg rounded-xl border border-muted",children:[e.jsx(se,{className:"pb-4 bg-gradient-to-r from-green-500/5 to-green-500/10 rounded-t-xl pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-500/10 rounded-lg",children:e.jsx(ia,{className:"h-5 w-5 text-green-500"})}),e.jsxs("div",{children:[e.jsx(ae,{className:"text-lg font-semibold",children:"Subscription & Payment"}),e.jsx(je,{children:"Select subscription plan and payment details"})]})]})}),e.jsxs(Q,{className:"pb-4 space-y-6",children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(x,{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(ia,{className:"h-4 w-4 text-muted-foreground"}),"Subscription Package *"]}),e.jsxs(ke,{onValueChange:J=>{k("subscription_package_id",J);const ge=z.find(he=>he.id===J);l(ge||null)}
2,disabled:c,children:[e.jsx(Se,{className:"h-11",children:e.jsx(Ae,{placeholder:c?"Loading packages...":"Select a subscription package"})}),e.jsx(Pe,{children:z.length>0?z.filter(J=>J.id&&typeof J.id=="string"&&J.id.trim().length>0).map(J=>e.jsx(X,{value:J.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:J.name}),e.jsxs(ee,{variant:"secondary",className:"text-xs",children:["$",J.price_monthly,"/mo"]})]})},J.id)):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",children:r?"Error loading packages":"No configured packages available"})})]}),p&&e.jsx("p",{className:"text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded-md px-3 py-2",children:"Some packages are hidden because they have no configured features yet."}),S.subscription_package_id&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.subscription_package_id.message]})]}),o&&e.jsxs("div",{className:"p-4 bg-gradient-to-br from-primary/5 to-primary/10 rounded-xl border border-primary/20",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-lg",children:o.name}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:o.description})]}),e.jsx(ee,{className:"bg-primary/10 text-primary border-primary/20",children:"Selected"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mt-4",children:[e.jsxs("div",{className:"text-center p-3 bg-background rounded-lg border",children:[e.jsxs("p",{className:"text-2xl font-bold text-primary",children:["$",o.price_monthly]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"per month"})]}),e.jsxs("div",{className:"text-center p-3 bg-background rounded-lg border",children:[e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:["$",o.price_yearly]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"per year"})]}),e.jsxs("div",{className:"text-center p-3 bg-background rounded-lg border",children:[e.jsx("p",{className:"text-2xl font-bold",children:o.max_employees||"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Max Employees"})]})]})]}),e.jsx(ra,{}),!M&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(x,{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(Rs,{className:"h-4 w-4 text-muted-foreground"}),"Billing Period *"]}),e.jsxs(ql,{value:_,className:"grid grid-cols-2 gap-4",onValueChange:J=>{k("period",J),h(J)},children:[e.jsxs("div",{className:`relative flex items-center space-x-3 rounded-xl border-2 p-4 cursor-pointer transition-all ${_==="monthly"?"border-primary bg-primary/5":"border-muted hover:border-muted-foreground/30"}`,children:[e.jsx(wn,{value:"monthly",id:"monthly"}),e.jsxs(x,{htmlFor:"monthly",className:"flex-1 cursor-pointer",children:[e.jsx("div",{className:"font-semibold",children:"Monthly"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Billed every month"}),o&&e.jsxs("div",{className:"mt-2 text-lg font-bold text-primary",children:["$",o.price_monthly,"/mo"]})]})]}),e.jsxs("div",{className:`relative flex items-center space-x-3 rounded-xl border-2 p-4 cursor-pointer transition-all ${_==="yearly"?"border-primary bg-primary/5":"border-muted hover:border-muted-foreground/30"}`,children:[e.jsx(wn,{value:"yearly",id:"yearly"}),e.jsxs(x,{htmlFor:"yearly",className:"flex-1 cursor-pointer",children:[e.jsxs("div",{className:"font-semibold flex items-center gap-2",children:["Yearly",e.jsx(ee,{variant:"secondary",className:"bg-green-100 text-green-700 text-xs",children:"Save up to 20%"})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Billed annually"}),o&&e.jsxs("div",{className:"mt-2 text-lg font-bold text-green-600",children:["$",o.price_yearly,"/yr"]})]})]})]}),S.period&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.period.message]})]}),e.jsx("div",{className:"p-4 bg-blue-50 dark:bg-blue-950/30 rounded-xl border border-blue-200 dark:border-blue-900",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dar
2k:bg-blue-900 rounded-lg",children:e.jsx(Rs,{className:"h-5 w-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:M?"Subscription does not expire (free plan)":"Subscription will expire on:"}),e.jsx("p",{className:"text-lg font-bold text-blue-600 dark:text-blue-400",children:M?"No expiry (free plan)":us(Y,"MMMM dd, yyyy")})]}),!M&&e.jsx("div",{className:"ml-auto",children:e.jsx(ee,{variant:"outline",className:"border-blue-300 text-blue-700 dark:text-blue-300",children:_==="yearly"?"1 Year":"1 Month"})})]})}),e.jsx(ra,{}),!M&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(x,{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx($s,{className:"h-4 w-4 text-muted-foreground"}),"Payment Method *"]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Nd.map(J=>e.jsxs("div",{className:`relative flex flex-col items-center p-4 rounded-xl border-2 cursor-pointer transition-all ${N===J.value?"border-primary bg-primary/5":"border-muted hover:border-muted-foreground/30"}`,onClick:()=>{k("payment_method",J.value),g(J.value)},children:[e.jsx(J.icon,{className:`h-6 w-6 mb-2 ${N===J.value?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"text-sm font-medium text-center",children:J.label}),e.jsx("span",{className:"text-xs text-muted-foreground text-center mt-1",children:J.description}),N===J.value&&e.jsx(ps,{className:"absolute top-2 right-2 h-4 w-4 text-primary"})]},J.value))}),S.payment_method&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.payment_method.message]})]}),e.jsx(ra,{}),!M&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(x,{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(ps,{className:"h-4 w-4 text-muted-foreground"}),"Payment Status *"]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:bd.map(J=>e.jsxs("div",{className:`relative flex items-center gap-3 p-4 rounded-xl border-2 cursor-pointer transition-all ${b===J.value?`border-primary ${J.color}`:"border-muted hover:border-muted-foreground/30 bg-background"}`,onClick:()=>{k("payment_status",J.value),P(J.value)},children:[e.jsx(J.icon,{className:"h-5 w-5"}),e.jsx("span",{className:"font-medium",children:J.label}),b===J.value&&e.jsx(ps,{className:"absolute top-2 right-2 h-4 w-4"})]},J.value))}),S.payment_status&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),S.payment_status.message]}),b==="pending"&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-950/30 rounded-lg border border-amber-200 dark:border-amber-800",children:[e.jsx(Ci,{className:"h-4 w-4 text-amber-600 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:"Organization will be created but access may be limited until payment is confirmed."})]})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"coupon_code",className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(la,{className:"h-4 w-4 text-muted-foreground"}),"Coupon Code"]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(E,{id:"coupon_code",placeholder:"Enter coupon code",...A("coupon_code"),className:"h-11 flex-1"}),e.jsx(u,{type:"button",className:"min-w-[180px]",onClick:w,disabled:!o||F,children:F?"Validating...":"Apply coupon"})]}),B&&e.jsxs("div",{className:"rounded-xl border border-green-200 bg-green-50 p-3 text-sm text-green-900",children:[e.jsxs("div",{className:"font-medium",children:[B.coupon_code," applied"]}),e.jsxs("div",{children:["Saved ",e.jsxs("span",{className:"font-semibold",children:["£",Number(B.discount_amount).toFixed(2)]})]}),e.jsxs("div",{children:["New price: ",e.jsxs("span",{className:"font-semibold",children:["£",G().toFixed(2)]})]})]}),q&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(Oe,{className:"h-3 w-3"}),q]})]}),o&&e.jsx(W,{className:"w-full shadow-lg rounded-xl border border-green-200 dark:border-green-900 bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-950/30 dark:to-emerald-950/30",children:e.jsx(Q,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Amount"}),e.jsx("div",{className:"space-y-1",children:M?e.jsx("p",{className:"text-3xl font-bold text-green-600",children:"Free"}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-3xl font-bold text-green-600",children:["$",G().toFixed(2),e.jsxs("span",{className:"text-base font-normal text-muted-foreground",children:["/",_==="yearly"?"year":"month"]})]}),(B||(o==null?void 0:o.discount_percentage))&&e.jsx("p",{className:"text-sm text-muted-foreground",children:B?e.jsxs(e.Fragment,{children:["Applied coupon ",e.jsx("span",{className:"font-semibold",children:B.coupon_code}),", saved £",Number(B.discount_amount).toFixed(2)]}):e.jsx(e.Fragment,{children:"Package discount applied"})})]})})]}),e.jsxs("div",{className:"space-y-1 text-right",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Valid Until"}),e.jsx("p",{className:"text-lg font-semibold",children:M?"No expiry":us(Y,"MMM dd, yyyy")})]}),e.jsx(u,{type:"submit",size:"lg",className:"w-full md:w-auto min-w-[200px]",disabled:t,children:t?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-4 w-4 mr-2"}),"Create Organization"]})})]})})}),!o&&e.jsx("div",{className:"flex justify-end",children:e.jsx(u,{type:"submit",size:"lg",className:"min-w-[200px]",disabled:t,children:t?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-4 w-4 mr-2"}),"Create Organization"]})})})]})})})}const wt=a=>{if(!a)return"-";const s=new Date(a);return Number.isNaN(s.getTime())?a:s.toLocaleDateString()};function wd(){const a=Vs(),[s,t]=m.useState(1),{data:n,isLoading:i,refetch:c}=cn({page:s,per_page:15,status:"all",license_status:"cancelled"}),r=(n==null?void 0:n.data)||[],o=(n==null?void 0:n.last_page)||1;return e.jsx(ye,{title:"Cancelled Subscriptions",subtitle:"Organizations that have cancelled their subscription (auto-renewal turned off)",link:"/admin-dashboard/organizations",children:e.jsxs("div",{className:"p-4 lg:p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(u,{variant:"ghost",size:"sm",onClick:()=>a("/admin-dashboard/organizations"),children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),"Back to Organizations"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>c(),children:[e.jsx(Es,{className:"h-4 w-4 mr-2"}),"Refresh"]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Who Cancelled"}),e.jsx(je,{children:"These organizations turned off auto-renewal. They keep access until their current period ends, then billing stops."})]}),e.jsxs(Q,{children:[i?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((l,_)=>e.jsx(js,{className:"h-16 w-full"},_))}):r.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Xe,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"No Cancelled Subscriptions"}),e.jsx("p",{className:"text-sm mt-1",children:"No organization has cancelled their subscription right now."})]}):e.jsx("div",{className:"rounded-lg border",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Contact"}),e.jsx(T,{children:"Package"}),e.jsx(T,{children:"Access Until"}),e.jsx(T,{className:"text-right",children:"Details"})]})}),e.jsx(Ue,{children:r.map(l=>{var _,h,N,g,b,P,z,p,M,A,O,k,j,S,d,L,I,B;return e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[(_=l.logo)!=null&&_.url?e.jsx("img",{src:va(l.logo.url)||void 0,alt:l.name,className:"h-10 w-10 rounded-lg object-cover"}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-muted flex items-center justify-center",children:e.jsx(Xe,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"font-medium",children:l.name})]})}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-1 text-sm",children:[(l.organization_email||l.login_email)&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(ms,{className:"h-3 w-3"}),l.organization_email||l.login_email]}),l.contact_number&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Is,{className:"h-3 w-3"}),l.contact_number]})]})}),e.jsx(C,{children:((N=(h=l.subscription)==null?void 0:h.package)==null?void 0:N.name)||"-"}),e.jsx(C,{children:wt((g=l.subscription)==null?void 0:g.expires_at)}),e.jsx(C,{className:"text-right",children:e.jsxs(Fe,{children:[e.jsx(di,{asChild:!0,children:e.jsx(u,{variant:"ghost",size:"sm",title:"View Details",children:e.jsx(Fs,{className:"h-4 w-4"})})}),e.jsxs(ze,{className:"max-w-lg",children:[e.jsx(Ee,{children:e.jsxs(De,{className:"flex items-center gap-3 text-xl",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Xe,{className:"h-5 w-5 text-primary"})}),l.name]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-muted/40 rounded-xl border",children:[e.jsxs(Oa,{className:"h-14 w-14 ring-2 ring-primary/20",children:[e.jsx(Ra,{src:va((b=l.logo)==null?void 0:b.url)||void 0,alt:l.name}),e.jsx(Ia,{className:"bg-primary/10",children:e.jsx(Xe,{className:"h-7 w-7 text-primary"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-bold truncate",children:l.name}),(l.organization_email||l.login_email)&&e.jsxs("p",{className:"text-sm text-muted-foreground truncate flex items-center gap-1",children:[e.jsx(ms,{className:"h-3 w-3"}),l.organization_email||l.login_email]}),l.contact_number&&e.jsxs("p",{className:"text-sm text-muted-foreground truncate flex items-center gap-1",children:[e.jsx(Is,{className:"h-3 w-3"}),l.contact_number]})]})]}),l.owner&&(l.owner.first_name||l.owner.email)&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Gs,{className:"h-3 w-3"})," Account Owner"]}),e.jsx("p",{className:"font-semibold text-sm",children:[l.owner.first_name,l.owner.last_name].filter(
2Boolean).join(" ")||"-"}),l.owner.email&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.owner.email})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx($s,{className:"h-3 w-3"})," Package"]}),e.jsx("p",{className:"font-semibold text-sm",children:((z=(P=l.subscription)==null?void 0:P.package)==null?void 0:z.name)||"-"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Rs,{className:"h-3 w-3"})," Access Until"]}),e.jsx("p",{className:"font-semibold text-sm",children:wt((p=l.subscription)==null?void 0:p.expires_at)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Monthly Price"}),e.jsx("p",{className:"font-semibold text-sm",children:Cs((A=(M=l.subscription)==null?void 0:M.package)==null?void 0:A.price_monthly)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Yearly Price"}),e.jsx("p",{className:"font-semibold text-sm",children:Cs((k=(O=l.subscription)==null?void 0:O.package)==null?void 0:k.price_yearly)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(gs,{className:"h-3 w-3"})," Employees"]}),e.jsxs("p",{className:"font-semibold text-sm flex items-center gap-1",children:[l.active_employee_count??0,e.jsxs("span",{className:"text-muted-foreground font-normal",children:["/",((S=(j=l.subscription)==null?void 0:j.package)==null?void 0:S.max_employees)??e.jsx(_i,{className:"h-3 w-3 inline"})]})]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Billing Frequency"}),e.jsx("p",{className:"font-semibold text-sm capitalize",children:((d=l.subscription)==null?void 0:d.payment_frequency)||"-"})]})]}),((I=(L=l.subscription)==null?void 0:L.applied_coupon)==null?void 0:I.code)&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1 flex items-center gap-1",children:[e.jsx(Da,{className:"h-3 w-3"})," Applied Coupon"]}),e.jsx("p",{className:"font-semibold text-sm font-mono",children:l.subscription.applied_coupon.code})]}),e.jsxs("div",{className:"text-sm text-muted-foreground bg-orange-50 border border-orange-200 rounded-lg p-3",children:["Auto-renewal is turned off. This organization keeps access until"," ",e.jsx("strong",{children:wt((B=l.subscription)==null?void 0:B.expires_at)}),", then billing stops."]})]})]})]})})]},l.id)})})]})}),o>1&&e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:s<=1,onClick:()=>t(l=>Math.max(1,l-1)),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground self-center",children:["Page ",s," of ",o]}),e.jsx(u,{variant:"outline",size:"sm",disabled:s>=o,onClick:()=>t(l=>Math.min(o,l+1)),children:"Next"})]})]})]})]})})}const Cd=He.injectEndpoints({endpoints:a=>({getPricingComparisonMatrix:a.query({query:()=>({url:"/admin/marketing-pricing-feature-matrix",method:"GET"}),providesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),createPricingComparisonGroup:a.mutation({query:s=>({url:"/admin/marketing-pricing-feature-groups",method:"POST",data:s}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),updatePricingComparisonGroup:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-pricing-feature-groups/${s}`,method:"PUT",data:t}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),deletePricingComparisonGroup:a.mutation({query:s=>({url:`/admin/marketing-pricing-feature-groups/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),createPricingComparisonFeature:a.mutation({query:s=>({url:"/admin/marketing-pricing-features",method:"POST",data:s}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),updatePricingComparisonFeature:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-pricing-features/${s}`,method:"PUT",data:t}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),deletePricingComparisonFeature:a.mutation({query:s=>({url:`/admin/marketing-pricing-features/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]}),syncPricingComparisonFeaturePackages:a.mutation({query:({featureId:s,package_ids:t})=>({url:`/admin/marketing-pricing-features/${s}/packages`,method:"PUT",data:{package_ids:t}}),invalidatesTags:[{type:"marketing-pricing-comparison",id:"MATRIX"}]})})}),{useGetPricingComparisonMatrixQuery:kd,useCreatePricingComparisonGroupMutation:Sd,useUpdatePricingComparisonGroupMutation:Ad,useDeletePricingComparisonGroupMutation:Pd,useCreatePricingComparisonFeatureMutation:Td,useUpd
2atePricingComparisonFeatureMutation:Fd,useDeletePricingComparisonFeatureMutation:zd,useSyncPricingComparisonFeaturePackagesMutation:Ed}=Cd,Gn={name:"",icon:"",sort_order:0,is_active:!0},Vn={group_id:"",name:"",tooltip:"",sort_order:0,is_active:!0,package_ids:[]};function Dd(a,s){return s?"Free":`£${Number(a??0).toFixed(2)}/mo`}function Ld(a){return a==null?"Unlimited":`Up to ${a}`}function Oi(){var he,me;const{data:a,isLoading:s}=kd(),[t,{isLoading:n}]=Sd(),[i,{isLoading:c}]=Ad(),[r,{isLoading:o}]=Pd(),[l,{isLoading:_}]=Td(),[h,{isLoading:N}]=Fd(),[g,{isLoading:b}]=zd(),[P,{isLoading:z}]=Ed(),[p,M]=m.useState(!1),[A,O]=m.useState(!1),[k,j]=m.useState(null),[S,d]=m.useState(null),[L,I]=m.useState(Gn),[B,y]=m.useState(Vn),F=((he=a==null?void 0:a.data)==null?void 0:he.packages)??[],K=((me=a==null?void 0:a.data)==null?void 0:me.groups)??[],q=m.useMemo(()=>{const Z={};for(const ne of K)for(const _e of ne.features)Z[_e.id]=new Set((_e.packages??[]).map(qe=>qe.id));return Z},[K]),U=()=>{j(null),I(Gn),M(!0)},re=Z=>{j(Z),I({name:Z.name,icon:Z.icon||"",sort_order:Z.sort_order,is_active:Z.is_active}),M(!0)},te=Z=>{var ne;d(null),y({...Vn,group_id:Z||((ne=K[0])==null?void 0:ne.id)||""}),O(!0)},G=(Z,ne)=>{d(ne),y({group_id:Z,name:ne.name,tooltip:ne.tooltip||"",sort_order:ne.sort_order,is_active:ne.is_active,package_ids:(ne.packages??[]).map(_e=>_e.id)}),O(!0)},w=async()=>{var Z;if(!((Z=L.name)!=null&&Z.trim())){v.error("Group name is required");return}try{k?(await i({id:k.id,body:L}).unwrap(),v.success("Feature group updated")):(await t(L).unwrap(),v.success("Feature group created")),M(!1)}catch{v.error("Failed to save feature group")}},Y=async Z=>{try{await r(Z).unwrap(),v.success("Feature group deleted")}catch{v.error("Failed to delete feature group")}},ue=async()=>{var Z;if(!B.group_id){v.error("Please select a feature group");return}if(!((Z=B.name)!=null&&Z.trim())){v.error("Feature name is required");return}try{S?(await h({id:S.id,body:B}).unwrap(),v.success("Feature updated")):(await l(B).unwrap(),v.success("Feature created")),O(!1)}catch{v.error("Failed to save feature")}},J=async Z=>{try{await g(Z).unwrap(),v.success("Feature deleted")}catch{v.error("Failed to delete feature")}},ge=async(Z,ne,_e)=>{const qe=q[Z]||new Set,fe=new Set(qe);_e?fe.add(ne):fe.delete(ne);try{await P({featureId:Z,package_ids:Array.from(fe)}).unwrap()}catch{v.error("Failed to update package assignment")}};return s?e.jsx(W,{children:e.jsx(Q,{className:"py-12 flex items-center justify-center",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-primary"})})}):e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"Pricing Feature Comparison"}),e.jsx(je,{children:"Manage pricing table feature groups, features, and package inclusion."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",onClick:U,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Group"]}),e.jsxs(u,{onClick:()=>te(),children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Feature"]})]})]}),e.jsx(Q,{className:"space-y-6",children:K.length===0?e.jsx("div",{className:"text-sm text-muted-foreground border rounded-lg p-4",children:"No pricing comparison groups yet. Create a group to start building the pricing comparison table."}):K.map(Z=>e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/30 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:Z.name}),!Z.is_active&&e.jsx(ee,{variant:"secondary",children:"Inactive"}),Z.icon?e.jsx(ee,{variant:"outline",children:Z.icon}):null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>te(Z.id),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"}),"Feature"]}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>re(Z),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>Y(Z.id),disabled:o,children:e.jsx(Le,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[780px] text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-background",children:[e.jsx("th",{className:"text-left px-3 py-2 w-[280px]",children:"Feature"}),F.map(ne=>e.jsxs("th",{className:"text-center px-2 py-2 font-medium",children:[e.jsx("div",{children:ne.name}),ne.is_recommended?e.jsx("div",{className:"text-[10px] text-amber-600 dar
2k:text-amber-400",children:"Recommended"}):null,e.jsx("div",{className:"text-[10px] text-muted-foreground",children:Dd(ne.price_monthly,ne.is_free)}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:Ld(ne.max_employees)})]},ne.id)),e.jsx("th",{className:"text-right px-3 py-2 w-[130px]",children:"Actions"})]})}),e.jsx("tbody",{children:Z.features.length===0?e.jsx("tr",{children:e.jsx("td",{className:"px-3 py-3 text-muted-foreground",colSpan:F.length+2,children:"No features in this group yet."})}):Z.features.map(ne=>{const _e=q[ne.id]||new Set;return e.jsxs("tr",{className:"border-b",children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium",children:ne.name}),ne.tooltip?e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:ne.tooltip}):null,ne.is_active?null:e.jsx(ee,{variant:"secondary",className:"mt-1",children:"Inactive"})]}),F.map(qe=>e.jsx("td",{className:"px-2 py-2 text-center",children:e.jsx(bs,{checked:_e.has(qe.id),onCheckedChange:fe=>ge(ne.id,qe.id,!!fe),disabled:z})},qe.id)),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:()=>G(Z.id,ne),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>J(ne.id),disabled:b,children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},ne.id)})})]})})]},Z.id))}),e.jsx(Fe,{open:p,onOpenChange:M,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:k?"Edit Feature Group":"Create Feature Group"}),e.jsx(Ge,{children:"Groups become sections in the pricing feature comparison table."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Group Name"}),e.jsx(E,{value:L.name||"",onChange:Z=>I(ne=>({...ne,name:Z.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Icon Name"}),e.jsx(E,{placeholder:"e.g. Users",value:L.icon||"",onChange:Z=>I(ne=>({...ne,icon:Z.target.value}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:L.sort_order??0,onChange:Z=>I(ne=>({...ne,sort_order:Number(Z.target.value||0)}))})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Active"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Only active groups show on pricing page."})]}),e.jsx(Ve,{checked:L.is_active??!0,onCheckedChange:Z=>I(ne=>({...ne,is_active:Z}))})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsxs(u,{onClick:w,disabled:n||c,children:[n||c?e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Save Group"]})]})]})}),e.jsx(Fe,{open:A,onOpenChange:O,children:e.jsxs(ze,{className:"max-w-2xl",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:S?"Edit Feature":"Create Feature"}),e.jsx(Ge,{children:"Add a feature row and mark which subscription packages include it."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Group"}),e.jsxs("select",{className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",value:B.group_id,onChange:Z=>y(ne=>({...ne,group_id:Z.target.value})),children:[e.jsx("option",{value:"",children:"Select group"}),K.map(Z=>e.jsx("option",{value:Z.id,children:Z.name},Z.id))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:B.sort_order??0,onChange:Z=>y(ne=>({...ne,sort_order:Number(Z.target.value||0)}))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Feature Name"}),e.jsx(E,{value:B.name||"",onChange:Z=>y(ne=>({...ne,name:Z.target.value}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{children:"Tooltip / Description"}),e.jsx(Ce,{rows:3,value:B.tooltip||"",onChange:Z=>y(ne=>({...ne,tooltip:Z.target.value}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Active"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Only active features show on pricing page."})]}),e.jsx(Ve,{checked:B.is_active??!0,onCheckedChange:Z=>y(ne=>({...ne,is_active:Z}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Included Packages"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:F.map(Z=>{const ne=(B.package_ids||[]).includes(Z.id);return e.jsxs("label",{className:"flex items-center gap-2 rounded-md border p-2 text-sm",children:[e.jsx(bs,{checked:ne,onCheckedChange:_e=>{const qe=new Set(B.package_ids||[]);_e?qe.add(Z.id):qe.delete(Z.id),y(fe=>({...fe,package_ids:Array.from(qe)}))}}),e.jsxs("span",{children:[Z.name,Z.is_recommended?" (Recommended)":""]})]}
2,Z.id)})})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>O(!1),children:"Cancel"}),e.jsxs(u,{onClick:ue,disabled:_||N,children:[_||N?e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Save Feature"]})]})]})})]})}const Ct={name:"",description:"",price_monthly:0,price_yearly:0,max_employees:null,free_trial_days:14,is_active:!0,is_visible:!0,is_free:!1,include_employee_corner:!0,feature_ids:[],discount_percentage:null,discount_expires_at:null,discount_max_renewals_per_org:null,discount_applies_to_monthly:!0,discount_applies_to_yearly:!0,is_recommended:!1},Ja=a=>{if(a.type==="feature")return[a.id];if(a.type==="feature_group")return a.children.map(s=>s.id);if(a.type==="module"){const s=[];for(const t of a.children)t.type==="feature"?s.push(t.id):t.type==="feature_group"&&s.push(...t.children.map(n=>n.id));return s}return[]};function Ri({feature:a,isSelected:s,onToggle:t,indent:n=!1}){return e.jsxs("div",{className:Ts("flex items-center gap-3 px-4 py-3 hover:bg-muted/40 transition-all duration-150 cursor-pointer border-b last:border-b-0",n&&"pl-12",s&&"bg-primary/10 border-l-4 border-l-primary"),onClick:()=>t(a.id,!s),children:[e.jsx(bs,{checked:s,onCheckedChange:i=>t(a.id,!!i),onClick:i=>i.stopPropagation(),className:"data-[state=checked]:bg-primary data-[state=checked]:border-primary"}),e.jsx(ki,{className:Ts("h-4 w-4 flex-shrink-0",s?"text-primary":"text-muted-foreground")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:Ts("text-sm",s&&"font-semibold text-foreground"),children:a.title}),a.is_core&&e.jsx(ee,{variant:"outline",className:"text-xs flex-shrink-0 border-blue-300 text-blue-700 dark:border-blue-700 dark:text-blue-300",children:"Core"}),a.has_settings&&e.jsxs(ee,{variant:"secondary",className:"text-xs flex-shrink-0",children:[e.jsx(an,{className:"h-3 w-3 mr-1"}),"Settings"]}),a.has_employee_corner&&e.jsxs(ee,{className:"text-xs bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-100 flex-shrink-0 border-0",children:[e.jsx(gs,{className:"h-3 w-3 mr-1"}),"Employee"]})]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:a.description})]}),e.jsxs(ee,{variant:"outline",className:"text-xs text-muted-foreground flex-shrink-0 font-normal",children:[a.permission_count||0," perms"]})]})}function Md({group:a,selectedFeatureIds:s,onToggleFeature:t,onToggleGroup:n,isExpanded:i,onToggleExpand:c}){const r=a.children.map(h=>h.id),o=r.filter(h=>s.has(h)).length,l=r.length>0&&o===r.length,_=o>0&&o<r.length;return e.jsxs("div",{className:"border-l-3 border-primary/30 ml-6",children:[e.jsxs("div",{className:Ts("flex items-center gap-3 px-4 py-3 bg-muted/30 cursor-pointer hover:bg-muted/50 transition-all duration-150",l&&"bg-primary/10 border-l-4 border-l-primary",_&&"bg-amber-50 dark:bg-amber-900/20 border-l-4 border-l-amber-500"),children:[e.jsx(u,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 flex-shrink-0",onClick:c,children:i?e.jsx(ca,{className:"h-4 w-4"}):e.jsx(wa,{className:"h-4 w-4"})}),e.jsx(bs,{checked:l?!0:_?"indeterminate":!1,onCheckedChange:h=>n(a.id,r,h===!0),className:"data-[state=indeterminate]:bg-amber-500 data-[state=indeterminate]:border-amber-500 data-[state=checked]:bg-primary data-[state=checked]:border-primary"}),e.jsx(sn,{className:"h-4 w-4 text-orange-500 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",onClick:c,children:e.jsx("span",{className:"text-sm font-medium",children:a.title})}),e.jsxs(ee,{variant:"outline",className:"text-xs flex-shrink-0",children:[o,"/",r.length]})]}),i&&e.jsx("div",{className:"bg-background",children:a.children.map(h=>e.jsx(Ri,{feature:h,isSelected:s.has(h.id),onToggle:t,indent:!0},h.id))})]})}function qd({module:a,selectedFeatureIds:s,onToggleModule:t,onToggleFeatureGroup:n,onToggleFeature:i,expandedModules:c,expandedGroups:r,onToggleModuleExpand:o,onToggleGroupExpand:l}){const _=c.has(a.id),h=Ja(a),N=h.filter(p=>s.has(p)).length,g=h.length>0&&N===h.length,b=N>0&&N<h.length,P=a.children.filter(p=>p.type==="feature_group"),z=a.children.filter(p=>p.type==="feature");return e.jsxs("div",{className:"border rounded-xl overflow-hidden mb-4 shadow-sm hover:shadow-md transition-shadow duration-200",children:[e.jsxs("div",{className:Ts("flex items-center gap-4 p-5 bg-muted/40 cursor-pointer hover:bg-muted/60 transition-all duration-150",g&&"bg-primary/15 border-l-4 border-l-primary",b&&"bg-amber-50 dark:bg-amber-900/20 border-l-4 border-l-amber-500"),
2children:[e.jsx(u,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 flex-shrink-0",onClick:()=>o(a.id),children:_?e.jsx(ca,{className:"h-4 w-4"}):e.jsx(wa,{className:"h-4 w-4"})}),e.jsx(bs,{checked:g?!0:b?"indeterminate":!1,onCheckedChange:p=>t(a.id,h,p===!0),className:"data-[state=indeterminate]:bg-amber-500 data-[state=indeterminate]:border-amber-500 data-[state=checked]:bg-primary data-[state=checked]:border-primary"}),e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",onClick:()=>o(a.id),children:[e.jsx($l,{className:Ts("h-5 w-5 flex-shrink-0",a.color||"text-primary")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"truncate",children:a.name}),a.is_core&&e.jsx(ee,{variant:"secondary",className:"text-xs flex-shrink-0",children:"Core"})]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:a.description})]})]}),e.jsxs(ee,{variant:"outline",className:"text-xs flex-shrink-0",children:[N,"/",h.length," features"]})]}),_&&e.jsxs("div",{className:"border-t bg-background",children:[P.map(p=>e.jsx(Md,{group:p,selectedFeatureIds:s,onToggleFeature:i,onToggleGroup:n,isExpanded:r.has(p.id),onToggleExpand:()=>l(p.id)},p.id)),z.length>0&&e.jsx("div",{className:Ts(P.length>0&&"border-t"),children:z.map(p=>e.jsx(Ri,{feature:p,isSelected:s.has(p.id),onToggle:i},p.id))}),P.length===0&&z.length===0&&e.jsx("div",{className:"p-6 text-center text-sm text-muted-foreground",children:"No features in this module"})]})]})}function Od(){const[a,s]=m.useState(!1),[t,n]=m.useState(null),[i,c]=m.useState(Ct),[r,o]=m.useState("basic"),[l,_]=m.useState(new Set),[h,N]=m.useState(new Set),[g,b]=m.useState(null),[P,z]=m.useState(!1),[p,M]=m.useState(!1),[A,O]=m.useState(null),[k,j]=m.useState({price_monthly:0,price_yearly:0,discount_percentage:null,discount_expires_at:null,discount_max_renewals_per_org:null,discount_applies_to_monthly:!0,discount_applies_to_yearly:!0,reason:""}),{data:S,isLoading:d,error:L}=on(),{data:I,isLoading:B}=pd(),[y,{isLoading:F}]=gd(),[K,{isLoading:q}]=jd(),[U,{isLoading:re}]=fd(),[te,{isLoading:G}]=vd(),w=m.useMemo(()=>new Set(i.feature_ids),[i.feature_ids]);m.useEffect(()=>{a||(n(null),c(Ct),o("basic"),_(new Set),N(new Set))},[a]),m.useEffect(()=>{P||b(null)},[P]),m.useEffect(()=>{if(t){let R=[];if(console.log("Editing package:",t.name),console.log("Feature keys:",t.feature_keys),console.log("Feature IDs:",t.feature_ids),console.log("Features:",t.features),t.feature_keys&&Array.isArray(t.feature_keys)?R=t.feature_keys.filter(H=>H&&H!=="null"):t.feature_ids&&Array.isArray(t.feature_ids)?R=t.feature_ids.filter(H=>H&&H!=="null"):t.features&&Array.isArray(t.features)&&(R=t.features.map(H=>typeof H=="object"&&H!==null&&"id"in H?String(H.id):null).filter(H=>H!==null&&H!=="null")),console.log("Extracted feature IDs:",R),c({name:t.name,description:t.description||"",price_monthly:t.price_monthly,price_yearly:t.price_yearly,max_employees:t.max_employees,free_trial_days:t.free_trial_days,is_active:t.is_active,is_visible:t.is_visible??!0,is_free:t.is_free,include_employee_corner:t.include_employee_corner??!0,feature_ids:R,discount_percentage:t.discount_percentage??null,discount_expires_at:t.discount_expires_at?t.discount_expires_at.substring(0,10):null,discount_max_renewals_per_org:t.discount_max_renewals_per_org??null,discount_applies_to_monthly:t.discount_applies_to_monthly??!0,discount_applies_to_yearly:t.discount_applies_to_yearly??!0,is_recommended:t.is_recommended??!1}),I&&R.length>0){const H=new Set,$=new Set;for(const de of I)if(Ja(de).some(be=>R.includes(be))){H.add(de.id);for(const be of de.children)be.type==="feature_group"&&be.children.map(Ls=>Ls.id).some(Ls=>R.includes(Ls))&&$.add(be.id)}_(H),N($)}}},[t,I]);const Y=m.useCallback((R,H,$)=>{c(de=>{const xe=new Set(de.feature_ids);return $?H.forEach(Me=>xe.add(Me)):H.forEach(Me=>xe.delete(Me)),{...de,feature_ids:Array.from(xe)}})},[]),ue=m.useCallback((R,H,$)=>{c(de=>{const xe=new Set(de.feature_ids);return $?H.forEach(Me=>
2xe.add(Me)):H.forEach(Me=>xe.delete(Me)),{...de,feature_ids:Array.from(xe)}})},[]),J=m.useCallback((R,H)=>{c($=>{const de=new Set($.feature_ids);return H?de.add(R):de.delete(R),{...$,feature_ids:Array.from(de)}})},[]),ge=m.useCallback(R=>{_(H=>{const $=new Set(H);return $.has(R)?$.delete(R):$.add(R),$})},[]),he=m.useCallback(R=>{N(H=>{const $=new Set(H);return $.has(R)?$.delete(R):$.add(R),$})},[]),me=m.useCallback(()=>{if(I){const R=new Set(I.map($=>$.id)),H=new Set;for(const $ of I)for(const de of $.children)de.type==="feature_group"&&H.add(de.id);_(R),N(H)}},[I]),Z=m.useCallback(()=>{_(new Set),N(new Set)},[]),ne=m.useCallback(()=>{if(I){const R=[];for(const H of I)R.push(...Ja(H));c(H=>({...H,feature_ids:R}))}},[I]),_e=m.useCallback(()=>{c(R=>({...R,feature_ids:[]}))},[]),qe=R=>{n(R),s(!0)},fe=()=>{n(null),c(Ct),s(!0)},Qe=async()=>{var R;try{const H={...i,price_monthly:Number(i.price_monthly),price_yearly:Number(i.price_yearly),free_trial_days:Number(i.free_trial_days),max_employees:i.max_employees?Number(i.max_employees):null,discount_max_renewals_per_org:i.discount_max_renewals_per_org?Number(i.discount_max_renewals_per_org):null};t?(await K({id:t.id,subscriptionData:H}).unwrap(),v.success("Package updated successfully")):(await y(H).unwrap(),v.success("Package created successfully")),s(!1)}catch(H){v.error(((R=H==null?void 0:H.data)==null?void 0:R.message)||"Failed to save package")}},oe=(R,H)=>{b({id:R,name:H}),z(!0)},Te=async()=>{var H;if(!g)return;const R=v.loading("Deleting package...");try{await te(g.id).unwrap(),v.success("Package deleted successfully",{id:R}),z(!1),b(null)}catch($){v.error(((H=$==null?void 0:$.data)==null?void 0:H.message)||"Failed to delete package",{id:R})}},we=R=>{O(R),j({price_monthly:R.price_monthly,price_yearly:R.price_yearly,discount_percentage:R.discount_percentage??null,discount_expires_at:R.discount_expires_at?R.discount_expires_at.substring(0,10):null,discount_max_renewals_per_org:R.discount_max_renewals_per_org??null,discount_applies_to_monthly:R.discount_applies_to_monthly??!0,discount_applies_to_yearly:R.discount_applies_to_yearly??!0,reason:""}),M(!0)},Ze=async()=>{var H;if(!A)return;if(!k.reason.trim()){v.error("A reason is required so subscribers can be told why the price changed");return}const R=v.loading("Updating price...");try{const $=await U({id:A.id,price_monthly:k.price_monthly,price_yearly:k.price_yearly,discount_percentage:k.discount_percentage,discount_expires_at:k.discount_expires_at,discount_max_renewals_per_org:k.discount_max_renewals_per_org,discount_applies_to_monthly:k.discount_applies_to_monthly,discount_applies_to_yearly:k.discount_applies_to_yearly,reason:k.reason.trim()}).unwrap();v.success(($==null?void 0:$.message)||"Price updated successfully",{id:R}),M(!1),O(null)}catch($){v.error(((H=$==null?void 0:$.data)==null?void 0:H.message)||"Failed to update price",{id:R})}},f=i.feature_ids.length,ie=m.useMemo(()=>I?I.reduce((R,H)=>R+Ja(H).length,0):0,[I]);return d?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):L?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-destructive",children:[e.jsx(Oe,{className:"h-12 w-12 mb-4"}),e.jsx("p",{children:"Failed to load subscription packages"})]}):e.jsx(ye,{title:"",subtitle:"",children:e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-3",children:[e.jsx(ia,{className:"h-8 w-8 text-primary"}),"Subscription Packages"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage subscription tiers and their features"})]}),e.jsxs(u,{onClick:fe,size:"lg",children:[e.jsx(Ie,{className:"h-5 w-5 mr-2"}),"New Package"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[S==null?void 0:S.map(R=>{var H;return e.jsxs(W,{className:Ts("relative overflow-hidden transition-all hover:shadow-lg",!R.is_active&&"opacity-60",R.is_free&&"border-green-500"),children:[R.is_free&&e.jsx("div",{className:"absolute top-0 right-0 bg-green-500 text-white text-xs px-3 py-1 rounded-bl-lg",children:"Free"}),e.jsx(se,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[R.name,!R.is_active&&e.jsx(ee,{variant:"secondary",children:"Inactive"})]}),e.jsx(je,{className:"mt-1",children:R.description||"No description"})]}),e.jsx(Il,{className:"h-6 w-6 text-yellow-500"})]})}),e.jsxs(Q,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{children:e.jsxs("p",{className:"text-2xl font-bold",children:["£",R.price_monthly,e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:"/mo"})]})}),e.jsx("div",{className:"border-l pl-4",children:e.jsxs("p",{className:"text-2xl font-bold",children:["£",R.price_yearly,e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:"/yr"})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-4 w-4 text-green-500"}),e.jsxs("span",{children:[R.max_employees??"Unlimited"," employees"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-4 w-4 text-green-500"}),e.jsxs("span",{children:[R.free_trial_days," days trial"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-4 w-4 text-primary"}),e.jsxs("span",{children:[((H=R.features)==null?void 0:H.length)||0," features"]})]}),e.jsx("div",{className:"flex items-center gap-2",children:R.include_employee_corner?e.jsxs(e.Fragment,{children:[e.jsx(Ps,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{children:"Employee Corner"})]}):e.jsxs(e.Fragment,{children:[e.jsx(st,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"No Employee Corner"})]})})]}),R.features&&R.features.length>0&&e.jsxs("div",{className:"border-t pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Included features:"}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[R.features.slice(0,4).map($=>e.jsx(ee,{variant:"secondary",className:"text-xs",children:$.name},$.id)),R.features.length>4&&e.jsxs(ee,{variant:"outline",className:"text-xs",children:["+",R.features.length-4," more"]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(u,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>qe(R),children:[e.jsx(ds,{className:"h-4 w-4 mr-1"}),"Edit"]}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>we(R),title:"Update price and notify subscribers",children:e.jsx(Vt,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>oe(R.id,R.name),disabled:G,children:e.jsx(Le,{className:"h-4 w-4"})})]})]})]},R.id)}),(!S||S.length===0)&&e.jsx(W,{className:"col-span-full",children:e.jsxs(Q,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ia,{className:"h-16 w-16 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No packages yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Create your first subscription package to get started"}),e.jsxs(u,{onClick:fe,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Create Package"]})]})})]}),e.jsx(Oi,{}),e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"w-[98vw] sm:w-[95vw] md:w-[92vw] lg:w-[88vw] xl:w-[85vw] 2xl:max-w-[1600px] h-[95vh] max-h-[95vh] flex flex-col p-0 gap-0 overflow-hidden rounded-xl shadow-2xl",children:[e.jsxs(Ee,{className:"px-6 py-4 border-b flex-shrink-0",children:[e.jsxs(De,{className:"flex items-center gap-2",children:[e.jsx(ia,{className:"h-5 w-5 text-primary"}),t?"Edit Package":"Create New Package"]}),e.jsx(Ge,{children:"Configure package details and select included features"})]}),e.jsxs(Qs,{value:r,onValueChange:o,className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[e.jsxs(Ks,{className:"grid w-full grid-cols-2 mx-6 mt-4 max-w-md flex-shrink-0",children:[e.jsx(Ye,{value:"basic",children:"Basic Info"}),e.jsxs(Ye,{value:"features",children:["Features (",f,"/",ie,")"]})]}),e.jsxs(Je,{value:"basic",className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"name",children:"Package Name *"}),e.jsx(E,{id:"name",placeholder:"e.g., Professional",value:i.name,onChange:R=>c(H=>({...H,name:R.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"free_trial_days",children:"Free Trial Days"}),e.jsx(E,{id:"free_trial_days",type:"number",min:0,value:i.free_trial_days,onChange:R=>c(H=>({...H,free_trial_days:parseInt(R.target.value)||0}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(Ce,{id:"description",placeholder:"Describe what this package offers...",value:i.description,onChange:R=>c(H=>({...H,description:R.target.value})),rows:3})]}),!t&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"price_monthly",children:"Monthly Price (£)"}),e.jsx(E,{id:"price_monthly",type:"number",min:0,step:"0.01",value:i.price_monthly,onChange:R=>c(H=>({...H,price_monthly:parseFloat(R.target.value)||0}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"price_yearly",children:"Yearly Price (£)"}),e.jsx(E,{id:"price_yearly",type:"number",min:0,step:"0.01",value:i.price_yearly,onChange:R=>c(H=>({...H,price_yearly:parseFloat(R.target.value)||0}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"max_employees",children:"Max Employees (leave empty for unlimited)"}),e.jsx(E,{id:"max_employees",type:"number",min:1,placeholder:"Unlimited",value:i.max_employees??"",onChange:R=>c(H=>({...H,max_employees:R.target.value?parseInt(R.target.value):null}))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx(x,{htmlFor:"is_active",className:"cursor-pointer",children:"Active"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Package is available for purchase"})]}),e.jsx(Ve,{id:"is_active",checked:i.is_active,onCheckedChange:R=>c(H=>({...H,is_active:R}))})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx(x,{htmlFor:"is_visible",className:"cursor-pointer",children:"Visible"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Show on pricing page"})]}),e.jsx(Ve,{id:"is_visible",checked:i.is_visible,onCheckedChange:R=>c(H=>({...H,is_visible:R}))})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx(x,{htmlFor:"is_free",className:"cursor-pointer",children:"Free Tier"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No payment required"})]}),e.jsx(Ve,{id:"is_free",checked:i.is_free,onCheckedChange:R=>c(H=>({...H,is_free:R}))})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx(x,{htmlFor:"include_employee_corner",className:"cursor-pointer",children:"Employee Corner"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enable employee self-service"})]}),e.jsx(Ve,{id:"include_employee_corner",checked:i.include_employee_corner,onCheckedChange:R=>c(H=>({...H,include_employee_corner:R}
2))})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800",children:[e.jsxs("div",{children:[e.jsxs(x,{htmlFor:"is_recommended",className:"cursor-pointer flex items-center gap-2",children:[e.jsx(Ea,{className:"h-4 w-4 text-amber-500"}),"Recommended"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Mark as recommended plan"})]}),e.jsx(Ve,{id:"is_recommended",checked:i.is_recommended,onCheckedChange:R=>c(H=>({...H,is_recommended:R}))})]})]})]}),e.jsxs(Je,{value:"features",className:"flex-1 flex flex-col min-h-0 overflow-hidden px-6 py-4",children:[e.jsx("div",{className:"w-full bg-muted/20 px-4 sm:px-6 py-3 border-b mb-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(u,{"aria-label":"Collapse All",variant:"outline",size:"sm",onClick:Z,className:"hover:bg-background flex-1 sm:flex-none",children:[e.jsx(wa,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Collapse All"})]}),e.jsxs(u,{"aria-label":"Expand All",variant:"outline",size:"sm",onClick:me,className:"hover:bg-background flex-1 sm:flex-none",children:[e.jsx(ca,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Expand All"})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(u,{"aria-label":"Select All",variant:"outline",size:"sm",onClick:ne,className:"hover:bg-background flex-1 sm:flex-none",children:[e.jsx(Ps,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Select All"})]}),e.jsxs(u,{"aria-label":"Deselect All",variant:"outline",size:"sm",onClick:_e,className:"hover:bg-background flex-1 sm:flex-none",children:[e.jsx(st,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Deselect All"})]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto pr-2 -mx-2 px-2",children:B?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-primary"})}):I&&I.length>0?e.jsx("div",{className:"space-y-3 pb-4",children:I.map(R=>e.jsx(qd,{module:R,selectedFeatureIds:w,onToggleModule:Y,onToggleFeatureGroup:ue,onToggleFeature:J,expandedModules:l,expandedGroups:h,onToggleModuleExpand:ge,onToggleGroupExpand:he},R.id))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(ki,{className:"h-12 w-12 mb-4"}),e.jsx("p",{children:"No modules or features available"})]})})]})]}),e.jsxs(Re,{className:"px-6 py-4 border-t flex-shrink-0",children:[e.jsx(u,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsxs(u,{onClick:Qe,disabled:F||q||!i.name,children:[(F||q)&&e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),t?"Update Package":"Create Package"]})]})]})}),e.jsx(Fe,{open:P,onOpenChange:z,children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Delete Subscription Package"}),e.jsx(Ge,{children:g?e.jsxs(e.Fragment,{children:["Are you sure you want to delete ",e.jsx("strong",{children:g.name}),"? This action cannot be undone."]}):"Are you sure you want to delete this package?"})]}),e.jsxs(Re,{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",onClick:()=>{z(!1),b(null)},children:"Cancel"}),e.jsx(u,{variant:"destructive",onClick:Te,disabled:!g||G,children:"Delete"})]})]})}),e.jsx(Fe,{open:p,onOpenChange:M,children:e.jsxs(ze,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsxs(De,{className:"flex items-center gap-2",children:[e.jsx(Vt,{className:"h-5 w-5 text-primary"}),"Update Price & Discount"]}),e.jsx(Ge,{children:A?e.jsxs(e.Fragment,{children:["Change the price or discount of ",e.jsx("strong",{children:A.name}),". Subscribed organizations will be emailed the old price, the new price, and your reason."]}):"Change the package price or discount."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"price_monthly_update",children:"Monthly Price (£)"}
2),e.jsx(E,{id:"price_monthly_update",type:"number",min:0,step:.01,value:k.price_monthly,onChange:R=>j(H=>({...H,price_monthly:parseFloat(R.target.value)||0}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"price_yearly_update",children:"Yearly Price (£)"}),e.jsx(E,{id:"price_yearly_update",type:"number",min:0,step:.01,value:k.price_yearly,onChange:R=>j(H=>({...H,price_yearly:parseFloat(R.target.value)||0}))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"discount_percentage_update",children:"Discount Percentage (%) - Optional"}),e.jsx(E,{id:"discount_percentage_update",type:"number",min:0,max:100,step:"0.01",placeholder:"e.g., 10 for 10% off",value:k.discount_percentage??"",onChange:R=>j(H=>({...H,discount_percentage:R.target.value?parseFloat(R.target.value):null}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"discount_expires_at_update",children:"Discount Expiry Date - Optional"}),e.jsx(E,{id:"discount_expires_at_update",type:"date",value:k.discount_expires_at??"",onChange:R=>j(H=>({...H,discount_expires_at:R.target.value||null}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"discount_max_renewals_per_org_update",children:"Discount Max Uses Per Organization - Optional"}),e.jsx(E,{id:"discount_max_renewals_per_org_update",type:"number",min:1,placeholder:"Unlimited",value:k.discount_max_renewals_per_org??"",onChange:R=>j(H=>({...H,discount_max_renewals_per_org:R.target.value?parseInt(R.target.value,10):null}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limits how many discounted payments one organization can receive"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsx(x,{htmlFor:"discount_applies_to_monthly_update",className:"cursor-pointer",children:"Discount For Monthly"}),e.jsx(Ve,{id:"discount_applies_to_monthly_update",checked:k.discount_applies_to_monthly,onCheckedChange:R=>j(H=>({...H,discount_applies_to_monthly:R}))})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 p-3 rounded-lg border",children:[e.jsx(x,{htmlFor:"discount_applies_to_yearly_update",className:"cursor-pointer",children:"Discount For Yearly"}),e.jsx(Ve,{id:"discount_applies_to_yearly_update",checked:k.discount_applies_to_yearly,onCheckedChange:R=>j(H=>({...H,discount_applies_to_yearly:R}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"price_change_reason",children:"Reason for change *"}),e.jsx(Ce,{id:"price_change_reason",placeholder:"e.g. Annual pricing review to reflect infrastru
2cture costs",value:k.reason,onChange:R=>j(H=>({...H,reason:R.target.value})),rows:3})]})]}),e.jsxs(Re,{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",onClick:()=>{M(!1),O(null)},children:"Cancel"}),e.jsx(u,{onClick:Ze,disabled:!A||re,children:re?"Updating...":"Update Price & Notify"})]})]})})]})})}const kt={name:"",code:"",type:"percentage",amount:0,min_purchase:null,usage_limit:null,max_uses_per_organization:null,is_first_time_user:!1,applicable_package_ids:[],applicable_organization_ids:[],applies_monthly:!0,applies_yearly:!0,expires_at:""};function Rd(){const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(!1),[r,o]=m.useState(!1),[l,_]=m.useState(null),[h,N]=m.useState(null),[g,b]=m.useState(kt),[P,z]=m.useState(null),[p,M]=m.useState(!1),[A,O]=m.useState(!1),[k,j]=m.useState(""),{data:S,isLoading:d,error:L}=Bl({page:a,search:t.trim()||void 0}),{data:I=[],isLoading:B}=on(),{data:y,isLoading:F}=cn({page:1,status:"active",search:k||void 0,per_page:50}),[K,{isLoading:q}]=Ul(),[U,{isLoading:re}]=Gl(),[te,{isLoading:G}]=Vl(),w=(S==null?void 0:S.data)||[],Y=S==null?void 0:S.meta,ue=(y==null?void 0:y.data)||[],J=()=>{const f="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";let ie="";for(let R=0;R<8;R++)ie+=f.charAt(Math.floor(Math.random()*f.length));b(R=>({...R,code:ie}))},ge=async f=>{await navigator.clipboard.writeText(f),z(f),v.success("Coupon code copied!"),setTimeout(()=>z(null),2e3)},he=()=>{_(null),b(kt),j(""),M(!1),O(!1),c(!0)},me=f=>{_(f),b({name:f.name,code:f.code,type:f.type,amount:f.amount,min_purchase:f.min_purchase,usage_limit:f.usage_limit,max_uses_per_organization:f.max_uses_per_organization??null,is_first_time_user:f.first_time_user,applicable_package_ids:Array.isArray(f.applicable_package_ids)?f.applicable_package_ids:[],applicable_organization_ids:Array.isArray(f.applicable_organization_ids)?f.applicable_organization_ids:[],applies_monthly:!f.applicable_frequencies||f.applicable_frequencies.length===0?!0:f.applicable_frequencies.includes("monthly"),applies_yearly:!f.applicable_frequencies||f.applicable_frequencies.length===0?!0:f.applicable_frequencies.includes("yearly"),expires_at:f.expires_at?f.expires_at.split("T")[0]:""}),j(""),M(!1),O(!1),c(!0)},Z=f=>{N(f),o(!0)},ne=async()=>{var ie,R;if(!g.name||!g.code||!g.amount){v.error("Please fill in all required fields");return}if(!g.applies_monthly&&!g.applies_yearly){v.error("Select at least one applicable billing frequency");return}const f={name:g.name,code:g.code.toUpperCase(),type:g.type,amount:g.amount,expires_at:g.expires_at||null,min_purchase:g.min_purchase,usage_limit:g.usage_limit,is_first_time_user:g.is_first_time_user,max_uses_per_organization:g.max_uses_per_organization,applicable_package_ids:g.applicable_package_ids,applicable_organization_ids:g.applicable_organization_ids,applicable_frequencies:[g.applies_monthly?"monthly":null,g.applies_yearly?"yearly":null].filter(Boolean)};try{l?(await U({id:l.id,data:f}).unwrap(),v.success("Coupon updated successfully!")):(await K(f).unwrap(),v.success("Coupon created successfully! ",{description:`Code: ${f.code}`})),c(!1),b(kt)}catch(H){const $=H,de=((ie=$==null?void 0:$.data)==null?void 0:ie.message)||((R=$==null?void 0:$.data)!=null&&R.errors?Object.values($.data.errors).flat().join(", "):"Failed to save coupon");v.error(de)}},_e=async()=>{if(h)try{await te(h.id).unwrap(),v.success("Coupon deleted successfully"),o(!1),N(null)}catch{v.error("Failed to delete coupon")}},qe=f=>f?new Date(f)<new Date:!1,fe=f=>f.usage_limit?`${f.usage_count||0}/${f.usage_limit}`:`${f.usage_count||0} uses`,Qe=f=>!f.applicable_frequencies||f.applicable_frequencies.length===0?"Monthly and yearly":f.applicable_frequencies.map(ie=>ie==="yearly"?"Yearly":"Monthly").join(", "),oe=f=>{b(ie=>{const R=ie.applicable_package_ids.includes(f);return{...ie,applicable_package_ids:R?ie.applicable_package_ids.filter(H=>H!==f):[...ie.applicable_package_ids,f]}})},Te=f=>{b(ie=>{const R=ie.applicable_organization_ids.includes(f);return{...ie,applicable_organization_ids:R?ie.applicable_organization_ids.filter(H=>H!==f):[...ie.applicable_organization_ids,f]}})},we=g.applicable_organization_ids.length===0?"All organizations":`${g.applicable_organization_ids.length} organization${g.applicable_organization_ids.length===1?"":"s"} selected`,Ze=g.applicable_package_ids.length===0?"All packages":`${g.applicable_package_ids.length} package${g.applicable_package_ids.length===1?"":"s"} selected`;return e.jsxs(ye,{title:"",subtitle:"",children:[e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Coupon Management"}),e.jsx("p",{className:"text-muted-foreground",children:"Create and manage discount coupons for subscription packages"})]}),e.jsxs(u,{onClick:he,className:"gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Create Coupon"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ae,{className:"text-sm font-medium",children:"Total Coupons"}),e.jsx(la,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:(Y==null?void 0:Y.total)||0})})]}),e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ae,{className:"text-sm font-medium",children:"Active"}),e.jsx(Ps,{className:"h-4 w-4 text-green-500"})]}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:w.filter(f=>!f.expires_at||!qe(f.expires_at)).length})})]}),e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ae,{className:"text-sm font-medium",children:"Percentage"}),e.jsx(vt,{className:"h-4 w-4 text-blue-500"})]}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:w.filter(f=>f.type==="percentage").length})})]}),e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ae,{className:"text-sm font-medium",children:"Flat Amount"}),e.jsx(Ya,{className:"h-4 w-4 text-purple-500"})]}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-purple-600",children:w.filter(f=>f.type==="flat").length})})]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"All Coupons"}),e.jsx(je,{children:"Manage your discount codes"})]}),e.jsxs("div",{className:"relative w-64",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(E,{placeholder:"Search coupons...",value:t,onChange:f=>{s(1),n(f.target.value)},className:"pl-10"})]})]})}),e.jsx(Q,{children:d?e.jsx("div",{className:"flex h-48 items-center justify-center",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}
2):L?e.jsx("div",{className:"flex h-48 items-center justify-center text-red-500",children:"Failed to load coupons"}):w.length===0?e.jsxs("div",{className:"flex h-48 flex-col items-center justify-center text-muted-foreground",children:[e.jsx(la,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsx("p",{children:"No coupons found"}),e.jsx(u,{variant:"link",onClick:he,children:"Create your first coupon"})]}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Code"}),e.jsx(T,{children:"Type"}),e.jsx(T,{children:"Discount"}),e.jsx(T,{children:"Usage"}),e.jsx(T,{children:"Compliance"}),e.jsx(T,{children:"Expires"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:w.map(f=>{var ie;return e.jsxs(le,{children:[e.jsx(C,{className:"font-medium",children:f.name}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"rounded bg-muted px-2 py-1 text-sm font-mono",children:f.code}),e.jsx(u,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>ge(f.code),children:P===f.code?e.jsx(Ps,{className:"h-3 w-3 text-green-500"}):e.jsx(Ql,{className:"h-3 w-3"})})]})}),e.jsx(C,{children:e.jsxs(ee,{variant:"outline",children:[f.type==="percentage"?e.jsx(vt,{className:"mr-1 h-3 w-3"}):e.jsx(Ya,{className:"mr-1 h-3 w-3"}),f.type]})}),e.jsx(C,{children:f.type==="percentage"?e.jsxs("span",{className:"font-semibold text-green-600",children:[f.amount??0,"%"]}):e.jsxs("span",{className:"font-semibold text-green-600",children:["£",(f.amount??0).toFixed(2)]})}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[e.jsx("div",{children:fe(f)}),(ie=f.usage_summary)!=null&&ie.max_uses_per_organization?e.jsxs("div",{children:["Org limit: ",f.usage_summary.remaining_redemptions_for_organization??f.usage_summary.max_uses_per_organization," remaining of ",f.usage_summary.max_uses_per_organization]}):null]})}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground max-w-xs",children:[e.jsxs("div",{children:["Billing: ",Qe(f)]}),f.min_purchase?e.jsxs("div",{children:["Minimum purchase: £",Number(f.min_purchase).toFixed(2)]}):null,f.first_time_user?e.jsx("div",{children:"Restricted to first-time organizations"}):null,f.applicable_package_ids&&f.applicable_package_ids.length>0?e.jsxs("div",{children:["Package restriction: ",f.applicable_package_ids.length," package",f.applicable_package_ids.length===1?"":"s"]}):e.jsx("div",{children:"Package restriction: all packages"}),f.applicable_organization_ids&&f.applicable_organization_ids.length>0?e.jsxs("div",{children:["Organization restriction: ",f.applicable_organization_ids.length," organization",f.applicable_organization_ids.length===1?"":"s"]}):e.jsx("div",{children:"Organization restriction: all organizations"})]})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Rs,{className:"h-3 w-3"}),f.expires_at?us(new Date(f.expires_at),"MMM d, yyyy"):"No expiry"]})}),e.jsxs(C,{children:[f.expires_at&&qe(f.expires_at)?e.jsx(ee,{variant:"destructive",children:"Expired"}):e.jsx(ee,{className:"bg-green-100 text-green-800",children:"Active"}),f.first_time_user&&e.jsxs(ee,{variant:"secondary",className:"ml-1",children:[e.jsx(gs,{className:"mr-1 h-3 w-3"}),"First-time"]})]}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"ghost",size:"sm",asChild:!0,title:"View Redemptions",children:e.jsx(Ss,{to:`/admin-dashboard/coupons/${f.id}/redemptions`,children:e.jsx(Kl,{className:"h-4 w-4"})})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>me(f),children:e.jsx(Hl,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>Z(f),children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},f.id)})})]}),Y&&Y.last_page>1&&e.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:a===1,onClick:()=>s(f=>f-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",a," of ",Y.last_page]}),e.jsx(u,{variant:"outline",size:"sm",disabled:a===Y.last_page,onClick:()=>s(f=>f+1),children:"Next"})]})]})})]})]}),e.jsx(Fe,{open:i,onOpenChange:c,children:e.jsxs(ze,{className:"sm:max-w-[500px]",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:l?"Edit Coupon":"Create New Coupon"}),e.jsx(Ge,{children:l?"Update the coupon details":"Create a new discount code for customers"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"name",children:"Name *"}),e.jsx(E,{id:"name",placeholder:"e.g., Summer Sale 2024",value:g.name,onChange:f=>b(ie=>({...ie,name:f.target.value}))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"code",children:"Code *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{id:"code",placeholder:"SUMMER2024",value:g.code,onChange:f=>b(ie=>({...ie,code:f.target.value.toUpperCase()})),className:"font-mono"}),e.jsx(u,{type:"button",variant:"outline",onClick:J,children:"Generate"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"type",children:"Type *"}),e.jsxs(ke,{value:g.type,onValueChange:f=>b(ie=>({...ie,type:f})),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"percentage",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(vt,{className:"mr-2 h-4 w-4"}),"Percentage"]})}),e.jsx(X,{value:"flat",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Ya,{className:"mr-2 h-4 w-4"}),"Flat Amount"]})})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(x,{htmlFor:"amount",children:[g.type==="percentage"?"Discount %":"Amount (£)"," *"]}),e.jsx(E,{id:"amount",type:"number",min:"0",max:g.type==="percentage"?100:void 0,step:g.type==="percentage"?1:.01,value:g.amount,onChange:f=>b(ie=>({...ie,amount:parseFloat(f.target.value)||0}))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"min_purchase",children:"Min. Purchase (£)"}),e.jsx(E,{id:"min_purchase",type:"number",min:"0",step:"0.01",placeholder:"Optional",value:g.min_purchase??"",onChange:f=>b(ie=>({...ie,min_purchase:f.target.value?parseFloat(f.target.value):null}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ex: Set to 50.00 = coupon only works if customer's cart total is £50 or more before applying the discount"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"usage_limit",children:"Usage Limit"}),e.jsx(E,{id:"usage_limit",type:"number",min:"0",placeholder:"Unlimited",value:g.usage_limit??"",onChange:f=>b(ie=>({...ie,usage_limit:f.target.value?parseInt(f.target.value):null}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ex: Set to 100 = coupon works for 100 total uses across all organizations"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"max_uses_per_organization",children:"Per Organization Limit"}),e.jsx(E,{id:"max_uses_per_organization",type:"number",min:"0",placeholder:"Unlimited",value:g.max_uses_per_organization??"",onChange:f=>b(ie=>({...ie,max_uses_per_organization:f.target.value?parseInt(f.target.value,10):null}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ex: Set to 1 = each company can only use this coupon once"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{children:"Applicable Packages"}),e.jsxs(Cn,{open:p,onOpenChange:M,children:[e.jsx(kn,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"justify-between font-normal",children:[e.jsx("span",{className:"truncate text-left",children:Ze}),e.jsx(ca,{className:"h-4 w-4 shrink-0 opacity-60"})]})}),e.jsx(Sn,{className:"w-[min(26rem,calc(100vw-2rem))] p-0",align:"start",collisionPadding:8,children:e.jsxs(An,{children:[e.jsx(Pn,{placeholder:"Search package..."}),e.jsxs(Tn,{children:[e.jsx(Fn,{children:"No package found."}),e.jsxs(zn,{children:[e.jsxs(Ua,{value:"all-packages",onSelect:()=>{b(f=>({...f,applicable_package_ids:[]}))},children:[e.jsx(Ps,{className:`mr-2 h-4 w-4 ${g.applicable_package_ids.length===0?"opacity-100":"opacity-0"}`}),"All packages"]}),I.map(f=>e.jsxs(Ua,{value:`${f.name} ${f.id}`,onSelect:()=>oe(f.id),children:[e.jsx(Ps,{className:`mr-2 h-4 w-4 ${g.applicable_package_ids.includes(f.id)?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:f.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f.id})]})]},f.id))]})]})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Ex: Select "Professional" = coupon only works for Professional plan. Leave as "All packages" to allow this coupon on every subscription plan.'})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(x,{children:"Applicable Organizations"})}),e.jsxs(Cn,{open:A,onOpenChange:O,children:[e.jsx(kn,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"justify-between font-normal",children:[e.jsx("span",{className:"truncate text-left",children:we}),e.jsx(ca,{className:"h-4 w-4 shrink-0 opacity-60"})]})}),e.jsx(Sn,{className:"w-[min(28.75rem,calc(100vw-2rem))] p-0",align:"start",collisionPadding:8,children:e.jsxs(An,{children:[e.jsx(Pn,{placeholder:"Search organization by name...",value:k,onValueChange:j}),e.jsxs(Tn,{children:[e.jsx(Fn,{children:"No organization found."}),e.jsxs(zn,{children:[e.jsxs(Ua,{value:"all-organizations",onSelect:()=>{b(f=>({...f,applicable_organization_ids:[]}))},children:[e.jsx(Ps,{className:`mr-2 h-4 w-4 ${g.applicable_organization_ids.length===0?"opacity-100":"opacity-0"}`}),"All organizations"]}),ue.map(f=>e.jsxs(Ua,{value:`${f.name} ${f.login_email||""}`,onSelect:()=>
2Te(f.id),children:[e.jsx(Ps,{className:`mr-2 h-4 w-4 ${g.applicable_organization_ids.includes(f.id)?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:f.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f.login_email||f.organization_email||f.id})]})]},f.id))]})]})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Ex: Select "Acme Corp" = only Acme Corp can use this coupon. Leave as "All organizations" to allow this coupon for all companies.'}),(B||F)&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading selection data..."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{children:"Applicable Billing Frequencies"}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(bs,{id:"applies_monthly",checked:g.applies_monthly,onCheckedChange:f=>b(ie=>({...ie,applies_monthly:!!f}))}),e.jsx(x,{htmlFor:"applies_monthly",className:"text-sm font-normal cursor-pointer",children:"Monthly"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(bs,{id:"applies_yearly",checked:g.applies_yearly,onCheckedChange:f=>b(ie=>({...ie,applies_yearly:!!f}))}),e.jsx(x,{htmlFor:"applies_yearly",className:"text-sm font-normal cursor-pointer",children:"Yearly"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(x,{htmlFor:"expires_at",children:"Expires At"}),e.jsx(E,{id:"expires_at",type:"date",value:g.expires_at,onChange:f=>b(ie=>({...ie,expires_at:f.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty for no expiration"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(bs,{id:"first_time_user",checked:g.is_first_time_user,onCheckedChange:f=>b(ie=>({...ie,is_first_time_user:!!f}))}),e.jsx(x,{htmlFor:"first_time_user",className:"text-sm font-normal cursor-pointer",children:"Only for first-time users"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsxs(u,{onClick:ne,disabled:q||re,className:"gap-2",children:[(q||re)&&e.jsx(ce,{className:"h-4 w-4 animate-spin"}),l?"Update Coupon":"Create Coupon"]})]})]})}),e.jsx(Fe,{open:r,onOpenChange:o,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Delete Coupon"}),e.jsxs(Ge,{children:['Are you sure you want to delete the coupon "',h==null?void 0:h.name,'"? This action cannot be undone.']})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsxs(u,{variant:"destructive",onClick:_e,disabled:G,children:[G&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete"]})]})]})})]})}const Qa=a=>new Intl.NumberFormat("en-GB",{style:"currency",currency:"GBP"}).format(a);function Id(){var h,N;const{couponId:a}=mi(),[s,t]=m.useState(1),{data:n,isLoading:i,error:c}=Wl({couponId:a,page:s},{skip:!a}),r=n==null?void 0:n.coupon,o=((h=n==null?void 0:n.redemptions)==null?void 0:h.data)??[],l=(N=n==null?void 0:n.redemptions)==null?void 0:N.meta,_=!!c;return e.jsx(ye,{title:"Coupon Redemptions",subtitle:"",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(u,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(Ss,{to:"/admin-dashboard/coupons",children:[e.jsx(ct,{className:"w-4 h-4 mr-1"})," Back to Coupons"]})})}),i&&e.jsx("div",{className:"flex justify-center items-center h-48",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),_&&e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Failed to load redemptions."}),r&&e.jsxs(e.Fragment,{children:[e.jsx(W,{children:e.jsx(se,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"w-4 h-4 text-indigo-500"}),r.name]}),e.jsxs(je,{className:"mt-1",children:["Code: ",e.jsx("span",{className:"font-mono font-semibold",children:r.code})," · ",r.type==="percentage"?`${r.amount}% off`:Qa(r.amount)]})]}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-muted",children:[e.jsx("div",{className:"text-2xl font-bold",children:r.used_count??o.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Uses"})]}),r.usage_limit&&e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-muted",children:[e.jsx("div",{className:"text-2xl font-bold",children:r.usage_limit}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Global Limit"})]}),r.max_uses_per_organization&&e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-muted",children:[e.jsx("div",{className:"text-2xl font-bold",children:r.max_uses_per_organization}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Per Org Limit"})]}),e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-muted",children:[e.jsx("div",{className:"text-2xl font-bold",children:(l==null?void 0:l.total)??o.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Redemptions"})]})]})]})})}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Redemption Records"}),e.jsx(je,{children:"All successful orders where this coupon was applied"})]}),e.jsx(Q,{children:o.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(la,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No redemptions recorded yet."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Package"}),e.jsx(T,{className:"text-right",children:"Original"}),e.jsx(T,{className:"text-right",children:"Discount"}),e.jsx(T,{className:"text-right",children:"Paid"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Date"})]})}),e.jsx(Ue,{children:o.map(g=>{var b,P,z;return e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:((b=g.organization)==null?void 0:b.name)??"-"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:(P=g.organization)==null?void 0:P.login_email})]})]})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ia,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:((z=g.subscription_package)==null?void 0:z.name)??"-"})]})}),e.jsx(C,{className:"text-right",children:Qa(g.price)}),e.jsxs(C,{className:"text-right text-emerald-600 font-medium",children:["-",Qa(g.discount)]}),e.jsx(C,{className:"text-right font-semibold",children:Qa(g.total)}),e.jsx(C,{children:e.jsx(ee,{variant:g.status==="completed"||g.status==="paid"?"default":"secondary",children:g.status})}),e.jsx(C,{className:"text-sm text-muted-foreground whitespace-nowrap",children:new Date(g.created_at).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})]},g.id)})})]})}),l&&l.last_page>1&&e.jsxs("div",{className:"flex justify-end items-center gap-2 mt-4",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:s<=1,onClick:()=>t(g=>g-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",l.current_page," of ",l.last_page]}),e.jsx(u,{variant:"outline",size:"sm",disabled:s>=l.last_page,onClick:()=>t(g=>g+1),children:"Next"})]})]})})]})]})]})})}function $d(a,s,t){const n=t==="monthly"?(a==null?void 0:a.list_price_monthly)??(s==null?void 0:s.monthly_price)??0:(a==null?void 0:a.list_price_yearly)??(s==null?void 0:s.yearly_price)??0;if(!a)return{listPrice:n,baseAmount:n,finalAmount:n,couponApplied:!1,couponCode:null,couponDiscount:0,packageDiscountApplied:!1,packageDiscountPct:0};const i=a.payment_frequency===t;return{listPrice:n,baseAmount:i?a.base_amount:n,finalAmount:i?a.final_amount:n,couponApplied:i&&a.coupon_applied,couponCode:i?a.coupon_code:null,couponDiscount:i?a.coupon_discount_amount:0,packageDiscountApplied:i&&a.package_discount_applied,packageDiscountPct:i?a.package_discount_percentage:0}}function dn({open:a,onOpenChange:s,license:t,mode:n="renewal",onSuccess:i}){var y;const[c,r]=m.useState(t.payment_frequency??"monthly"),[o,l]=m.useState(""),[_,h]=m.useState(""),[N,g]=m.useState(!1),[b,P]=m.useState(""),[z,p]=m.useState(""),[M,A]=m.useState(""),[O,{isLoading:k}]=Vo(),[j,{isLoading:S}]=Ko(),d=n==="unlock",L=k||S,I=m.useMemo(()=>$d(t.renewal_pricing,t.package,c),[t.renewal_pricing,t.package,c]);m.useEffect(()=>{a&&(r(t.payment_frequency??"monthly"),g(!1),h(""))},[a,t.id,t.payment_frequency]),m.useEffect(()=>{N||h(I.finalAmount.toFixed(2))},[I.finalAmount,N]);const B=async()=>{var K;if(!o.trim()){v.error("Please specify a payment method");return}const F=N&&_?parseFloat(_):I.finalAmount;if(!F||F<=0){v.error("Please specify a valid payment amount");return}try{if(d){const q=await j({licenseId:t.id,payment_method:o,payment_amount:F,payment_reference:b||void 0,payment_date:z||void 0,notes:M||void 0,apply_coupon:!N}).unwrap();v.success(q.message||"License unlocked successfully")}else{const q=await O({licenseId:t.id,payment_frequency:c,...N?{amount:F}:{},notes:M||void 0,apply_coupon:!N}).unwrap();v.success(q.message||"License renewed successfully")}s(!1),l(""),h(""),P(""),p(""),A(""),g(!1),i==null||i()}catch(q){v.error(((K=q==null?void 0:q.data)==null?void 0:K.message)||`Failed to ${d?"unlock":"renew"} license`)}};return e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"sm:max-w-[540px]",children:[e.jsxs(Ee,{children:[e.jsx(De,{className:"flex items-center gap-2",children:d?e.jsxs(e.Fragment,{children:[e.jsx(En,{className:"h-5 w-5 text-orange-600"}),"Unlock License - Manual Payment"]}):"Manual License Renewal"}),e.jsx(Ge,{children:d?`Process manual payment and unlock ${t.organization.name}`:`Renew subscription for ${t.organization.name}`})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"rounded-lg border bg-muted/40 p-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Organization"}),e.jsx("span",{className:"font-medium text-right",children:t.organization.name})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Email"}),e.jsx("span",{className:"text-right",children:t.organization.email})]})]}),e.jsxs("div",{className:"rounded-lg border p-3 space-y-2 bg-green-50/50 dark:bg-green-950/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(la,{className:"h-4 w-4"}),"Renewal pricing"]}),I.packageDiscountApplied&&e.jsxs("p",{className:"text-xs text-green-700",children:["Package discount: ",I.packageDiscountPct,"% applied"]}),(I.listPrice>I.baseAmount||I.couponApplied)&&e.jsxs("p",{className:"text-sm line-through text-muted-foreground",children:["List: £",I.listPrice.toFixed(2)]}),I.baseAmount<I.listPrice&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["After package discount: £",I.baseAmount.toFixed(2)]}),e.jsxs("p",{className:"text-lg font-semibold text-green-700",children:["Amount due: £",I.finalAmount.toFixed(2)]}),I.couponApplied&&I.couponCode?e.jsxs(ee,{variant:"outline",className:"text-green-700 border-green-300",children:["Coupon ",I.couponCode," (â£",I.couponDiscount.toFixed(2),")"]}):((y=t.renewal_pricing)==null?void 0:y.applicable_coupon_count)===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No valid org coupon for this renew
2al"}):null]}),!d&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"frequency",className:"flex items-center gap-2",children:[e.jsx(Rs,{className:"h-4 w-4"}),"Billing Frequency"]}),e.jsxs(ke,{value:c,onValueChange:F=>r(F),children:[e.jsx(Se,{id:"frequency",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"monthly",children:"Monthly"}),e.jsx(X,{value:"yearly",children:"Yearly"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"payment-method",className:"flex items-center gap-2",children:[e.jsx($s,{className:"h-4 w-4"}),"Payment Method ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(ke,{value:o,onValueChange:l,children:[e.jsx(Se,{id:"payment-method",children:e.jsx(Ae,{placeholder:"Select payment method"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"bank_transfer",children:"Bank Transfer"}),e.jsx(X,{value:"check",children:"Check / Cheque"}),e.jsx(X,{value:"cash",children:"Cash"}),e.jsx(X,{value:"card",children:"Credit/Debit Card"}),e.jsx(X,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(x,{htmlFor:"payment-amount",className:"flex items-center gap-2",children:[e.jsx(Ya,{className:"h-4 w-4"}),"Payment Amount"]}),e.jsx(u,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>g(F=>!F),children:N?"Use calculated amount":"Override amount"})]}),e.jsx(E,{id:"payment-amount",type:"number",step:"0.01",value:_,onChange:F=>{g(!0),h(F.target.value)},disabled:!N&&!d}),!N&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Coupon and package discounts are applied automatically."})]}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"payment-reference",className:"flex items-center gap-2",children:[e.jsx(Yl,{className:"h-4 w-4"}),"Payment Reference (Optional)"]}),e.jsx(E,{id:"payment-reference",placeholder:"e.g., Transaction ID, Check number",value:b,onChange:F=>P(F.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"payment-date",className:"flex items-center gap-2",children:[e.jsx(Rs,{className:"h-4 w-4"}),"Payment Date (Optional)"]}),e.jsx(E,{id:"payment-date",type:"date",value:z,onChange:F=>p(F.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"notes",className:"flex items-center gap-2",children:[e.jsx(da,{className:"h-4 w-4"}),"Notes (Optional)"]}),e.jsx(Ce,{id:"notes",value:M,onChange:F=>{if(F.target.value.length>1e3){v.error("Notes cannot exceed 1000 characters");return}A(F.target.value)},rows:3}),e.jsxs("div",{className:"text-xs text-muted-foreground text-right",children:[M.length," / 1000"]})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>s(!1),disabled:L,children:"Cancel"}),e.jsx(u,{onClick:B,disabled:L||!o.trim(),className:d?"bg-orange-600 hover:bg-orange-700":"",children:L?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),d?"Unlocking...":"Renewing..."]}):d?e.jsxs(e.Fragment,{children:[e.jsx(En,{className:"mr-2 h-4 w-4"}),"Confirm Unlock"]}):"Confirm Renewal"})]})]})})}function Bd(){const a=Vs(),[s,t]=m.useState(""),[n,i]=m.useState("all"),[c,r]=m.useState(!1),[o,l]=m.useState("renewal"),[_,h]=m.useState(null),N=k=>{const j=k.renewal_pricing;if(!j){const S=k.payment_frequency==="yearly"?k.package.yearly_price:k.package.monthly_price;return{label:`£${Number(S).toFixed(2)}`,hasDiscount:!1}}return{label:`£${j.final_amount.toFixed(2)}`,hasDiscount:j.final_amount<j.list_price,list:j.list_price,coupon:j.coupon_applied?j.coupon_code:null,couponDiscount:j.coupon_discount_amount,packageDiscount:j.package_discount_applied}},{data:g,isLoading:b,error:P,refetch:z}=Ei({status:n,search:s},{refetchOnMountOrArgChange:!0});P&&v.error("Failed to load licenses. Please try again.");const p=(g==null?void 0:g.licenses)||[],M=(g==null?void 0:g.statistics)||{total:0,active:0,expiring_soon:0,expired:0,pending_payment:0,free_plan:0},A=(k,j)=>{if(j==="pending")return e.jsxs(ee,{className:"bg-orange-500 hover:bg-orange-600",children:[e.jsx(Oe,{className:"w-3 h-3 mr-1"}),"Payment Pending"]});switch(k){case"active":return e.jsxs(ee,{className:"bg-green-500 hover:bg-green-600",children:[e.jsx(Ot,{className:"w-3 h-3 mr-1"}),"Active"]});case"expiring_soon":return e.jsxs(ee,{className:"bg-yellow-500 hover:bg-yellow-600",children:[e.jsx(zs,{className:"w-3 h-3 mr-1"}),"Expiring Soon"]});case"expired":return e.jsxs(ee,{variant:"destructive",children:[e.jsx(oa,{className:"w-3 h-3 mr-1"}),"Expired"]});case"suspended":return e.jsxs(ee,{variant:"destructive",className:"bg-red-700",children:[e.jsx(Oe,{className:"w-3 h-3 mr-1"}),"Suspended"]});case"free_plan":return e.jsxs(ee,{variant:"outline",className:"bg-blue-100 text-blue-700",children:[e.jsx(Ot,{className:"w-3 h-3 mr-1"}),"Free Plan"]});default:return e.jsx(ee,{variant:"secondary",children:k})}},O=()=>{const k=[["Organization","Email","Package","Renewal Price","Coupon","Status","Expires At","Days Remaining"],...p.map(L=>{const I=N(L);return[L.organization.name,L.organization.email,L.package.name,I.label,I.
2coupon??"None",L.status,L.expires_at?us(new Date(L.expires_at),"MMM d, yyyy"):"N/A",L.days_remaining==null?"N/A":`${L.days_remaining}`]})].map(L=>L.join(",")).join(` 3`),j=new Blob([k],{type:"text/csv"}),S=window.URL.createObjectURL(j),d=document.createElement("a");d.href=S,d.download=`licenses-${us(new Date,"yyyy-MM-dd")}.csv`,d.click(),v.success("Licenses exported successfully")};return e.jsx(ye,{title:"All Licenses",subtitle:"",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"License Management"}),e.jsx("p",{className:"text-muted-foreground",children:"View and manage all organization licenses"})]}),e.jsxs(W,{className:"mb-6",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Filters"}),e.jsx(je,{children:"Search and filter licenses"})]}),e.jsx(Q,{children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(E,{placeholder:"Search by organization name or email...",value:s,onChange:k=>t(k.target.value),className:"pl-10"})]})}),e.jsxs(ke,{value:n,onValueChange:k=>i(k),children:[e.jsxs(Se,{className:"w-full md:w-48",children:[e.jsx(fa,{className:"w-4 h-4 mr-2"}),e.jsx(Ae,{placeholder:"Filter by status"})]}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All Statuses"}),e.jsx(X,{value:"active",children:"Active"}),e.jsx(X,{value:"expiring_soon",children:"Expiring Soon"}),e.jsx(X,{value:"expired",children:"Expired"}),e.jsx(X,{value:"suspended",children:"Suspended"}),e.jsx(X,{value:"pending_payment",children:"ð Locked/Pending Payment"}),e.jsx(X,{value:"free_plan",children:"Free Plan"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",onClick:()=>z(),disabled:b,children:[e.jsx(Es,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),"Refresh"]}),e.jsxs(u,{variant:"outline",onClick:O,disabled:p.length===0,children:[e.jsx(ma,{className:"w-4 h-4 mr-2"}),"Export"]})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-4 mb-6",children:[e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total Licenses"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:M.total})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Active"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:M.active})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Expiring Soon"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:M.expiring_soon})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Expired"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:M.expired})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Free Plan"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:M.free_plan||0})})]}),e.jsxs(W,{className:"col-span-2 sm:col-span-1",children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"ð Locked"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-orange-600",children:M.pending_payment||0})})]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsxs(ae,{children:["All Licenses (",p.length,")"]}),e.jsx(je,{children:"Complete list of organization licenses and their status"})]}),e.jsx(Q,{children:b?e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{className:"min-w-[200px]",children:"Organization"}),e.jsx(T,{className:"min-w-[150px]",children:"Package"}),e.jsx(T,{className:"min-w-[140px]",children:"Renewal Price"}),e.jsx(T,{className:"min-w-[120px]",children:"Coupon"}),e.jsx(T,{className:"min-w-[150px]",children:"Status"}),e.jsx(T,{className:"min-w-[100px]",children:"Billing"}),e.jsx(T,{className:"min-w-[120px]",children:"Expires At"}),e.jsx(T,{className:"min-w-[120px]",children:"Days Remaining"}),e.jsx(T,{className:"text-right min-w-[180px]",children:"Actions"})]})}),e.jsx(Ue,{children:p.length===0?e.jsx(le,{children:e.jsx(C,{colSpan:9,className:"text-center py-8",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Oe,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"No licenses found"})]})})}):p.map(k=>{var S;const j=N(k);return e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:k.organization.name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:k.organization.email})]})}),e.jsxs(C,{children:[e.jsx("div",{className:"font-medium",children:k.package.name}),e.jsxs("div",{className:"text-xs text-muted-foreground capitalize",children:[k.payment_frequency," · list £",k.payment_frequency==="yearly"?k.package.yearly_price:k.package.monthly_price]})]}),e.jsxs(C,{children:[e.jsx("div",{className:"font-medium text-green-700",children:j.label}),j.hasDiscount&&j.list!=null&&e.jsxs("div",{className:"text-xs line-through text-muted-foreground",children:["£",j.list.toFixed(2)]}),j.packageDiscount&&e.jsx("div",{className:"text-xs text-green-600",children:"Package discount"})]}),e.jsx(C,{children:j.coupon?e.jsxs(ee,{variant:"outline",className:"text-green-700 border-green-300 font-mono text-xs",children:[j.coupon,j.c
3ouponDiscount!=null&&j.couponDiscount>0&&e.jsxs("span",{className:"ml-1 font-sans",children:["â£",j.couponDiscount.toFixed(2)]})]}):(S=k.renewal_pricing)!=null&&S.applicable_coupon_count?e.jsx("span",{className:"text-xs text-muted-foreground",children:"No auto coupon"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"-"})}),e.jsx(C,{children:A(k.status,k.payment_status)}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",className:"capitalize",children:k.payment_frequency})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Rs,{className:"h-4 w-4 text-muted-foreground"}),k.expires_at?e.jsx(e.Fragment,{children:us(new Date(k.expires_at),"MMM d, yyyy")}):e.jsx(e.Fragment,{children:e.jsx("span",{children:"N/A"})})]})}),e.jsx(C,{children:(()=>{const d=k.days_remaining,I=k.status==="free_plan"||d==null,B=I?"text-muted-foreground":d>14?"text-green-600":d>0?"text-yellow-600":"text-red-600",y=I?"N/A":d>=0?`${d} day${d!==1?"s":""}`:"Expired";return e.jsx("span",{className:B,children:y})})()}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex gap-2 justify-end flex-wrap",children:[e.jsxs(u,{variant:"ghost",size:"sm",onClick:()=>a(`/admin-dashboard/licenses/${k.id}`),children:[e.jsx(Fs,{className:"w-4 h-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"View"})]}),k.payment_status==="pending"?e.jsxs(u,{variant:"default",size:"sm",className:"bg-orange-600 hover:bg-orange-700",onClick:()=>{h({id:k.id,name:k.organization.name,email:k.organization.email,payment_frequency:k.payment_frequency,package:{monthly_price:k.package.monthly_price,yearly_price:k.package.yearly_price},renewal_pricing:k.renewal_pricing}),l("unlock"),r(!0)},children:[e.jsx(Oe,{className:"w-4 h-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Unlock"})]}):e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>{h({id:k.id,name:k.organization.name,email:k.organization.email,payment_frequency:k.payment_frequency,package:{monthly_price:k.package.monthly_price,yearly_price:k.package.yearly_price},renewal_pricing:k.renewal_pricing}),l("renewal"),r(!0)},children:[e.jsx($s,{className:"w-4 h-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Renew"})]})]})})]},k.id)})})]})})})]}),_&&e.jsx(dn,{open:c,onOpenChange:r,license:{id:_.id,organization:{name:_.name,email:_.email},package:_.package,payment_frequency:_.payment_frequency,renewal_pricing:_.renewal_pricing},mode:o,onSuccess:()=>z()})]})})}function Ud(){const a=Vs(),[s,t]=m.useState(""),[n,i]=m.useState(!1),[c,r]=m.useState(!1),[o,l]=m.useState(null),[_,h]=m.useState("30"),{data:N,isLoading:g,refetch:b}=$o({search:s}),[P,{isLoading:z}]=Di(),[p,{isLoading:M}]=Go(),A=(N==null?void 0:N.licenses)||[],O=(N==null?void 0:N.statistics)||{total_expired:0,grace_period:0,suspended:0},k=async(d,L)=>{try{await P(d).unwrap(),v.success(`Reminder email sent to ${L}`),b()}catch(I){v.error("Failed to send reminder email"),console.error(I)}},j=(d,L,I)=>{l({id:d,name:L,email:I}),i(!0)},S=async()=>{if(o)try{await p({licenseId:o.id,additional_days:parseInt(_)}).unwrap(),v.success(`Grace period extended for ${o.name}`),i(!1),l(null),h("30"),b()}catch(d){v.error("Failed to extend grace period"),console.error(d)}};return e.jsx(ye,{title:"Expiring Lisences",subtitle:"",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Expired Licenses"}),e.jsx("p",{className:"text-muted-foreground",children:"Organizations with expired subscriptions"})]}),e.jsx(W,{className:"mb-6 border-red-500 bg-red-50 dark:bg-red-950",children:e.jsx(Q,{className:"",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oe,{className:"h-5 w-5 text-red-600 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h3",{className:"font-semibold text-red-900 dark:text-red-100",children:[A.length," Organization",A.length!==1?"s":""," with Expired Licenses"]}),e.jsx("p",{className:"text-sm text-red-800 dark:text-red-200 mt-1",children:"These organizations have lost access to their accounts and need to renew their subscriptions."})]})]})})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 mb-6",children:[e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total Expired"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:O.total_expired})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Within Grace Period"})}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-2xl font-bold text-orange-600",children:O.grace_peri
3od}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"⤠30 days expired"})]})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Suspended"})}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-2xl font-bold text-red-700",children:O.suspended}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"> 30 days expired"})]})]})]}),e.jsxs(W,{className:"mb-6",children:[e.jsx(se,{children:e.jsx(ae,{children:"Search"})}),e.jsx(Q,{children:e.jsxs("div",{className:"relative",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(E,{placeholder:"Search by organization name or email...",value:s,onChange:d=>t(d.target.value),className:"pl-10"})]})})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsxs(ae,{children:["Expired Licenses (",A.length,")"]}),e.jsx(je,{children:"Organizations sorted by days since expiration (oldest first)"})]}),e.jsx(Q,{children:g?e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"rounded-md border",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Expired At"}),e.jsx(T,{children:"Days Expired"}),e.jsx(T,{children:"Reminder"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:A.length===0?e.jsx(le,{children:e.jsx(C,{colSpan:6,className:"text-center py-8",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Oe,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"No expired licenses found"})]})})}):A.map(d=>e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:d.organization.name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:d.organization.email})]})}),e.jsx(C,{children:d.status==="suspended"?e.jsxs(ee,{variant:"destructive",className:"bg-red-700",children:[e.jsx(Oe,{className:"w-3 h-3 mr-1"}),"Suspended"]}):e.jsxs(ee,{variant:"destructive",children:[e.jsx(oa,{className:"w-3 h-3 mr-1"}),"Expired"]})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}),us(new Date(d.expires_at),"MMM d, yyyy")]})}),e.jsxs(C,{children:[e.jsxs("span",{className:d.days_expired>30?"text-red-700 font-semibold":"text-red-600",children:[Math.floor(d.days_expired)," days ago"]}),d.days_expired>30&&e.jsx("div",{className:"text-xs text-red-700",children:"Beyond grace period"})]}),e.jsx(C,{children:d.reminder_sent?e.jsxs("div",{className:"text-sm",children:[e.jsxs(ee,{variant:"outline",className:"mb-1",children:[e.jsx(ms,{className:"w-3 h-3 mr-1"}),"Sent"]}),d.last_reminder&&e.jsx("div",{className:"text-xs text-muted-foreground",children:us(new Date(d.last_reminder),"MMM d")})]}):e.jsx(Jl,{children:e.jsxs(Xl,{children:[e.jsx(Zl,{asChild:!0,children:e.jsxs(ee,{variant:"secondary",className:"cursor-help gap-1",children:["Not sent",e.jsx(ga,{className:"w-3 h-3"})]})}),e.jsx(ec,{side:"top",className:"max-w-xs",children:e.jsxs("p",{className:"text-xs",children:["No reminder email has been sent to this organization yet.",d.days_expired>30?" This account is beyond the grace period - consider sending a reminder or escalating.":' Click "Reminder" to notify them about their expired subscription.']})})]})})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsxs(u,{variant:"ghost",size:"sm",onClick:()=>a(`/admin-dashboard/licenses/${d.id}`),children:[e.jsx(Fs,{className:"w-4 h-4 mr-1"}),"View"]}
3),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>k(d.id,d.organization.name),disabled:z,children:[e.jsx(ms,{className:"w-4 h-4 mr-1"}),"Reminder"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>{l({id:d.id,name:d.organization.name,email:d.organization.email,package:{monthly_price:d.package.monthly_price,yearly_price:d.package.yearly_price}}),r(!0)},children:[e.jsx($s,{className:"w-4 h-4 mr-1"}),"Renew"]}),d.status!=="suspended"&&e.jsx(u,{variant:"outline",size:"sm",onClick:()=>j(d.id,d.organization.name,d.organization.email),children:"Extend Grace"})]})})]},d.id))})]})})})]}),e.jsx(Fe,{open:n,onOpenChange:i,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Extend Grace Period"}),e.jsxs(Ge,{children:["Extend the grace period for ",o==null?void 0:o.name]})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"days",children:"Additional Days"}),e.jsx(E,{id:"days",type:"number",min:"1",max:"90",value:_,onChange:d=>h(d.target.value),placeholder:"Enter number of days (1-90)"})]})}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(u,{onClick:S,disabled:M,children:M?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Extending..."]}):"Confirm"})]})]})}),o&&e.jsx(dn,{open:c,onOpenChange:r,license:{id:o.id,organization:{name:o.name,email:o.email},package:o.package},onSuccess:()=>b()})]})})}const Qn=["#2563eb","#16a34a","#ea580c","#dc2626","#0891b2","#7c3aed","#db2777"],St=a=>new Intl.NumberFormat("en-GB",{style:"currency",currency:"GBP",minimumFractionDigits:2,maximumFractionDigits:2}).format(a);function Kn(){const a=new Date().getFullYear(),[s,t]=m.useState(a),[n,{isLoading:i}]=Uo(),c=async()=>{try{const P=await n({year:s}).unwrap(),z=window.URL.createObjectURL(P),p=document.createElement("a");p.href=z,p.download=`revenue-report-${s}.pdf`,document.body.appendChild(p),p.click(),p.remove(),window.URL.revokeObjectURL(z)}catch{alert("Failed to download report. Please try again.")}},{data:r,isLoading:o,error:l,refetch:_}=Bo({year:s}),h=m.useMemo(()=>r!=null&&r.available_years&&r.available_years.length>0?r.available_years:[s],[r==null?void 0:r.available_years,s]),N=(r==null?void 0:r.revenue_by_month)??[],g=((r==null?void 0:r.revenue_by_package)??[]).filter(P=>P.revenue>0),b=(r==null?void 0:r.total_earned_revenue)??0;return o?e.jsx(ye,{title:"Revenue Analytics",subtitle:"",children:e.jsx("div",{className:"flex justify-center items-center h-96",children:e.jsx(ce,{className:"h-10 w-10 animate-spin text-muted-foreground"})})}):l?e.jsx(ye,{title:"Revenue Analytics",subtitle:"",children:e.jsxs("div",{className:"flex flex-col items-center justify-center h-96 gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Failed to load revenue analytics."}),e.jsxs(u,{variant:"outline",onClick:()=>_(),className:"gap-2",children:[e.jsx(Dn,{className:"w-4 h-4"})," Retry"]})]})}):e.jsx(ye,{title:"Revenue Analytics",subtitle:"",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Revenue Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(r==null?void 0:r.revenue_source)==="active_subscriptions_fallback"?"Showing subscription projection (no paid orders found for selected year)":`Actual earned revenue from completed payments (${(r==null?void 0:r.completed_payments_count)??0} payments)`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"year-filter",className:"text-sm text-muted-foreground",children:"Year"}),e.jsx("select",{id:"year-filter",className:"h-9 rounded-md border bg-background px-3 text-sm",value:s,onChange:P=>t(Number(P.target.value)),children:h.map(P=>e.jsx("option",{value:P,children:P},P))}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>_(),className:"gap-2",children:[e.jsx(Dn,{className:"w-4 h-4"})," Refresh"]}),e.jsxs(u,{size:"sm",onClick:c,disabled:i,className:"gap-2",children:[e.jsx(ma,{className:"w-4 h-4"}),i?"Generatingâ¦":"Download PDF"]})]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Total Earned Revenue"}),e.jsxs(je,{children:["Completed payment totals for ",(r==null?void 0:r.year)??s]})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-4xl font-bold",children:St(b)}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:["Completed payments: ",(r==null?void 0:r.completed_payments_count)??0]})]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Monthly Revenue"}),e.jsx(je,{children:"Year-filtered month-wise earned revenue"})]}),e.jsx(Q,{children:N.length===0?e.jsx("div",{className:"h-72 flex items-center justify-center text-muted-foreground text-sm",children:"No monthly data for selected year."}):e.jsx(Ma,{width:"100%",height:300,children:e.jsxs(Ut,{data:N,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(at,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(La,{dataKey:"month",tick:{fontSize:12}}),e.jsx(ja,{tickFormatter:P=>`£${P}`,tick:{fontSize:11},width:70}),e.jsx(qa,{formatter:P=>St(P)}),e.jsx(Gt,{dataKey:"revenue",radius:[4,4,0,0],fill:"#2563eb"})]})})})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Subscription-wise Revenue"}),e.jsx(je,{children:"Revenue split by package"})]}),e.jsx(Q,{children:g.length===0?e.jsx("div",{className:"h-72 flex items-center justify-center text-muted-foreground text-sm",children:"No package revenue for selected year."}):e.jsx(Ma,{width:"100%",height:320,children:e.jsxs(Ut,{data:g,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(at,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(La,{dataKey:"name",tick:{fontSize:12}}),e.jsx(ja,{tickFormatter:P=>`£${P}`,tick:{fontSize:11},width:70}),e.jsx(qa,{formatter:(P,z,p)=>{var M;return[St(P),`${((M=p==null?void 0:p.payload)==null?void 0:M.orders)??0} orders`]}}),e.jsx(Gt,{dataKey:"revenue",radius:[4,4,0,0],children:g.map((P,z)=>e.jsx(Ni,{fill:Qn[z%Qn.length]},z))})]})})})]})]})})}function Gd(){var j;const{licenseId:a}=mi(),s=Vs(),[t,n]=m.useState(!1),{data:i,isLoading:c,error:r,refetch:o}=Qo(a||"",{skip:!a,refetchOnMountOrArgChange:!0}),[l,{isLoading:_}]=Di();if(!a)return e.jsx(ye,{title:"License Details",subtitle:"",children:e.jsx("div",{className:"p-4",children:e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Oe,{className:"mx-auto h-12 w-12 text-red-500 mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Invalid License ID"}),e.jsx(u,{onClick:()=>s("/admin-dashboard/licenses"),children:"Back to Licenses"})]})})})})});if(c)return e.jsx(ye,{title:"License Details",subtitle:"",children:e.jsx("div",{className:"flex justify-center items-center py-24",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})})});if(r||!i)return e.jsx(ye,{title:"License Details",subtitle:"",children:e.jsx("div",{className:"p-4",children:e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Oe,{className:"mx-auto h-12 w-12 text-red-500 mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Unable to Load License"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:((j=r==null?void 0:r.data)==null?void 0:j.error)||"An error occurred while loading license details."}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsx(u,{variant:"outline",onClick:()=>s("/admin-dashboard/licenses"),children:"Back to Licenses"}),e.jsx(u,{onClick:()=>o(),children:"Retry"})]})]})})})})});const{license:h}=i,N=h.renewal_pricing,g=(N==null?void 0:N.applicable_coupons)??[],b=N!=null&&N.coupon_applied?N.coupon_code:null,P=g.filter(S=>S.coupon_code!==b),z=N?N.list_price:h.payment_frequency==="yearly"?h.package.yearly_price:h.package.monthly_price,p=(N==null?void 0:N.final_amount)??z,M=h.package.max_employees!=null&&Number(h.package.max_employees)>0&&Number(h.package.max_employees)<9999?String(h.package.max_employees):"Unlimited",A=S=>{switch(S){case"active":return e.jsxs(ee,{className:"bg-green-500 hover:bg-green-600",children:[e.jsx(Ot,{className:"w-3 h-3 mr-1"}),"Active"]});case"expiring_soon":return e.jsxs(ee,{className:"bg-yellow-500 hover:bg-yellow-600",children:[e.jsx(zs,{className:"w-3 h-3 mr-1"}),"Expiring Soon"]});case"expired":return e.jsxs(ee,{variant:"destructive",children:[e.jsx(oa,{className:"w-3 h-3 mr-1"}),"Expired"]});case"suspended":return e.jsxs(ee,{variant:"destructive",className:"bg-red-700",children:[e.jsx(Oe,{className:"w-3 h-3 mr-1"}),"Suspended"]});default:return e.jsx(ee,{variant:"secondary",children:S})}},O=async()=>{try{await l(a).unwrap(),v.success(`Reminder email sent to ${h.organization.name}`),o()}catch(S){v.error("Failed to send reminder email"),console.error(S)}},k=()=>{const S=[["Date","Description","Amount","Currency","Coupon","Discount","Status","Payment Method","Invoice","Reference"],...h.payment_history.map(B=>[us(new Date(B.created_at),"MMM d, yyyy"),B.description??"",B.amount.toString(),B.currency,B.coupon_code??"",B.discount_amount!=null?B.discount_amount.toString():"",B.status,B.payment_method,B.invoice_number??"",B.stripe_payment_intent_id??B.stripe_session_id??B.id])].map(B=>B.join(",")).join(` 4`),d=new Blob([S],{type:"text/csv"}),L=window.URL.createObjectURL(d),I=document.createElement("a");I.href=L,I.download=`${h.organization.name}-payments-${us(new Date,"yyyy-MM-dd")}.csv`,I.click(),v.success("Payment history exported")};return e.jsx(ye,{title:"License Details",subtitle:"",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:h.organization.name}),e.jsx("p",{className:"text-muted-foreground",children:"License Details"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",onClick:()=>s("/admin-dashboard/licenses"),children:[e.jsx(ct,{}),"Back to Licenses"]}),e.jsxs(u,{variant:"outline",onClick:()=>o(),children:[e.jsx(Es,{className:"h-4 w-4 mr-2"}),"Refresh"]}),e.jsx(u,{onClick:()=>n(!0),children:"Manual Renewal"})]})]}),(h.status==="expired"||h.status==="suspended")&&e.jsx(W,{className:"border-red-500 bg-red-50 dark:bg-red-950",children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oe,{className:"h-5 w-5 text-red-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h3",{className:"font-semibold text-red-900 dark:text-red-100",children:["License ",h.status==="suspended"?"Suspended":"Expired"]}),e.jsx("p",{className:"text-sm text-red-800 dark:text-red-200 mt-1",children:"This organization has lost access. Consider sending a reminder or manually renewing their license."}),e.jsx(u,{onClick:O,className:"mt-3",size:"sm",disabled:_,children:_?"Sending...":"Send Reminder Email"})]})]})})}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(sc,{className:"h-5 w-5"}),"Organization Information"]})}),e.jsxs(Q,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Email:"}),e.jsx("span",{className:"text-sm font-medium",children:h.organization.email})]}),h.organization.phone&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Phone:"}),e.jsx("span",{className:"text-sm font-medium",children:h.organization.phone})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Total Employees:"}),e.jsxs("span",{className:"text-sm font-bold",children:[h.organization.employee_count??0," / ",M]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Organization ID:"}),e.jsx("code",{className:"text-xs bg-muted px-2 py-1 rounded",children:h.organization.id})]})]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx($s,{className:"h-5 w-5"}),"License Status"]}),A(h.status)]})}),e.jsxs(Q,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"License ID:"}),e.jsx("code",{className:"text-xs bg-muted px-2 py-1 rounded",children:h.id})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Starts At:"}),e.jsx("span",{className:"text-sm font-medium",children:us(new Date(h.starts_at),"MMM d, yyyy")})]}),h.expires_at&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Expires At:"}),e.jsx("span",{className:"text-sm font-medium",children:us(new Date(h.expires_at),"MMM d, yyyy")})]}),h.days_remaining!=null&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Days Remaining:"}),e.jsx("span",{className:`text-sm font-medium ${h.days_remaining>14?"text-green-600":h.days_remaining>0?"text-yellow-600":"text-red-600"}`,children:h.days_remaining>0?`${h.days_remaining} days`:`${Math.abs(h.days_remaining)} days ago`})]}),h.payment_status&&e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Payment Status:"}),e.jsx(ee,{variant:"outline",className:"capitalize",children:h.payment_status})]})]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(ia,{className:"h-5 w-5"}),"Package Details"]}
4)}),e.jsxs(Q,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:h.package.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:h.package.description})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Monthly Price:"}),e.jsxs("p",{className:"text-lg font-bold",children:["£",h.package.monthly_price]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Yearly Price:"}),e.jsxs("p",{className:"text-lg font-bold",children:["£",h.package.yearly_price]})]})]}),h.package.max_employees!=null&&e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Max Employees:"}),e.jsx("span",{className:"text-sm font-medium",children:M})]}),h.package.max_storage_mb&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Max Storage:"}),e.jsxs("span",{className:"text-sm font-medium",children:[h.package.max_storage_mb," MB"]})]})]})]}),e.jsxs(W,{className:"md:col-span-1 border-green-200 dark:border-green-900",children:[e.jsxs(se,{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-5 w-5 text-green-600"}),"Renewal Pricing"]}),e.jsxs(je,{children:["Next renewal for"," ",e.jsx(ee,{variant:"outline",className:"capitalize ml-1",children:h.payment_frequency})," ","billing"]})]}),e.jsxs(Q,{children:[e.jsxs("div",{className:"max-w-lg space-y-3 rounded-lg border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["List price (",h.payment_frequency,")"]}),e.jsxs("span",{children:["£",Number(z).toFixed(2)]})]}),N!=null&&N.package_discount_applied?e.jsxs("div",{className:"flex justify-between text-sm text-green-700",children:[e.jsxs("span",{children:["Package discount (",N.package_discount_percentage,"%)"]}),e.jsxs("span",{children:["â£",(z-N.base_amount).toFixed(2)]})]}):null,N!=null&&N.coupon_applied&&N.coupon_code?e.jsxs("div",{className:"flex justify-between text-sm text-green-700",children:[e.jsxs("span",{children:["Coupon"," ",e.jsx(ee,{variant:"outline",className:"font-mono text-green-700 border-green-300 ml-1",children:N.coupon_code})]}),e.jsxs("span",{children:["â£",N.coupon_discount_amount.toFixed(2)]})]}):null,e.jsxs("div",{className:"flex justify-between border-t pt-3 font-semibold text-green-700",children:[e.jsx("span",{children:"Amount due on renewal"}),e.jsxs("span",{className:"text-lg",children:["£",Number(p).toFixed(2)]})]}),h.price!=null&&Number(h.price)!==Number(p)&&e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Last recorded license price"}),e.jsxs("span",{children:["£",Number(h.price).toFixed(2)]})]}),N!=null&&N.coupon_applied?e.jsx("p",{className:"text-xs text-muted-foreground pt-1",children:"Coupon auto-applies on manual renew unless amount is overridden."}):null]}),P.length>0&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Other available coupons"}),P.map(S=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border p-3 text-sm max-w-lg",children:[e.jsxs("div",{children:[e.jsx(ee,{variant:"outline",className:"font-mono",children:S.coupon_code}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:S.coupon_name})]}),e.jsxs("div",{className:"text-right text-green-700",children:[e.jsxs("p",{className:"font-medium",children:["â£",S.discount_amount.toFixed(2)]}),e.jsxs("p",{className:"text-xs",children:["Pays £",S.final_amount.toFixed(2)]})]})]},S.coupon_id))]})]})]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"Payment History"}),e.jsx(je,{children:"Stripe, manual admin, and order payments for this organization"})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:k,disabled:!h.payment_history||h.payment_history.length===0,children:[e.jsx(ma,{className:"h-4 w-4 mr-2"}),"Export"]})]})}),e.jsx(Q,{children:!h.payment_history||h.payment_history.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Oe,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"No payment history available"})]}):e.jsx("div",{className:"rounded-md border",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Date"}),e.jsx(T,{children:"Description"}),e.jsx(T,{children:"Amount"}),e.jsx(T,{children:"Coupon"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Method"}),e.jsx(T,{children:"Invoice"}),e.jsx(T,{children:"Reference"})]})}),e.jsx(Ue,{children:h.payment_history.map(S=>e.jsxs(le,{children:[e.jsx(C,{children:us(new Date(S.created_at),"MMM d, yyyy HH:mm")}
4),e.jsxs(C,{className:"max-w-[200px]",children:[e.jsx("span",{className:"text-sm",children:S.description??"-"}),S.is_manual&&e.jsx(ee,{variant:"outline",className:"ml-1 text-xs",children:"Manual"})]}),e.jsxs(C,{className:"font-medium",children:[S.currency.toUpperCase()," ",S.amount.toFixed(2),S.discount_amount!=null&&S.discount_amount>0&&e.jsxs("div",{className:"text-xs text-green-700",children:["â£",S.discount_amount.toFixed(2)," discount"]})]}),e.jsx(C,{children:S.coupon_code?e.jsx(ee,{variant:"outline",className:"font-mono text-xs",children:S.coupon_code}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(C,{children:e.jsx(ee,{variant:S.status==="succeeded"?"default":"secondary",className:S.status==="succeeded"?"bg-green-500":"",children:S.status})}),e.jsx(C,{className:"capitalize text-sm",children:S.payment_method}),e.jsx(C,{children:S.invoice_url?e.jsxs("a",{href:S.invoice_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-primary hover:underline",children:[S.invoice_number??"View",e.jsx(Si,{className:"h-3 w-3"})]}):S.invoice_number?e.jsx("span",{className:"text-xs font-mono",children:S.invoice_number}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(C,{children:e.jsx("code",{className:"text-xs bg-muted px-2 py-1 rounded break-all",children:S.stripe_payment_intent_id??S.stripe_session_id??S.id})})]},S.id))})]})})})]}),e.jsx(dn,{open:t,onOpenChange:n,license:{id:a,organization:{name:h.organization.name,email:h.organization.email},package:{monthly_price:h.package.monthly_price,yearly_price:h.package.yearly_price},payment_frequency:h.payment_frequency,renewal_pricing:h.renewal_pricing},onSuccess:()=>o()})]})})}const Ta=()=>{var a;return(a=localStorage.getItem("token"))==null?void 0:a.replace(/"/g,"")},Vd=He.injectEndpoints({endpoints:a=>({getOrganizationStats:a.query({query:({search:s,status:t,license_status:n,package_name:i})=>{const c=Ta(),r={};return c&&(r.Authorization=`Bearer ${c}`),{url:"/admin/reports/organizations",method:"GET",params:{search:s,status:t,license_status:n,package_name:i},headers:r}},providesTags:["adminOrganizationStats"]}),downloadOrganizationStatsPdf:a.mutation({query:({search:s,status:t,license_status:n,package_name:i})=>{const c=Ta(),r={};return c&&(r.Authorization=`Bearer ${c}`),r.Accept="application/pdf",{url:"/admin/reports/organizations/pdf",method:"GET",params:{search:s,status:t,license_status:n,package_name:i},headers:r}}}),downloadOrganizationStatsCsv:a.mutation({query:({search:s,status:t,license_status:n,package_name:i})=>{const c=Ta(),r={};return c&&(r.Authorization=`Bearer ${c}`),r.Accept="text/csv",{url:"/admin/reports/organizations/csv",method:"GET",params:{search:s,status:t,license_status:n,package_name:i},headers:r}}}),getRevenueAnalytics:a.query({query:({period:s,start_date:t,end_date:n})=>{const i=Ta(),c={};return i&&(c.Authorization=`Bearer ${i}`),{url:"/admin/reports/revenue",method:"GET",params:{period:s,start_date:t,end_date:n},headers:c}},providesTags:["adminRevenueAnalytics"]}),getSystemActivityMetrics:a.query({query:({period:s})=>{const t=Ta(),n={};return t&&(n.Authorization=`Bearer ${t}`),{url:"/admin/reports/activity",method:"GET",params:{period:s},headers:n}},providesTags:["adminActivityMetrics"]})})}),{useGetOrganizationStatsQuery:Qd,useDownloadOrganizationStatsPdfMutation:Kd,useDownloadOrganizationStatsCsvMutation:Hd}=Vd;function Wd(){const[a,s]=m.useState(""),[t,n]=m.useState("all"),[i,c]=m.useState("all"),[r,o]=m.useState(""),[l,{isLoading:_}]=Kd(),[h,{isLoading:N}]=Hd(),{data:g,isLoading:b,refetch:P}=Qd({search:a.trim()||void 0,status:t!=="all"?t:void 0,license_status:i!=="all"?i:void 0,package_name:r.trim()||void 0},{refetchOnMountOrArgChange:!0}),z=Array.isArray(g==null?void 0:g.data)?g.data:[],p=(g==null?void 0:g.statistics)||{total_organizations:0,active_organizations:0,inactive_organizations:0,total_employees:0},M=z.filter(d=>!!(d!=null&&d.license)).length,A=d=>{if(!d)return e.jsx(ee,{variant:"outline",children:"No License"});const I={active:{variant:"default",label:"Active"},expiring_soon:{variant:"secondary",label:"Expiring Soon"},expired:{variant:"destructive",label:"Expired"},suspended:{variant:"destructive",label:"Suspended"}}[d]||{variant:"outline",label:d};return e.jsx(ee,{variant:I.variant,children:I.label})},O=()=>({search:a.trim()||void 0,status:t!=="all"?t:void 0,license_status:i!=="all"?i:void 0,package_name:r.trim()||void 0}),k=(d,L)=>{const I=window.URL.createObjectURL(d),B=document.createElement("a");B.href=I,B.download=`organization-statistics-${new Date().toISOString().split("T")[0]}.${L}`,document.body.appendChild(B),B.click(),B.remove(),window.URL.revokeObjectURL(I)},j=async()=>
4{if(z.length)try{const d=await l(O()).unwrap();k(d,"pdf"),v.success("Organization report downloaded")}catch{v.error("Failed to download organization report PDF")}},S=async()=>{if(z.length)try{const d=await h(O()).unwrap();k(d,"csv"),v.success("Organization report downloaded")}catch{v.error("Failed to download organization report CSV")}};return e.jsx(ye,{title:"Organization Reports",subtitle:"",children:e.jsxs("div",{className:"p-4 lg:p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Xe,{className:"w-7 h-7 text-blue-600"}),"Organization Statistics"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Clean overview of organizations, contacts, and subscriptions."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(u,{variant:"outline",onClick:S,disabled:!g||z.length===0||N,children:[e.jsx(ac,{className:"w-4 h-4 mr-2"}),N?"Exporting...":"Export CSV"]}),e.jsxs(u,{onClick:j,disabled:!g||z.length===0||_,children:[e.jsx(ma,{className:"w-4 h-4 mr-2"}),_?"Exporting...":"Export PDF"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-5 gap-4",children:[e.jsx(hs,{className:"border-slate-200 shadow-sm",children:e.jsxs(Q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Total"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold",children:p.total_organizations})]})}),e.jsx(hs,{className:"border-slate-200 shadow-sm",children:e.jsxs(Q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Active"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold",children:p.active_organizations})]})}),e.jsx(hs,{className:"border-slate-200 shadow-sm",children:e.jsxs(Q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Inactive"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold",children:p.inactive_organizations})]})}),e.jsx(hs,{className:"border-slate-200 shadow-sm",children:e.jsxs(Q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Employees"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold",children:p.total_employees})]})}),e.jsx(hs,{className:"border-slate-200 shadow-sm",children:e.jsxs(Q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Licensed"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold",children:M})]})})]}),e.jsxs(W,{className:"shadow-sm",children:[e.jsx(se,{className:"border-b",children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(fa,{className:"w-4 h-4"}),"Filters"]}),e.jsx(je,{children:"Search by name, email, phone, package, or status."})]}),e.jsxs(u,{variant:"outline",onClick:()=>P(),disabled:b,children:[e.jsx(Es,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),"Refresh"]})]})}),e.jsxs(Q,{className:"p-4 grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"relative md:col-span-2 xl:col-span-2",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(E,{placeholder:"Search by organization, email, phone, registration, or package",value:a,onChange:d=>s(d.target.value),className:"pl-10"})]}),e.jsxs(ke,{value:t,onValueChange:d=>n(d),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Organization status"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All statuses"}),e.jsx(X,{value:"active",children:"Active"}),e.jsx(X,{value:"inactive",children:"Inactive"})]})]}),e.jsxs(ke,{value:i,onValueChange:d=>c(d),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Subscription status"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All subscriptions"}),e.jsx(X,{value:"active",children:"Active"}),e.jsx(X,{value:"expired",children:"Expired"}),e.jsx(X,{value:"suspended",children:"Suspended"}),e.jsx(X,{value:"inactive",children:"Inactive"})]})]}),e.jsx(E,{placeholder:"Package name",value:r,onChange:d=>o(d.target.value)}),e.jsx(u,{variant:"outline",onClick:()=>{s(""),n("all"),c("all"),o("")},children:"Clear filters"})]})]}),e.jsxs(W,{className:"border-slate-200 shadow-sm",children:[e.jsxs(se,{className:"border-b",children:[e.jsxs(ae,{children:["Organizations (",z.length,")"]}),e.jsx(je,{children:"Email, phone, status, and subscription details."})]}),e.jsx(Q,{className:"p-0",children:b?e.jsx("div",{className:"py-12 text-center text-muted-foreground",children:"Loading organizations..."}):z.length===0?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx(Oe,{className:"w-16 h-16 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-lg font-medium text-gray-900",children:"No organizations foun
4d"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Try adjusting your filters"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{className:"min-w-[1150px]",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Email"}),e.jsx(T,{className:"hidden sm:table-cell",children:"Phone"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Employees"}),e.jsx(T,{children:"License"}),e.jsx(T,{children:"Package"}),e.jsx(T,{children:"Created"})]})}),e.jsx(Ue,{children:z.map(d=>{var L,I,B,y,F;return e.jsxs(le,{children:[e.jsx(C,{className:"max-w-[240px]",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(Oa,{className:"h-9 w-9 rounded-lg",children:[e.jsx(Ra,{src:va((L=d==null?void 0:d.logo)==null?void 0:L.url)||void 0,alt:(d==null?void 0:d.name)||"Organization"}),e.jsx(Ia,{children:e.jsx(Xe,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"font-medium truncate",children:(d==null?void 0:d.name)||"N/A"})})]})}),e.jsx(C,{className:"max-w-[240px] truncate text-sm text-muted-foreground",children:(d==null?void 0:d.organization_email)||(d==null?void 0:d.login_email)||"N/A"}),e.jsx(C,{className:"hidden sm:table-cell text-sm text-muted-foreground",children:(d==null?void 0:d.contact_number)||"N/A"}),e.jsx(C,{children:e.jsx(ee,{variant:(d==null?void 0:d.status)==="active"?"default":"secondary",children:((d==null?void 0:d.status)||"unknown").toUpperCase()})}),e.jsx(C,{className:"text-right font-medium",children:(d==null?void 0:d.employee_count)??0}),e.jsx(C,{children:A((I=d==null?void 0:d.license)==null?void 0:I.status)}),e.jsxs(C,{className:"max-w-[220px]",children:[e.jsx("div",{className:"font-medium truncate",children:((y=(B=d==null?void 0:d.license)==null?void 0:B.package)==null?void 0:y.name)||"No Subscription"}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:((F=d==null?void 0:d.license)==null?void 0:F.payment_frequency)||"-"})]}),e.jsx(C,{className:"text-sm text-muted-foreground",children:(d==null?void 0:d.created_at)||"N/A"})]},d==null?void 0:d.id)})})]})})})]})]})})}const Yd=He.injectEndpoints({endpoints:a=>({getSmtpConfigurations:a.query({query:s=>({url:"/admin/smtp-configurations",method:"GET",params:s}),transformResponse:s=>s.data??[],providesTags:["smtpConfigurations"]}),getSmtpConfiguration:a.query({query:s=>({url:`/admin/smtp-configurations/${s}`,method:"GET"}),transformResponse:s=>s.data,providesTags:(s,t,n)=>[{type:"smtpConfigurations",id:n}]}),createSmtpConfiguration:a.mutation({query:s=>({url:"/admin/smtp-configurations",method:"POST",data:s}),transformResponse:s=>s.data,invalidatesTags:["smtpConfigurations"]}),updateSmtpConfiguration:a.mutation({query:({id:s,data:t})=>({url:`/admin/smtp-configurations/${s}`,method:"PUT",data:t}),transformResponse:s=>s.data,invalidatesTags:(s,t,{id:n})=>[{type:"smtpConfigurations",id:n},"smtpConfigurations"]}),deleteSmtpConfiguration:a.mutation({query:s=>({url:`/admin/smtp-configurations/${s}`,method:"DELETE"}),invalidatesTags:["smtpConfigurations"]}),testSmtpConfiguration:a.mutation({query:({id:s,data:t})=>({url:`/admin/smtp-configurations/${s}/test`,method:"POST",data:t})}),getResolvedSmtpConfiguration:a.query({query:s=>({url:"/admin/smtp-configurations/resolved",method:"GET",params:s}),transformResponse:s=>({...s.data,source:s.source||"system"})})})}),{useGetSmtpConfigurationsQuery:Jd,useCreateSmtpConfigurationMutation:Xd,useUpdateSmtpConfigurationMutation:Zd,useDeleteSmtpConfigurationMutation:em,useTestSmtpConfigurationMutation:sm}=Yd,At={name:"",host:"",port:587,encryption:"tls",username:"",password:"",from_address:"",from_name:"",purpose:"transactional",purposes:Ai,fallback_priority:100,is_default:!1,is_active:!0,description:""};function am(){const[a,s]=m.useState(!1),[t,n]=m.useState(!1),[i,c]=m.useState(!1),[r,o]=m.useState(null),[l,_]=m.useState(null),[h,N]=m.useState(null),[g,b]=m.useState(""),[P,z]=m.useState(At),{data:p,isLoading:M,error:A,refetch:O}=Jd({system_only:!0}),[k,{isLoading:j}]=Xd(),[S,{isLoading:d}]=Zd(),[L,{isLoading:I}]=em(),[B,{isLoading:y}]=sm(),F=w=>{var Y;w?(o(w),z({name:w.name,host:w.host,port:w.port,encryption:w.encryption,username:w.username,password:"",from_address:w.from_address,from_name:w.from_name,purpose:w.purpose,purposes:(Y=w.purposes)!=null&&Y.length?w.purposes:[w.purpose],fallback_priority:w.fallback_priority??100,is_default:w.is_default,is_active:w.is_active,description:w.description||""})):(o(null),z(At)),s(!0)},K=()=>{s(!1),o(null),z(At)},q=async w=>{var Y;w.preventDefault();try{r?(await S({id:r.id,data:P}).unwrap(),v.success("SMTP configuration updated successfully")):(await k(P).unwrap(),v.success("SMTP configuration created successfully"));try{await O()}catch{}K()}catch(ue){v.error(((Y=ue==null?void 0:ue.data)==null?void 0:Y.message)||"Failed to save SMTP configuration")}},U=async()=>{var w;if(l)try{await L(l.id).unwrap(),v.success("SMTP configuration deleted successfully"),n(!1),_(null);try{await O()}catch{}}catch(Y){v.error(((w=Y==null?void 0:Y.data)==null?void 0:w.message)||"Failed to delete SMTP configuration")}},re=async()=>{var w;if(!(!h||!g))try{const Y=await B({id:h.id,data:{test_email:g}}).unwrap();v.success(Y.message||"Test email sent successfully"),c(!1),N(null),b("")}catch(Y){v.error(((w=Y==null?void 0:Y.data)==null?void 0:w.message)||"SMTP test failed")}},te=(w,Y)=>{z(ue=>({...ue,[w]:Y}))},G=P.purposes&&P.purposes.length>0?P.purposes:P.purpose?[P.purpose]:Ai;return M?e.jsxs("div",{className:"space-y-4",children:[e.jsx(js,{className:"h-12 w-full"}),e.jsx(js,{className:"h-64 w-full"})]}):A?e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Oe,{className:"mx-auto h-12 w-12 text-red-500 mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Failed to Load SMTP Configurations"}),e.jsx("p",{className:"text-muted-foreground",children:"Please try again later."})]})})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(ms,{className:"h-5 w-5"}),"SMTP Configurations"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage email sending configurations for the system"})]}),e.jsxs(u,{onClick:()=>F(),className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Add SMTP Config"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:p&&p.length>0?e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Host"}),e.jsx(T,{children:"Port"}),e.jsx(T,{children:"Purpose"}),e.jsx(T,{children:"Fallback order"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Default"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:p.map(w=>{var Y;return e.jsxs(le,{children:[e.jsx(C,{className:"font-medium",children:w.name}),e.jsx(C,{children:w.host}),e.jsx(C,{children:w.port}),e.jsx(C,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:((Y=w.purposes)!=null&&Y.length?w.purposes:[w.purpose]).map(ue=>{var J;return e.jsx(ee,{variant:"outline",className:ic(ue)?"border-red-400 text-red-700":"",title:(J=nc.find(ge=>ge.value===ue))==null?void 0:J.examples,children:tc(ue)},ue)})})}),e.jsx(C,{className:"text-sm text-muted-foreground",children:w.is_default?"Primary":w.fallback_priority??100}),e.jsx(C,{children:w.is_active?e.jsx(ee,{variant:"default",className:"bg-green-500",children:"Active"}):e.jsx(ee,{variant:"secondary",children:"Inactive"})}),e.jsx(C,{children:w.is_default&&e.jsx(ps,{className:"h-5 w-5 text-green-500"})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",onClick:()=>{N(w),c(!0)},children:e.jsx(tn,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>F(w),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>{_(w),n(!0)},children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},w.id)})})]}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ms,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No SMTP Configurations"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Get started by adding your first SMTP configuration."}),e.jsxs(u,{onClick:()=>F(),children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add SMTP Config"]})]})})}),e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:r?"Edit SMTP Configuration":"Add SMTP Configuration"}),e.jsx(Ge,{children:"Configure SMTP settings for sending emails from the system."})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"name",children:"Configuration Name *"}),e.jsx(E,{id:"name",value:P.name,onChange:w=>te("name",w.target.value),placeholder:"e.g., Primary SMTP",required:!0})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Purposes carried by this connection *"}),e.jsx(rc,{value:G,onChange:w=>z(Y=>({...Y,purposes:w,purpose:w[0]}))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"host",children:"SMTP Host *"}),e.jsx(E,{id:"host",value:P.host,onChange:w=>te("host",w.target.value),placeholder:"smtp.example.com",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"port",children:"Port *"}),e.jsx(E,{id:"port",type:"number",value:P.port,onChange:w=>te("port",parseInt(w.target.value)||587),required:!0})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"username",children:"Username *"}),e.jsx(E,{id:"username",value:P.username,onChange:w=>te("username",w.target.value),placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"password",children:["Password ",r?"(leave blank to keep current)":"*"]}),e.jsx(E,{id:"password",type:"password",value:P.password,onChange:w=>te("password",w.target.value),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",required:!r})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"encryption",children:"Encryption"}),e.jsxs(ke,{value:P.encryption,onValueChange:w=>te("encryption",w),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select encryption"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"tls",children:"TLS"}),e.jsx(X,{value:"ssl",children:"SSL"}),e.jsx(X,{value:"none",children:"None"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"from_address",children:"From Email *"}),e.jsx(E,{id:"from_address",type:"email",value:P.from_address,onChange:w=>te("from_address",w.target.value),placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"from_name",children:"From Name *"}),e.jsx(E,{id:"from_name",value:P.from_name,onChange:w=>te("from_name",w.target.value),placeholder:"HR System",required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(Ce,{id:"description",value:P.description||"",onChange:w=>te("description",w.target.value),placeholder:"Optional description for this configuration"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"fallback_priority",children:"Fallback order"}),e.jsx(E,{id:"fallback_priority",type:"number",min:0,max:65535,value:P.fallback_priority??100,onChange:w=>te("fallback_priority",parseInt(w.target.value)||0)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"If the default connection for this purpose refuses a message, the remaining connections are tried in this order - lowest number first - before falling back to the server default. The default connection is always tried first regardless of this number."})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_active",checked:P.is_active,onCheckedChange:w=>te("is_active",w)}),e.jsx(x,{htmlFor:"is_active",children:"Active"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_default",checked:P.is_default,onCheckedChange:w=>te("is_default",w)}),e.jsx(x,{htmlFor:"is_default",children:"Set as Default"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:K,children:"Cancel"}),e.jsxs(u,{type:"submit",disabled:j||d,children:[(j||d)&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),r?"Update":"Create"]})]})]})]})}),e.jsx(ss,{open:t,onOpenChange:n,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete SMTP Configuration"}),e.jsxs(is,{children:['Are you sure you want to delete "',l==null?void 0:l.name,'"? This action cannot be undone.']})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsxs(cs,{onClick:U,disabled:I,children:[I&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete"]})]})]})}),e.jsx(Fe,{open:i,onOpenChange:c,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Test SMTP Configuration"}),e.jsxs(Ge,{children:['Send a test email to verify "',h==null?void 0:h.name,'" is working correctly.']})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"test_email",children:"Send Test Email To"}),e.jsx(E,{id:"test_email",type:"email",value:g,onChange:w=>b(w.target.value),placeholder:"[email protected]"})]})}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>{c(!1),N(null),b("")},children:"Cancel"}),e.jsxs(u,{onClick:re,disabled:y||!g,children:[y&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Test Email"]})]})]})})]})}const tm=He.injectEndpoints({endpoints:a=>({getAzureBlobConfigurations:a.query({query:s=>({url:"/admin/azure-blob-configurations",method:"GET",params:s}),transformResponse:s=>s.data??[],providesTags:["azureBlobConfigurations"]}),getAzureBlobConfiguration:a.query({query:s=>({url:`/admin/azure-blob-configurations/${s}`,method:"GET"}),transformResponse:s=>s.data,providesTags:(s,t,n)=>[{type:"azureBlobConfigurations",id:n}]}),createAzureBlobConfiguration:a.mutation({query:s=>({url:"/admin/azure-blob-configurations",method:"POST",data:s}),transformResponse:s=>s.data,invalidatesTags:["azureBlobConfigurations"]}),updateAzureBlobConfiguration:a.mutation({query:({id:s,data:t})=>({url:`/admin/azure-blob-configurations/${s}`,method:"PUT",data:t}),transformResponse:s=>s.data,invalidatesTags:(s,t,{id:n})=>[{type:"azureBlobConfigurations",id:n},"azureBlobConfigurations"]}),deleteAzureBlobConfiguration:a.mutation({query:s=>({url:`/admin/azure-blob-configurations/${s}`,method:"DELETE"}),invalidatesTags:["azureBlobConfigurations"]}),testAzureBlobConfiguration:a.mutation({query:s=>({url:`/admin/azure-blob-configurations/${s}/test`,method:"POST"})}),getResolvedAzureBlobConfiguration:a.query({query:s=>({url:"/admin/azure-blob-configurations/resolved",method:"GET",params:s}),transformResponse:s=>({...s.data,source:s.source||"system"})})})}),{useGetAzureBlobConfigurationsQuery:nm,useCreateAzureBlobConfigurationMutation:im,useUpdateAzureBlobConfigurationMutation:rm,useDeleteAzureBlobConfigurationMutation:lm,useTestAzureBlobConfigurationMutation:cm}=tm,Pt={name:"",account_name:"",account_key:"",container_name:"",endpoint:"",connection_string:"",purpose:"general",is_default:!1,is_active:!0,description:""};function om(){const[a,s]=m.useState(!1),[t,n]=m.useState(!1),[i,c]=m.useState(null),[r,o]=m.useState(null),[l,_]=m.useState(Pt),{data:h,isLoading:N,error:g,refetch:b}=nm({system_only:!0}),[P,{isLoading:z}]=im(),[p,{isLoading:M}]=rm(),[A,{isLoading:O}]=lm(),[k,{isLoading:j}]=cm(),S=F=>{F?(c(F),_({name:F.name,account_name:F.account_name,account_key:"",container_name:F.container_name,endpoint:F.endpoint||"",connection_string:"",purpose:F.purpose,is_default:F.is_default,is_activ
4e:F.is_active,description:F.description||""})):(c(null),_(Pt)),s(!0)},d=()=>{s(!1),c(null),_(Pt)},L=async F=>{var K;F.preventDefault();try{i?(await p({id:i.id,data:l}).unwrap(),v.success("Azure Blob configuration updated successfully")):(await P(l).unwrap(),v.success("Azure Blob configuration created successfully"));try{await b()}catch{}d()}catch(q){v.error(((K=q==null?void 0:q.data)==null?void 0:K.message)||"Failed to save Azure Blob configuration")}},I=async()=>{var F;if(r)try{await A(r.id).unwrap(),v.success("Azure Blob configuration deleted successfully"),n(!1),o(null);try{await b()}catch{}}catch(K){v.error(((F=K==null?void 0:K.data)==null?void 0:F.message)||"Failed to delete Azure Blob configuration")}},B=async F=>{var K;try{const q=await k(F.id).unwrap();v.success(q.message||"Azure Blob connection test successful")}catch(q){v.error(((K=q==null?void 0:q.data)==null?void 0:K.message)||"Azure Blob test failed")}},y=(F,K)=>{_(q=>({...q,[F]:K}))};return N?e.jsxs("div",{className:"space-y-4",children:[e.jsx(js,{className:"h-12 w-full"}),e.jsx(js,{className:"h-64 w-full"})]}):g?e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Oe,{className:"mx-auto h-12 w-12 text-red-500 mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Failed to Load Azure Blob Configurations"}),e.jsx("p",{className:"text-muted-foreground",children:"Please try again later."})]})})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5"}),"Azure Blob Storage Configurations"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage Azure Blob storage configurations for file uploads"})]}),e.jsxs(u,{onClick:()=>S(),className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Add Azure Blob Config"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:h&&h.length>0?e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Account"}),e.jsx(T,{children:"Container"}),e.jsx(T,{children:"Purpose"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Default"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:h.map(F=>e.jsxs(le,{children:[e.jsx(C,{className:"font-medium",children:F.name}),e.jsx(C,{children:F.account_name}),e.jsx(C,{children:F.container_name}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",className:"capitalize",children:F.purpose})}),e.jsx(C,{children:F.is_active?e.jsx(ee,{variant:"default",className:"bg-green-500",children:"Active"}):e.jsx(ee,{variant:"secondary",children:"Inactive"})}),e.jsx(C,{children:F.is_default&&e.jsx(ps,{className:"h-5 w-5 text-green-500"})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",onClick:()=>B(F),disabled:j,children:j?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(tn,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>S(F),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>{o(F),n(!0)},children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},F.id))})]}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ya,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Azure Blob Configurations"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Get started by adding your first Azure Blob storage configuration."}),e.jsxs(u,{onClick:()=>S(),children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Azure Blob Config"]})]})})}),e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:i?"Edit Azure Blob Configuration":"Add Azure Blob Configuration"}),e.jsx(Ge,{children:"Configure Azure Blob storage settings for file uploads."})]}),e.jsxs("form",{onSubmit:L,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"name",children:"Configuration Name *"}),e.jsx(E,{id:"name",value:l.name,onChange:F=>y("name",F.target.value),placeholder:"e.g., Primary Storage",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"purpose",children:"Purpose"}),e.jsxs(ke,{value:l.purpose,onValueChange:F=>y("purpose",F),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select purpose"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"documents",children:"Documents"}),e.jsx(X,{value:"media",children:"Media"}),e.jsx(X,{value:"backups",children:"Backups"}),e.jsx(X,{value:"general",children:"General"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"account_name",children:"Storage Account Name *"}),e.jsx(E,{id:"account_name",value:l.account_name,onChange:F=>y("account_name",F.target.value),placeholder:"yourstorageaccount",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"container_name",children:"Container Name *"}),e.jsx(E,{id:"container_name",value:l.container_name,onChange:F=>y("container_name",F.target.value),placeholder:"documents",required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"account_key",children:["Account Key ",i?"(leave blank to keep current)":"*"]}),e.jsx(E,{id:"account_key",type:"password",value:l.account_key,onChange:F=>y("account_key",F.target.value),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",required:!i})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"endpoint",children:"Custom Endpoint (Optional)"}),e.jsx(E,{id:"endpoint",value:l.endpoint||"",onChange:F=>y("endpoint",F.target.value),placeholder:"https://yourstorageaccount.blob.core.windows.net"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty to use the default Azure endpoint"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"connection_string",children:"Connection String (Alternative, leave blank to use account name/key)"}),e.jsx(Ce,{id:"connection_string",value:l.connection_string||"",onChange:F=>y("connection_string",F.target.value),placeholder:"DefaultEndpointsProtocol=https;AccountName=...",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(Ce,{id:"description",value:l.description||"",onChange:F=>y("description",F.target.value),placeholder:"Optional description for this configuration"})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_active",checked:l.is_active,onCheckedChange:F=>y("is_active",F)}),e.jsx(x,{htmlFor:"is_active",children:"Active"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_default",checked:l.is_default,onCheckedChange:F=>y("is_default",F)}),e.jsx(x,{htmlFor:"is_default",children:"Set as Default"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:d,children:"Cancel"}),e.jsxs(u,{type:"submit",disabled:z||M,children:[(z||M)&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),i?"Update":"Create"]})]})]})]})}),e.jsx(ss,{open:t,onOpenChange:n,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete Azure Blob Configuration"}),e.jsxs(is,{children:['Are you sure you want to delete "',r==null?void 0:r.name,'"? This action cannot be undone.']})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsxs(cs,{onClick:I,disabled:O,children:[O&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete"]})]})]})})]})}const Tt={name:"",service_type:"openai",provider:"openai",api_key:"",api_endpoint:"",model:"gpt-4",temperature:.7,max_tokens:4096,language:"en",voice:"",bot_name:"",purpose:"interview",is_default:!0,is_active:!0,description:"",organization_id:null},dm={openai:tt,stt:pc,tts:hc},mm={openai:"LLM (Language Model)",stt:"Speech-to-Text",tts:"Text-to-Speech"};function um(){const[a,s]=m.useState(!1),[t,n]=m.useState(!1),[i,c]=m.useState(null),[r,o]=m.useState(null),[l,_]=m.useState(Tt),{data:h,isLoading:N,error:g,refetch:b}=lc({system_only:!0}),[P,{isLoading:z}]=cc(),[p,{isLoading:M}]=oc(),[A,{isLoading:O}]=dc(),[k,{isLoading:j}]=mc(),[S,{isLoading:d}]=uc(),[L]=xc(),I=G=>{G?(c(G),_({name:G.name,service_type:G.service_type,provider:G.provider,api_key:"",api_endpoint:G.api_endpoint||"",model:G.model||"",temperature:G.temperature??.7,max_tokens:G.max_tokens??4096,language:G.language||"",voice:G.voice||"",bot_name:G.bot_name||"",purpose:G.purpose,is_default:G.is_default,is_active:G.is_active,description:G.description||""})):(c(null),_(Tt)),s(!0)},B=()=>{s(!1),c(null),_(Tt)},y=async G=>{var w;G.preventDefault();try{i?(await p({id:i.id,data:l}).unwrap(),v.success("AI configuration updated successfully")):(await P(l).unwrap(),v.success("AI configuration created successfully"));try{await b()}catch{}B()}catch(Y){v.error(((w=Y==null?void 0:Y.data)==null?void 0:w.message)||"Failed to save AI configuration")}},F=async()=>{var G;if(r)try{await A(r.id).unwrap(),v.success("AI configuration deleted successfully"),n(!1),o(null);try{await b()}catch{}}catch(w){v.error(((G=w==null?void 0:w.data)==null?void 0:G.message)||"Failed to delete AI configuration")}},K=async G=>{var w;try{const Y=await k(G.id).unwrap();v.success(Y.message||"AI connection test successful")}catch(Y){v.error(((w=Y==null?void 0:Y.data)==null?void 0:w.message)||"AI test failed")}},q=(G,w)=>{_(Y=>({...Y,[G]:w}))},U=()=>Nt[l.service_type]||Nt.openai,re=()=>l.service_type==="openai"?Ln[l.provider]||Ln.openai:[];if(N)return e.jsxs("div",{className:"space-y-4",children:[e.jsx(js,{className:"h-12 w-full"}),e.jsx(js,{className:"h-64 w-full"})]});if(g)return e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Oe,{className:"mx-auto h-12 w-12 text-red-500 mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Failed to Load AI Configurations"}),e.jsx("p",{className:"text-muted-foreground",children:"Please try again later."})]})})});const te={openai:(h==null?void 0:h.filter(G=>G.service_type==="openai"))||[],stt:(h==null?void 0:h.filter(G=>G.service_type==="stt"))||[],tts:(h==null?void 0:h.filter(G=>G.service_type==="tts"))||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5"}),"AI Service Configurations"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage AI configurations for LLM, Speech-to-Text, and Text-to-Speech services"})]}),e.jsxs(u,{onClick:()=>I(),className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Add AI Config"]})]}),Object.entries(te).map(([G,w])=>{const Y=dm[G],ue=mm[G];return e.jsx(W,{children:e.jsxs(Q,{className:"pt-6",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2 mb-4",children:[e.jsx(Y,{className:"h-5 w-5"}),ue]}),w.length>0?e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Provider"}),e.jsx(T,{children:"Model"}),e.jsx(T,{children:"Purpose"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Default"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:w.map(J=>e.jsxs(le,{children:[e.jsx(C,{className:"font-medium",children:J.name}),e.jsx(C,{className:"capitalize",children:J.provider.replace("_"," ")}),e.jsx(C,{children:J.model||"-"}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",className:"capitalize",children:J.purpose.replace("_"," ")})}),e.jsx(C,{children:J.is_active?e.jsx(ee,{variant:"default",className:"bg-green-500",children:"Active"}):e.jsx(ee,{variant:"secondary",children:"Inactive"})}),e.jsx(C,{children:J.is_default&&e.jsx(ps,{className:"h-5 w-5 text-green-500"})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",onClick:()=>K(J),disabled:j,children:j?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(tn,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>I(J),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>{o(J),n(!0)},children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},J.id))})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No ",ue.toLowerCase()," configurations yet."]})]})},G)}),(h==null?void 0:h.length)===0&&e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(tt,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No AI Configurations"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Get started by adding your first AI service configuration."}),e.jsxs(u,{onClick:()=>I(),children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add AI Config"]})]})})}),e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:i?"Edit AI Configuration":"Add AI Configuration"}),e.jsx(Ge,{children:"Configure AI service settings for language models, speech-to-text, or text-to-speech."})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"name",children:"Configuration Name *"}),e.jsx(E,{id:"name",value:l.name,onChange:G=>q("name",G.target.value),placeholder:"e.g., Interview AI",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"service_type",children:"Service Type *"}),e.jsxs(ke,{value:l.service_type,onValueChange:G=>{_(w=>{var J;const Y=G,ue=Nt[Y];return{...w,service_type:Y,provider:gc(Y)??((J=ue==null?void 0:ue[0])==null?void 0:J.value)??w.provider,model:"",voice:"",purpose:yt[Y]??w.purpose}})},disabled:!!i,children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select service type"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"openai",children:"LLM (Language Model)"}),e.jsx(X,{value:"stt",children:"Speech-to-Text"}),e.jsx(X,{value:"tts",children:"Text-to-Speech"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"provider",children:"Provider *"}),e.jsxs(ke,{value:l.provider,onValueChange:G=>_(w=>({...w,provider:G,model:"",voice:""})),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select provider"})}),e.jsx(Pe,{children:U().map(G=>e.jsx(X,{value:G.value,children:G.label},G.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"purpose",children:"Purpose"}),e.jsxs("div",{className:"flex h-10 items-center gap-2 rounded-md border border-input bg-muted px-3",children:[e.jsx(Fa,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:jc[yt[l.service_type]]??yt[l.service_type]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Set automatically by the service type â this is the value the interview bot looks the service up by."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"api_key",children:["API Key ",i?"(leave blank to keep current)":"*"]}),e.jsx(E,{id:"api_key",type:"password",value:l.api_key,onChange:G=>q("api_key",G.target.value),placeholder:"sk-...",required:!i})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"api_endpoint",children:"Custom API Endpoint (Optional)"}),e.jsx(E,{id:"api_endpoint",value:l.api_endpoint||"",onChange:G=>q("api_endpoint",G.target.value),placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty to use the provider's default endpoint"})]}),l.service_type==="openai"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-col
4s-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"model",children:"Model"}),e.jsxs(ke,{value:l.model||"",onValueChange:G=>q("model",G),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select model"})}),e.jsx(Pe,{children:re().map(G=>e.jsx(X,{value:G,children:G},G))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"temperature",children:"Temperature"}),e.jsx(E,{id:"temperature",type:"number",step:"0.1",min:"0",max:"2",value:l.temperature??.7,onChange:G=>q("temperature",parseFloat(G.target.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"max_tokens",children:"Max Tokens"}),e.jsx(E,{id:"max_tokens",type:"number",min:"1",max:"128000",value:l.max_tokens??4096,onChange:G=>q("max_tokens",parseInt(G.target.value))})]})]}),(l.service_type==="stt"||l.service_type==="tts")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"model",children:"Model"}),e.jsx(fc,{serviceType:l.service_type,provider:l.provider,model:l.model,onChange:G=>q("model",G)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"language",children:"Language"}),e.jsxs(ke,{value:l.language||"",onValueChange:G=>q("language",G),children:[e.jsx(Se,{id:"language",children:e.jsx(Ae,{placeholder:"Select language"})}),e.jsx(Pe,{children:vc.map(G=>e.jsx(X,{value:G.code,children:G.name},G.code))})]})]})]}),l.service_type==="tts"&&e.jsx(yc,{provider:l.provider,apiKey:l.api_key,language:l.language,model:l.model,voice:l.voice,onVoiceChange:G=>q("voice",G),aiConfigurationId:i==null?void 0:i.id,listVoices:S,isLoadingVoices:d,speakVoiceSample:L},l.provider)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(Ce,{id:"description",value:l.description||"",onChange:G=>q("description",G.target.value),placeholder:"Optional description for this configuration"})]}),l.service_type==="tts"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"bot_name",children:"Interview bot name"}),e.jsx(E,{id:"bot_name",value:l.bot_name??"",onChange:G=>q("bot_name",G.target.value),placeholder:"HRC Interviewer",maxLength:120}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The name the interview bot introduces itself with. This is the platform default: an organization that sets its own overrides it. Leave blank to use the value from the environment."})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_active",checked:l.is_active,onCheckedChange:G=>q("is_active",G)}),e.jsx(x,{htmlFor:"is_active",children:"Active"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_default",checked:l.is_default,onCheckedChange:G=>q("is_default",G)}),e.jsx(x,{htmlFor:"is_default",children:"Set as Default"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:B,children:"Cancel"}),e.jsxs(u,{type:"submit",disabled:z||M,children:[(z||M)&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),i?"Update":"Create"]})]})]})]})}),e.jsx(ss,{open:t,onOpenChange:n,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete AI Configuration"}),e.jsxs(is,{children:['Are you sure you want to delete "',r==null?void 0:r.name,'"? This action cannot be undone.']})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsxs(cs,{onClick:F,disabled:O,children:[O&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete"]})]})]})})]})}function xm(){const[a,s]=m.useState("smtp");return e.jsx(ye,{title:"",subtitle:"",children:e.jsxs("div",{className:"space-y-6 p-3 sm:p-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold sm:text-3xl",children:[e.jsx(an,{className:"h-6 w-6 sm:h-8 sm:w-8"}),"System Configurations"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"Configure system-wide settings for SMTP, Azure Blob Storage, and AI services. These are default configurations that organizations can override."})]})}),e.jsxs(Qs,{value:a,onValueChange:s,className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsxs(Ks,{className:"inline-flex h-auto min-w-full sm:w-full sm:grid sm:grid-cols-3",children:[e.jsxs(Ye,{value:"smtp",className:"h-9 min-w-[150px] flex items-center gap-2 text-xs sm:text-sm",children:[e.jsx(ms,{className:"h-4 w-4"}),e.jsx("span",{className:"whitespace-nowrap",children:"SMTP Settings"})]}),e.jsxs(Ye,{value:"azure",className:"h-9 min-w-[180px] flex items-center gap-2 text-xs sm:text-sm",children:[e.jsx(ya,{className:"h-4 w-4"}),e.jsx("span",{className:"whitespace-nowrap",children:"Azure Blob Storage"})]}),e.jsxs(Ye,{value:"ai",className:"h-9 min-w-[130px] flex items-center gap-2 text-xs sm:text-sm",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx("span",{className:"whitespace-nowrap",children:"AI Services"})]})]})}),e.jsx(Je,{value:"smtp",className:"mt-6 space-y-6",children:e.jsx(am,{})}),e.jsx(Je,{value:"azure",className:"mt-6 space-y-6",children:e.jsx(om,{})}),e.jsx(Je,{value:"ai",className:"mt-6 space-y-6",children:e.jsx(um,{})})]})]})})}const qs=fs("token"),hm=He.injectEndpoints({endpoints:a=>({getSitePages:a.query({query:s=>{const t=(s==null?void 0:s.page)??1,n=[];s!=null&&s.site_type&&n.push(`site_type=${encodeURIComponent(s.site_type)}`),s!=null&&s.content_type&&n.push(`content_type=${encodeURIComponent(s.content_type)}`);const i=n.length?`&${n.join("&")}`:"";return{url:`/admin/site-pages?page=${t}${i}`,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}},providesTags:s=>s!=null&&s.data?[...s.data.map(t=>
4({type:"site-pages",id:t.id})),{type:"site-pages",id:"LIST"}]:[{type:"site-pages",id:"LIST"}]}),getSitePage:a.query({query:s=>({url:`/admin/site-pages/${s}`,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),providesTags:(s,t,n)=>[{type:"site-pages",id:n}]}),createSitePage:a.mutation({query:s=>({url:"/admin/site-pages",method:"POST",body:s,headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:[{type:"site-pages",id:"LIST"}]}),updateSitePage:a.mutation({query:({id:s,body:t})=>({url:`/admin/site-pages/${s}`,method:"PUT",body:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:(s,t,{id:n})=>[{type:"site-pages",id:n},{type:"site-pages",id:"LIST"}]}),deleteSitePage:a.mutation({query:s=>({url:`/admin/site-pages/${s}`,method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:[{type:"site-pages",id:"LIST"}]}),addSection:a.mutation({query:({pageId:s,section:t})=>({url:`/admin/site-pages/${s}/sections`,method:"POST",body:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:(s,t,{pageId:n})=>[{type:"site-pages",id:n}]}),updateSection:a.mutation({query:({pageId:s,sectionId:t,section:n})=>({url:`/admin/site-pages/${s}/sections/${t}`,method:"PUT",body:n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:(s,t,{pageId:n})=>[{type:"site-pages",id:n}]}),deleteSection:a.mutation({query:({pageId:s,sectionId:t})=>({url:`/admin/site-pages/${s}/sections/${t}`,method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:(s,t,{pageId:n})=>[{type:"site-pages",id:n}]}),reorderSections:a.mutation({query:({pageId:s,sectionIds:t})=>({url:`/admin/site-pages/${s}/sections/reorder`,method:"POST",body:{section_ids:t},headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}}),invalidatesTags:(s,t,{pageId:n})=>[{type:"site-pages",id:n}]}),notifyOrganizations:a.mutation({query:s=>({url:`/admin/site-pages/${s}/notify`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${qs}`}})})}),overrideExisting:!0}),{useGetSitePagesQuery:pm,useGetSitePageQuery:gm,useCreateSitePageMutation:jm,useUpdateSitePageMutation:fm,useDeleteSitePageMutation:vm,useNotifyOrganizationsMutation:ym}=hm;function Nm(a){const s=a+"CollectionProvider",[t,n]=ui(s),[i,c]=t(s,{collectionRef:{current:null},itemMap:new Map}),r=z=>{const{scope:p,children:M}=z,A=pe.useRef(null),O=pe.useRef(new Map).current;return e.jsx(i,{scope:p,itemMap:O,collectionRef:A,children:M})};r.displayName=s;const o=a+"CollectionSlot",l=It(o),_=pe.forwardRef((z,p)=>{const{scope:M,children:A}=z,O=c(o,M),k=Rt(p,O.collectionRef);return e.jsx(l,{ref:k,children:A})});_.displayName=o;const h=a+"CollectionItemSlot",N="data-radix-collection-item",g=It(h),b=pe.forwardRef((z,p)=>{const{scope:M,children:A,...O}=z,k=pe.useRef(null),j=Rt(p,k),S=c(h,M);return pe.useEffect(()=>(S.itemMap.set(k,{ref:k,...O}),()=>void S.itemMap.delete(k))),e.jsx(g,{[N]:"",ref:j,children:A})});b.displayName=h;function P(z){const p=c(a+"CollectionConsumer",z);return pe.useCallback(()=>{const A=p.collectionRef.current;if(!A)return[];const O=Array.from(A.querySelectorAll(`[${N}]`));return Array.from(p.itemMap.values()).sort((S,d)=>O.indexOf(S.ref.current)-O.indexOf(d.ref.current))},[p.collectionRef,p.itemMap])}return[{Provider:r,Slot:_,ItemSlot:b},P,n]}function bm(a,s,{checkForDefaultPrevented:t=!0}={}){return function(i){if(a==null||a(i),t===!1||!i.defaultPrevented)return s==null?void 0:s(i)}}var _m=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ii=_m.reduce((a,s)=>{const t=It(`Primitive.${s}`),n=m.forwardRef((i,c)=>{const{asChild:r,...o}=i,l=r?t:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(l,{...o,ref:c})});return n.displayName=`Primitive.${s}`,{...a,[s]:n}},{}),Ds="Accordion",wm=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[mn,Cm,km]=Nm(Ds),[pt,Wh]=ui(Ds,[km,Pi]),un=Pi(),$i=pe.forwardRef((a,s)=>{const{type:t,...n}=a,i=n,c=n;return e.jsx(mn.Provider,{scope:a.__scopeAccordion,children:t==="multiple"?e.jsx(Tm,{...c,ref:s}):e.jsx(Pm,{...i,ref:s})})});$i.displayName=Ds;var[Bi,Sm]=pt(Ds),[Ui,Am]=pt(Ds,{collapsible:!1}),Pm=pe.forwardRef((a,s)=>{const{value:t,defaultValue:n,onValueChange:i=()=>{},collapsible:c=!1,...r}=a,[o,l]=xi({prop:t,defaultProp:n??"",onChange:i,caller:Ds});return e.jsx(Bi,{scope:a.__scopeAccordion,value:pe.useMemo(()=>o?[o]:[],[o]),onItemOpen:l,onItemClose:pe.useCallback(()=>c&&l(""),[c,l]),children:e.jsx(Ui,{scope:a.__scopeAccordion,collapsible:c,children:e.jsx(Gi,{...r,ref:s})})})}),Tm=pe.forwardRef((a,s)=>{const{value:t,defaultValue:n,onValueChange:i=()=>{},...c}=a,[r,o]=xi({prop:t,defaultProp:n??[],onChange:i,caller:Ds}),l=pe.useCallback(h=>o((N=[])=>[...N,h]),[o]),_=pe.useCallback(h=>o((N=[])=>N.filter(g=>g!==h)),[o]);return e.jsx(Bi,{scope:a.__scopeAccordion,value:r,onItemOpen:l,onItemClose:_,children:e.jsx(Ui,{scope:a.__scopeAccordion,collapsible:!0,children:e.jsx(Gi,{...c,ref:s})})})}),[Fm,gt]=pt(Ds),Gi=pe.forwardRef((a,s)=>{const{__scopeAccordion:t,disabled:n,dir:i,orientation:c="vertical",...r}=a,o=pe.useRef(null),l=Rt(o,s),_=Cm(t),N=wc(i)==="ltr",g=bm(a.onKeyDown,b=>{var L;if(!wm.includes(b.key))return;const P=b.target,z=_().filter(I=>{var B;return!((B=I.ref.current)!=null&&B.disabled)}),p=z.findIndex(I=>I.ref.current===P),M=z.length;if(p===-1)return;b.preventDefault();let A=p;const O=0,k=M-1,j=()=>{A=p+1,A>k&&(A=O)},S=()=>{A=p-1,A<O&&(A=k)};switch(b.key){case"Home":A=O;break;case"End":A=k;break;case"ArrowRight":c==="horizontal"&&(N?j():S());break;case"ArrowDown":c==="vertical"&&j();break;case"ArrowLeft":c==="horizontal"&&(N?S():j());break;case"ArrowUp":c==="vertical"&&S();break}const d=A%M;(L=z[d].ref.current)==null||L.focus()});return e.jsx(Fm,{scope:t,disabled:n,direction:i,orientation:c,children:e.jsx(mn.Slot,{scope:t,children:e.jsx(Ii.div,{...r,"data-orientation":c,ref:l,onKeyDown:n?void 0:g})})})}
4),rt="AccordionItem",[zm,xn]=pt(rt),Vi=pe.forwardRef((a,s)=>{const{__scopeAccordion:t,value:n,...i}=a,c=gt(rt,t),r=Sm(rt,t),o=un(t),l=Fr(),_=n&&r.value.includes(n)||!1,h=c.disabled||a.disabled;return e.jsx(zm,{scope:t,open:_,disabled:h,triggerId:l,children:e.jsx(Nc,{"data-orientation":c.orientation,"data-state":Ji(_),...o,...i,ref:s,disabled:h,open:_,onOpenChange:N=>{N?r.onItemOpen(n):r.onItemClose(n)}})})});Vi.displayName=rt;var Qi="AccordionHeader",Ki=pe.forwardRef((a,s)=>{const{__scopeAccordion:t,...n}=a,i=gt(Ds,t),c=xn(Qi,t);return e.jsx(Ii.h3,{"data-orientation":i.orientation,"data-state":Ji(c.open),"data-disabled":c.disabled?"":void 0,...n,ref:s})});Ki.displayName=Qi;var Jt="AccordionTrigger",Hi=pe.forwardRef((a,s)=>{const{__scopeAccordion:t,...n}=a,i=gt(Ds,t),c=xn(Jt,t),r=Am(Jt,t),o=un(t);return e.jsx(mn.ItemSlot,{scope:t,children:e.jsx(bc,{"aria-disabled":c.open&&!r.collapsible||void 0,"data-orientation":i.orientation,id:c.triggerId,...o,...n,ref:s})})});Hi.displayName=Jt;var Wi="AccordionContent",Yi=pe.forwardRef((a,s)=>{const{__scopeAccordion:t,...n}=a,i=gt(Ds,t),c=xn(Wi,t),r=un(t);return e.jsx(_c,{role:"region","aria-labelledby":c.triggerId,"data-orientation":i.orientation,...r,...n,ref:s,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...a.style}})});Yi.displayName=Wi;function Ji(a){return a?"open":"closed"}var Em=$i,Dm=Vi,Lm=Ki,Mm=Hi,qm=Yi;function Om({...a}){return e.jsx(Em,{"data-slot":"accordion",...a})}function Rm({className:a,...s}){return e.jsx(Dm,{"data-slot":"accordion-item",className:Ts("border-b last:border-b-0",a),...s})}function Im({className:a,children:s,...t}){return e.jsx(Lm,{className:"flex",children:e.jsxs(Mm,{"data-slot":"accordion-trigger",className:Ts("focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",a),...t,children:[s,e.jsx(ca,{className:"text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200"})]})})}function $m({className:a,children:s,...t}){return e.jsx(qm,{"data-slot":"accordion-content",className:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",...t,children:e.jsx("div",{className:Ts("pt-0 pb-4",a),children:s})})}const Hn={"privacy-policy":"privacy","terms-of-service":"terms","cookie-policy":"cookie"},Bm=[{value:"job-portal",label:"Job Portal"},{value:"marketing-web",label:"Marketing Site"}],Ft=[{value:"privacy-policy",label:"Privacy Policy"},{value:"terms-of-service",label:"Terms of Service"},{value:"cookie-policy",label:"Cookie Policy"}],Xi=[{value:"text",label:"Text Block",icon:da},{value:"list",label:"Bullet List",icon:Oc},{value:"grid",label:"Grid Layout",icon:Rc},{value:"contact",label:"Contact Info",icon:Is},{value:"faq",label:"FAQ Section",icon:ga},{value:"hero",label:"Hero Section",icon:Ic}];function Um({section:a,index:s,onUpdate:t,onDelete:n}){const{attributes:i,listeners:c,setNodeRef:r,transform:o,transition:l,isDragging:_}=Mc({id:a.id||a._tempId||`temp-${s}`}),h={transform:qc.Transform.toString(o),transition:l,opacity:_?.5:1},N=Xi.find(b=>b.value===a.section_type),g=(N==null?void 0:N.icon)||da;return e.jsx("div",{ref:r,style:h,className:"mb-4",children:e.jsx(Om,{type:"single",collapsible:!0,className:"w-full",children:e.jsxs(Rm,{value:`section-${s}`,className:"border rounded-lg bg-card",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4",children:[e.jsx("button",{className:"cursor-grab hover:bg-muted rounded p-1",...i,...c,children:e.jsx($c,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(g,{className:"h-4 w-4 text-primary"}),e.jsx(Im,{className:"flex-1 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2 text-left",children:[e.jsx("span",{className:"font-medium",children:a.title||`Section ${s+1}`}),e.jsx(ee,{variant:"outline",className:"text-xs",children:(N==null?void 0:N.label)||a.section_type}),!a.is_active&&e.jsx(ee,{variant:"secondary",className:"text-xs",children:"Hidden"})]})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:b=>{b.stopPropagation(),n(s)},children:e.jsx(Le,{className:"h-4 w-4"})})]}),e.jsx($m,{className:"px-4 pb-4",children:e.jsx(Gm,{section:a,onUpdate:b=>t(s,b)})})]})})})}function Gm({section:a,onUpdate:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Section Title"}),e.jsx(E,{value:a.title,onChange:t=>s({title:t.target.value}),placeholder:"Enter section title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Section Type"}),e.jsxs(ke,{value:a.section_type,onValueChange:t=>s({section_type:t}),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsx(Pe,{children:Xi.map(t=>e.jsx(X,{value:t.value,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.icon,{className:"h-4 w-4"}),t.label]})},t.value))})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{checked:a.is_active,onCheckedChange:t=>s({is_active:t})}),e.jsx(x,{children:"Active / Visible"})]}),e.jsx(ra,{}),a.section_type==="text"&&e.jsx(Vm,{content:a.content,onUpdate:t=>s({content:t})}),a.section_type==="list"&&e.jsx(Qm,{content:a.content,onUpdate:t=>s({content:t})}),a.section_type==="grid"&&e.jsx(Km,{content:a.content,onUpdate:t=>s({content:t})}),a.section_type==="contact"&&e.jsx(Hm,{content:a.content,onUpdate:t=>s({content:t})}),a.section_type==="faq"&&e.jsx(Wm,{content:a.content,onUpdate:t=>s({content:t})}),a.section_type==="hero"&&e.jsx(Ym,{content:a.content,onUpdate:t=>s({content:t})})]})}
4function Vm({content:a,onUpdate:s}){const t=(a==null?void 0:a.paragraphs)||[""];return e.jsxs("div",{className:"space-y-3",children:[e.jsx(x,{children:"Paragraphs"}),t.map((n,i)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ce,{value:n,onChange:c=>{const r=[...t];r[i]=c.target.value,s({...a,paragraphs:r})},placeholder:"Enter paragraph text...",className:"min-h-[80px]"}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>{const c=t.filter((r,o)=>o!==i);s({...a,paragraphs:c.length?c:[""]})},children:e.jsx(Le,{className:"h-4 w-4"})})]},i)),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>s({...a,paragraphs:[...t,""]}),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add Paragraph"]})]})}function Qm({content:a,onUpdate:s}){const t=(a==null?void 0:a.items)||[""];return e.jsxs("div",{className:"space-y-3",children:[e.jsx(x,{children:"List Items"}),t.map((n,i)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"â¢"}),e.jsx(E,{value:n,onChange:c=>{const r=[...t];r[i]=c.target.value,s({...a,items:r})},placeholder:"Enter list item..."})]}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>{const c=t.filter((r,o)=>o!==i);s({...a,items:c.length?c:[""]})},children:e.jsx(Le,{className:"h-4 w-4"})})]},i)),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>s({...a,items:[...t,""]}),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add Item"]})]})}function Km({content:a,onUpdate:s}){var n;const t=(a==null?void 0:a.cards)||[{title:"",description:""}];return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Grid Cards"}),e.jsxs(ke,{value:((n=a==null?void 0:a.columns)==null?void 0:n.toString())||"3",onValueChange:i=>s({...a,columns:parseInt(i)}),children:[e.jsx(Se,{className:"w-24",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"2",children:"2 Columns"}),e.jsx(X,{value:"3",children:"3 Columns"}),e.jsx(X,{value:"4",children:"4 Columns"})]})]})]}),t.map((i,c)=>e.jsx(W,{className:"p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{value:i.title,onChange:r=>{const o=[...t];o[c]={...i,title:r.target.value},s({...a,cards:o})},placeholder:"Card title..."}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>{const r=t.filter((o,l)=>l!==c);s({...a,cards:r.length?r:[{title:"",description:""}]})},children:e.jsx(Le,{className:"h-4 w-4"})})]}),e.jsx(Ce,{value:i.description,onChange:r=>{const o=[...t];o[c]={...i,description:r.target.value},s({...a,cards:o})}
4,placeholder:"Card description...",className:"min-h-[60px]"}),e.jsx(E,{value:i.icon||"",onChange:r=>{const o=[...t];o[c]={...i,icon:r.target.value},s({...a,cards:o})},placeholder:"Icon name (optional)..."})]})},c)),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>s({...a,cards:[...t,{title:"",description:""}]}),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add Card"]})]})}function Hm({content:a,onUpdate:s}){return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Email"}),e.jsx(E,{value:(a==null?void 0:a.email)||"",onChange:t=>s({...a,email:t.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Phone"}),e.jsx(E,{value:(a==null?void 0:a.phone)||"",onChange:t=>s({...a,phone:t.target.value}),placeholder:"+1 234 567 8900"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Address"}),e.jsx(Ce,{value:(a==null?void 0:a.address)||"",onChange:t=>s({...a,address:t.target.value}),placeholder:"Full address..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Business Hours"}),e.jsx(E,{value:(a==null?void 0:a.hours)||"",onChange:t=>s({...a,hours:t.target.value}),placeholder:"Mon-Fri 9AM-5PM"})]})]})}function Wm({content:a,onUpdate:s}){const t=(a==null?void 0:a.faqs)||[{question:"",answer:""}];return e.jsxs("div",{className:"space-y-3",children:[e.jsx(x,{children:"FAQ Items"}),t.map((n,i)=>e.jsx(W,{className:"p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{value:n.question,onChange:c=>{const r=[...t];r[i]={...n,question:c.target.value},s({...a,faqs:r})},placeholder:"Question..."}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>{const c=t.filter((r,o)=>o!==i);s({...a,faqs:c.length?c:[{question:"",answer:""}]})},children:e.jsx(Le,{className:"h-4 w-4"})})]}),e.jsx(Ce,{value:n.answer,onChange:c=>{const r=[...t];r[i]={...n,answer:c.target.value},s({...a,faqs:r})},placeholder:"Answer...",className:"min-h-[80px]"})]})},i)),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>s({...a,faqs:[...t,{question:"",answer:""}]}),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add FAQ"]})]})}function Ym({content:a,onUpdate:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Headline"}),e.jsx(E,{value:(a==null?void 0:a.headline)||"",onChange:t=>s({...a,headline:t.target.value}),placeholder:"Main headline..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Subheadline"}),e.jsx(Ce,{value:(a==null?void 0:a.subheadline)||"",onChange:t=>s({...a,subheadline:t.target.value}),placeholder:"Supporting text..."})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Primary Button Text"}),e.jsx(E,{value:(a==null?void 0:a.primaryButtonText)||"",onChange:t=>s({...a,primaryButtonText:t.target.value}),placeholder:"Get Started"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Primary Button Link"}),e.jsx(E,{value:(a==null?void 0:a.primaryButtonLink)||"",onChange:t=>s({...a,primaryButtonLink:t.target.value}),placeholder:"/signup"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Secondary Button Text"}),e.jsx(E,{value:(a==null?void 0:a.secondaryButtonText)||"",onChange:t=>s({...a,secondaryButtonText:t.target.value}),placeholder:"Learn More"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Secondary Button Link"}),e.jsx(E,{value:(a==null?void 0:a.secondaryButtonLink)||"",onChange:t=>s({...a,secondaryButtonLink:t.target.value}),placeholder:"/about"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Backgroun
4d Image URL"}),e.jsx(E,{value:(a==null?void 0:a.backgroundImage)||"",onChange:t=>s({...a,backgroundImage:t.target.value}),placeholder:"https://..."})]})]})}function Jm(){var Qe;const[a,s]=m.useState("job-portal"),[t,n]=m.useState("privacy-policy"),[i,c]=m.useState(null),[r,o]=m.useState(!1),[l,_]=m.useState(!1),[h,N]=m.useState(""),[g,b]=m.useState(void 0),[P,z]=m.useState(!0),[p,M]=m.useState([]),[A,O]=m.useState({}),[k,j]=m.useState(""),{data:S,isLoading:d,refetch:L}=pm({site_type:a,content_type:Hn[t]}),{data:I,isLoading:B}=gm(i,{skip:!i}),[y,{isLoading:F}]=jm(),[K,{isLoading:q}]=fm(),[U,{isLoading:re}]=vm(),[te,{isLoading:G}]=ym(),w=Cc(Mn(Lc),Mn(Dc,{coordinateGetter:Ec}));m.useEffect(()=>{const Te=((S==null?void 0:S.data)||[])[0];Te?c(Te.id):(c(null),Y())},[S]),m.useEffect(()=>{if(I!=null&&I.data){const oe=I.data;N(oe.title||""),b(oe.slug||""),z(oe.is_active??!0),M(oe.sections||[]),O(oe.meta||{}),j(oe.change_summary||"")}},[I]);function Y(){const oe=Ft.find(Te=>Te.value===t);N((oe==null?void 0:oe.label)||""),b(t),z(!0),M([]),O({}),j("")}function ue(oe){const{active:Te,over:we}=oe;if(we&&Te.id!==we.id){const Ze=p.findIndex(R=>(R.id||R._tempId)===Te.id),f=p.findIndex(R=>(R.id||R._tempId)===we.id),ie=zc(p,Ze,f).map((R,H)=>({...R,sort_order:H}));M(ie)}}function J(){const oe={_tempId:`temp-${Date.now()}`,title:`New Section ${p.length+1}`,section_type:"text",content:{paragraphs:[""]},sort_order:p.length,is_active:!0};M([...p,oe])}function ge(oe,Te){const we=[...p];we[oe]={...we[oe],...Te},M(we)}function he(oe){M(p.filter((Te,we)=>we!==oe))}async function me(){var Te;const oe={title:h,slug:g,site_type:a,content_type:Hn[t],is_active:P,meta:A,change_summary:k||null,sections:p.map((we,Ze)=>({id:we.id,title:we.title,section_type:we.section_type,content:we.content,sort_order:Ze,is_active:we.is_active}))};try{if(i)await K({id:i,body:oe}).unwrap(),v.success("Page updated successfully");else{const we=await y(oe).unwrap();c((Te=we.data)==null?void 0:Te.id),v.success("Page created successfully")}L()}catch(we){v.error("Failed to save page"),console.error(we)}}async function Z(){if(i){try{await U(i).unwrap(),v.success("Page deleted successfully"),c(null),Y(),L()}catch{v.error("Failed to delete page")}o(!1)}}async function ne(){var oe;if(i){try{await te(i).unwrap(),v.success("Organizations are being notified with the updated document")}catch(Te){v.error(((oe=Te==null?void 0:Te.data)==null?void 0:oe.message)||"Failed to notify organizations")}_(!1)}}const _e=d||B,qe=F||q,fe=!!i&&a==="marketing-web"&&P;return e.jsxs(ye,{title:"",subtitle:"",children:[e.jsx("div",{className:"w-full min-w-0 bg-background py-4 sm:py-6",children:e.jsxs("div",{className:"mx-auto min-w-0 px-3 sm:px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(kc,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Content Management"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Create and manage structured content sections"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[fe&&e.jsxs(u,{variant:"outline",onClick:()=>_(!0),disabled:G,children:[G?e.jsx(ce,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Sc,{className:"h-4 w-4 mr-1"}),"Notify Organizations"]}),e.jsxs(u,{onClick:me,disabled:qe,children:[qe?e.jsx(ce,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(ht,{className:"h-4 w-4 mr-1"}),"Save Changes"]})]})]}),e.jsx(W,{className:"mb-6",children:e.jsx(Q,{className:"py-4",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Site"}),e.jsxs(ke,{value:a,onValueChange:oe=>s(oe),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsx(Pe,{children:Bm.map(oe=>e.jsx(X,{value:oe.value,children:oe.label},oe.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Page Type"}),e.jsxs(ke,{value:t,onValueChange:oe=>n(oe),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsx(Pe,{children:Ft.map(oe=>e.jsx(X,{value:oe.value,children:oe.label},oe.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Status"}),e.jsx("div",{className:"flex items-center gap-2 h-10",children:i?e.jsx(ee,{variant:"default",className:"bg-green-500",children:"Exists"}):e.jsx(ee,{variant:"secondary",children:"New Page"})})]})]})})}),_e?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs(W,{className:"lg:col-span-1",children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(an,{className:"h-4 w-4"}),"Page Settings"]})}),e.jsxs(Q,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Page Title"}),e.jsx(E,{value:h,onChange:oe=>N(oe.target.value),placeholder:"Enter page title"})]}),e.jsx(ra,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"General Description"}),e.jsx(Ce,{value:(A==null?void 0:A.generalDescription)||"",onChange:oe=>O({...A,generalDescription:oe.target.value}),placeholder:"Short description shown on listings or previews",className:"min-h-[80px]"})]}),a==="marketing-web"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"What Changed"}),e.jsx(Ce,{value:k,onChange:oe=>j(oe.target.value),placeholder:"e.g. Added a section on data retention and updated the data-sharing clause",className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Shown in the "policy updated" email sent to organizations - s
4ave the page after editing this before using Notify Organizations.'})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx(ra,{}),e.jsxs(u,{variant:"destructive",className:"w-full",onClick:()=>o(!0),children:[e.jsx(Le,{className:"h-4 w-4 mr-1"}),"Delete Page"]})]})]})]}),e.jsxs(W,{className:"lg:col-span-2",children:[e.jsx(se,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"Content Sections"}),e.jsx(je,{children:"Drag to reorder. Click to expand and edit."})]}),e.jsxs(u,{onClick:J,size:"sm",children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add Section"]})]})}),e.jsx(Q,{children:p.length===0?e.jsxs("div",{className:"text-center py-12 border-2 border-dashed rounded-lg",children:[e.jsx(da,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"font-medium mb-2",children:"No sections yet"}),e.jsx("p",{className:"text-muted-foreground text-sm mb-4",children:"Add your first content section to get started"}),e.jsxs(u,{onClick:J,variant:"outline",children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Add Section"]})]}):e.jsx(Ac,{sensors:w,collisionDetection:Pc,onDragEnd:ue,children:e.jsx(Tc,{items:p.map(oe=>oe.id||oe._tempId||""),strategy:Fc,children:e.jsx(nn,{className:"h-[600px] pr-4",children:p.map((oe,Te)=>e.jsx(Um,{section:oe,index:Te,onUpdate:ge,onDelete:he},oe.id||oe._tempId))})})})})]})]})]})}),e.jsx(ss,{open:r,onOpenChange:o,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete this page?"}),e.jsx(is,{children:"This action cannot be undone. This will permanently delete the page and all its sections."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:Z,className:"bg-destructive text-destructive-foreground",children:re?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"Delete"})]})]})}),e.jsx(ss,{open:l,onOpenChange:_,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Notify all organizations?"}),e.jsxs(is,{children:["This will email every active organization's primary user an updated PDF copy of this ",(Qe=Ft.find(oe=>oe.value===t))==null?void 0:Qe.label,'. This uses the currently saved version of the page, not any unsaved changes - including the saved "What Changed" text and a link to the live policy page.']})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:ne,children:G?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"Notify"})]})]})})]})}const Xm="https://api.sovohr.com";function Wn(a){return a?a.startsWith("http")?a:`${Xm}${a}`:""}function Zm(){const[a,s]=m.useState("all"),[t,n]=m.useState(null),[i,c]=m.useState(!1),[r,o]=m.useState("pending"),[l,_]=m.useState(""),[h,N]=m.useState(""),{data:g,isLoading:b}=Wo({status:a==="all"?void 0:a}),{data:P}=Li(),[z,{isLoading:p}]=Yo(),M=(g==null?void 0:g.data)||[],A=!!t&&r==="resolved"&&t.status!=="resolved",O=async()=>{if(t){if(A&&!h.trim()){v.error("Add a message to send to the submitter, or leave the status unchanged.");return}try{await z({id:t.id,data:{status:r,admin_notes:l,...A?{resolution_message:h.trim()}:{}}}).unwrap(),v.success(A?`Ticket resolved - email sent to ${t.user.email}`:"Ticket status updated successfully"),c(!1)}catch(d){console.error("Error updating ticket:",d),v.error("Failed to update ticket status")}}},k=d=>{n(d),o(d.status),_(d.admin_notes||""),N(d.resolution_message||d.default_resolution_message||""),c(!0)},j=d=>{const L={pending:{variant:"destructive",icon:Oe},contacted:{variant:"default",icon:zs},resolved:{variant:"default",icon:ps}},I=L[d]||L.pending,B=I.icon;return e.jsxs(ee,{variant:I.variant,className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),d.charAt(0).toUpperCase()+d.slice(1)]})},S=d=>{const L={low:"bg-blue-100 text-blue-800",medium:"bg-yellow-100 text-yellow-800",high:"bg-red-100 text-red-800"};return e.jsx(ee,{className:L[d]||L.medium,children:d.charAt(0).toUpperCase()+d.slice(1)})};return e.jsx(ye,{title:"Support",subtitle:"Manage Support Tickets",link:"/admin-dashboard/support",children:e.jsxs("main",{className:"flex flex-1 flex-col gap-6 p-4 md:p-8",children:[P&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 md:grid-cols-3 lg:grid-cols-5",children:[e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total Tickets"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:P.total})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Pending"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:P.pending})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Contacted"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:P.contacted})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Resolved"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:P.resolved})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"High Priority"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-orange-600",children:P.high_priority})})]})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(ke,{value:a,onValueChange:s,children:[e.jsx(Se,{className:"w-[180px]",children:e.jsx(Ae,{placeholder:"Filter by status"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All Tickets"}),e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"resolved",children:"Resolved"})]})]})}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Support Tickets"}),e.jsx(je,{children:"Manage and respond to support requests"})]}),e.jsx(Q,{children:b?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading tickets..."}):M.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No tickets found"}):e.jsx("div",{className:"space-y-4",children:M.map(d=>e.jsxs("div",{className:"border rounded-lg p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1 flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:["#",d.id]}),e.jsx("h3",{className:"font-semibold break-words",children:d.subject}),j(d.status),S(d.priority)]}),e.jsxs("p",{className:"text-sm text-muted-foreground break-words",children:[d.organization.name," ⢠",d.user.n
4ame," ⢠",new Date(d.created_at).toLocaleDateString()]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-xs text-muted-foreground pt-1",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 max-w-full break-words",children:[e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0"}),d.organization.organization_email||d.organization.login_email||"N/A"]}),e.jsxs("span",{className:"inline-flex items-center gap-1 max-w-full break-words",children:[e.jsx(Is,{className:"h-3.5 w-3.5 shrink-0"}),d.organization.contact_number||"N/A"]})]})]}),e.jsx(u,{variant:"outline",size:"sm",className:"shrink-0 self-start",onClick:()=>k(d),children:"Update Status"})]}),e.jsx("p",{className:"text-sm break-words",children:d.message}),d.attachment_url&&e.jsxs("a",{href:Wn(d.attachment_url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-primary hover:underline max-w-full break-words",children:[e.jsx(Qt,{className:"h-4 w-4 shrink-0"}),d.attachment_name||"View attachment"]}),d.admin_notes&&e.jsxs("div",{className:"bg-muted p-2 rounded text-sm break-words",children:[e.jsx("strong",{children:"Admin Notes:"})," ",d.admin_notes]})]},d.id))})})]}),e.jsx(Fe,{open:i,onOpenChange:c,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Update Ticket Status"}),e.jsxs(Ge,{children:["Update the status and add notes for ticket #",t==null?void 0:t.id]})]}),(t==null?void 0:t.organization)&&e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3 text-sm space-y-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium break-words",children:[e.jsx(Xe,{className:"h-4 w-4 shrink-0"}),t.organization.name]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 max-w-full break-words",children:[e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0"}),t.organization.organization_email||t.organization.login_email||"N/A"]}),e.jsxs("span",{className:"inline-flex items-center gap-1 max-w-full break-words",children:[e.jsx(Is,{className:"h-3.5 w-3.5 shrink-0"}),t.organization.contact_number||"N/A"]})]})]}),(t==null?void 0:t.attachment_url)&&e.jsxs("a",{href:Wn(t.attachment_url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-primary hover:underline max-w-full break-words",children:[e.jsx(Qt,{className:"h-4 w-4 shrink-0"}),t.attachment_name||"View attachment"]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Status"}),e.jsxs(ke,{value:r,onValueChange:d=>o(d),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"resolved",children:"Resolved"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Admin Notes"}),e.jsx(Ce,{value:l,onChange:d=>_(d.target.value),placeholder:"Internal only - never sent to the customer.",rows:4})]}),A&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-green-300 bg-green-50 p-3",children:[e.jsxs("label",{className:"text-sm font-medium",children:["Resolution email to ",t==null?void 0:t.user.email]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This is what will be sent when you update. Edit it however you like."}),e.jsx(Ce,{value:h,onChange:d=>N(d.target.value),rows:8,className:"bg-white"})]}),!A&&(t==null?void 0:t.resolution_message)&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Resolution email already sent"}),e.jsx(Ce,{value:t.resolution_message,readOnly:!0,rows:5})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(u,{onClick:O,disabled:p,children:p?"Updating...":A?"Resolve & Send Email":"Update Ticket"})]})]})})]})})}const eu=He.injectEndpoints({endpoints:a=>({getVideoTutorials:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.category&&n.push(`category=${encodeURIComponent(s.category)}`),(s==null?void 0:s.is_active)!==void 0&&n.push(`is_active=${s.is_active}`),{url:`/admin/video-tutorials?${n.join("&")}`,method:"GET"}},providesTags:s=>s!=null&&s.data?[...s.data.map(t=>
4({type:"video-tutorials",id:t.id})),{type:"video-tutorials",id:"LIST"}]:[{type:"video-tutorials",id:"LIST"}]}),getVideoTutorial:a.query({query:s=>({url:`/admin/video-tutorials/${s}`,method:"GET"}),providesTags:(s,t,n)=>[{type:"video-tutorials",id:n}]}),createVideoTutorial:a.mutation({query:s=>({url:"/admin/video-tutorials",method:"POST",body:s}),invalidatesTags:[{type:"video-tutorials",id:"LIST"}]}),updateVideoTutorial:a.mutation({query:({id:s,body:t})=>({url:`/admin/video-tutorials/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"video-tutorials",id:n},{type:"video-tutorials",id:"LIST"}]}),deleteVideoTutorial:a.mutation({query:s=>({url:`/admin/video-tutorials/${s}`,method:"DELETE"}),invalidatesTags:[{type:"video-tutorials",id:"LIST"}]}),getVideoTutorialCategories:a.query({query:()=>({url:"/admin/video-tutorials-categories",method:"GET"})})}),overrideExisting:!0}),{useGetVideoTutorialsQuery:su,useCreateVideoTutorialMutation:au,useUpdateVideoTutorialMutation:tu,useDeleteVideoTutorialMutation:nu}=eu,zt={title:"",description:"",video_url:"",thumbnail_url:"",duration:"",category:"",icon:"",sort_order:0,is_active:!0};function iu(){const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(!1),[r,o]=m.useState(null),[l,_]=m.useState(zt),[h,N]=m.useState(null),{data:g,isLoading:b}=su({page:a}),[P,{isLoading:z}]=au(),[p,{isLoading:M}]=tu(),[A,{isLoading:O}]=nu(),k=(g==null?void 0:g.data)||[],j=(g==null?void 0:g.meta)||{last_page:1},S=k.filter(y=>y.title.toLowerCase().includes(t.toLowerCase())||y.category.toLowerCase().includes(t.toLowerCase())),d=()=>{o(null),_(zt),c(!0)},L=y=>{o(y),_({title:y.title,description:y.description||"",video_url:y.video_url||"",thumbnail_url:y.thumbnail_url||"",duration:y.duration||"",category:y.category,icon:y.icon||"",sort_order:y.sort_order,is_active:y.is_active}),c(!0)},I=async y=>{if(y.preventDefault(),!l.title||!l.category){v.error("Title and category are required");return}try{r?(await p({id:r.id,body:l}).unwrap(),v.success("Video tutorial updated successfully")):(await P(l).unwrap(),v.success("Video tutorial created successfully")),c(!1),_(zt),o(null)}catch(F){console.error(F),v.error("Failed to save video tutorial")}},B=async y=>{try{await A(y).unwrap(),v.success("Video tutorial deleted successfully"),N(null)}catch(F){console.error(F),v.error("Failed to delete video tutorial")}};return e.jsx(ye,{title:"Video Tutorials",subtitle:"",link:"",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Bc,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Video Tutorials"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage support video tutorials"})]})]}),e.jsxs(u,{onClick:d,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Tutorial"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search by title or category...",value:t,onChange:y=>n(y.target.value),className:"max-w-sm"})]})})}),e.jsxs(W,{className:"mt-4",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"All Video Tutorials"}),e.jsxs(je,{children:[k.length," total tutorials"]})]}),e.jsxs(Q,{children:[b?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Title"}),e.jsx(T,{children:"Category"}),e.jsx(T,{children:"Duration"}),e.jsx(T,{children:"Order"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:S.length===0?e.jsx(le,{children:e.jsx(C,{colSpan:6,className:"text-center py-8 text-muted-foreground",children:"No tutorials found"})}):S.map(y=>e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[y.thumbnail_url&&e.jsx("img",{src:y.thumbnail_url,alt:y.title,className:"w-16 h-10 object-cover rounded"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:y.title}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:y.description})]})]})}),e.jsx(C,{children:e.jsx(ee,{variant:"secondary",children:y.category})}),e.jsx(C,{children:y.duration||"-"}),e.jsx(C,{children:y.sort_order}),e.jsx(C,{children:e.jsx(ee,{variant:y.is_active?"default":"outline",children:y.is_active?"Active":"Inactive"})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[y.video_url&&e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>window.open(y.video_url,"_blank"),children:e.jsx(Si,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>L(y),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>N(y.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})})]},y.id))})]}),j.last_page>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-4",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:a===1,onClick:()=>s(a-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",a," of ",j.last_page]}),e.jsx(u,{variant:"outline",size:"sm",disabled:a===j.last_page,onClick:()=>s(a+1),children:"Next"})]})]})]}),e.jsx(Fe,{open:i,onOpenChange:c,children:e.jsx(ze,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:e.jsxs("form",{onSubmit:I,children:[e.jsxs(Ee,{children:[e.jsx(De,{children:r?"Edit Tutorial":"Add Tutorial"}),e.jsx(Ge,{children:r?"Update video tutorial details":"Create a new video tutorial"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"title",children:"Title *"}),e.jsx(E,{id:"title",value:l.title,onChange:y=>_({...l,title:y.target.value}),placeholder:"e.g., Getting Started with HR Portal",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(Ce,{id:"description",value:l.description,onChange:y=>_({...l,description:y.target.value}),placeholder:"Brief description of the tutorial",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"category",children:"Category *"}),e.jsx(E,{id:"category",value:l.category,onChange:y=>_({...l,category:y.target.value}),placeholder:"e.g., Getting Started, Attendance, Leave",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"video_url",children:"Video URL"}),e.jsx(E,{id:"video_url",value:l.video_url,onChange:y=>_({...l,video_url:y.target.value}),placeholder:"https://www.youtube.com/watch?v=..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"thumbnail_url",children:"Thumbnail URL"}),e.jsx(E,{id:"thumbnail_url",value:l.thumbnail_url,onChange:y=>_({...l,thumbnail_url:y.target.value}),placeholder:"https://..."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"duration",children:"Duration"}),e.jsx(E,{id:"duration",value:l.duration,onChange:y=>_({...l,duration:y.target.value}),placeholder:"e.g., 5:30"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"sort_order",children:"Sort Order"}),e.jsx(E,{id:"sort_order",type:"number",value:l.sort_order,onChange:y=>_({...l,sort_order:parseInt(y.target.value)||0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"icon",children:"Icon Name (optional)"}),e.jsx(E,{id:"icon",value:l.icon,onChange:y=>_({...l,icon:y.target.value}),placeholder:"e.g., Briefcase, Users, Calendar"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_active",checked:l.is_active,onCheckedChange:y=>_({...l,is_active:y})}),e.jsx(x,{htmlFor:"is_active",children:"Active"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(u,{type:"submit",disabled:z||M,children:z||M?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):r?"Update":"Create"})]})]})})}),e.jsx(Fe,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Confirm Delete"}),e.jsx(Ge,{children:"Are you sure you want to delete this video tutorial? This action cannot be undone."})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>N(null),children:"Cancel"}),e.jsx(u,{variant:"destructive",onClick:()=>h&&B(h),disabled:O,children:O?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):"Delete"})]})]})})]})})}const ru=He.injectEndpoints({endpoints:a=>
4({getSupportFaqs:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.category&&n.push(`category=${encodeURIComponent(s.category)}`),(s==null?void 0:s.is_active)!==void 0&&n.push(`is_active=${s.is_active}`),{url:`/admin/support-faqs?${n.join("&")}`,method:"GET"}},providesTags:s=>s!=null&&s.data?[...s.data.map(t=>({type:"support-faqs",id:t.id})),{type:"support-faqs",id:"LIST"}]:[{type:"support-faqs",id:"LIST"}]}),getSupportFaq:a.query({query:s=>({url:`/admin/support-faqs/${s}`,method:"GET"}),providesTags:(s,t,n)=>[{type:"support-faqs",id:n}]}),createSupportFaq:a.mutation({query:s=>({url:"/admin/support-faqs",method:"POST",body:s}),invalidatesTags:[{type:"support-faqs",id:"LIST"}]}),updateSupportFaq:a.mutation({query:({id:s,body:t})=>({url:`/admin/support-faqs/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"support-faqs",id:n},{type:"support-faqs",id:"LIST"}]}),deleteSupportFaq:a.mutation({query:s=>({url:`/admin/support-faqs/${s}`,method:"DELETE"}),invalidatesTags:[{type:"support-faqs",id:"LIST"}]}),getSupportFaqCategories:a.query({query:()=>({url:"/admin/support-faqs-categories",method:"GET"})})}),overrideExisting:!0}),{useGetSupportFaqsQuery:lu,useCreateSupportFaqMutation:cu,useUpdateSupportFaqMutation:ou,useDeleteSupportFaqMutation:du}=ru,Et={question:"",answer:"",category:"",sort_order:0,is_active:!0};function mu(){const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(!1),[r,o]=m.useState(null),[l,_]=m.useState(Et),[h,N]=m.useState(null),{data:g,isLoading:b}=lu({page:a}),[P,{isLoading:z}]=cu(),[p,{isLoading:M}]=ou(),[A,{isLoading:O}]=du(),k=(g==null?void 0:g.data)||[],j=(g==null?void 0:g.meta)||{last_page:1},S=k.filter(y=>{var F;return y.question.toLowerCase().includes(t.toLowerCase())||y.answer.toLowerCase().includes(t.toLowerCase())||(((F=y.category)==null?void 0:F.toLowerCase())||"").includes(t.toLowerCase())}),d=()=>{o(null),_(Et),c(!0)},L=y=>{o(y),_({question:y.question,answer:y.answer,category:y.category||"",sort_order:y.sort_order,is_active:y.is_active}),c(!0)},I=async y=>{if(y.preventDefault(),!l.question||!l.answer){v.error("Question and answer are required");return}try{r?(await p({id:r.id,body:l}).unwrap(),v.success("FAQ updated successfully")):(await P(l).unwrap(),v.success("FAQ created successfully")),c(!1),_(Et),o(null)}catch(F){console.error(F),v.error("Failed to save FAQ")}},B=async y=>{try{await A(y).unwrap(),v.success("FAQ deleted successfully"),N(null)}catch(F){console.error(F),v.error("Failed to delete FAQ")}};return e.jsx(ye,{title:"Support FAQs",subtitle:"",link:"",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(ga,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Support FAQs"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage frequently asked questions"})]})]}),e.jsxs(u,{onClick:d,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add FAQ"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search FAQs...",value:t,onChange:y=>n(y.target.value),className:"max-w-sm"})]})})}),e.jsxs(W,{className:"mt-4",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"All FAQs"}),e.jsxs(je,{children:[k.length," total FAQs"]})]}),e.jsxs(Q,{children:[b?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{className:"w-[35%]",children:"Question"}),e.jsx(T,{className:"w-[35%]",children:"Answer"}),e.jsx(T,{children:"Category"}),e.jsx(T,{children:"Order"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:S.length===0?e.jsx(le,{children:e.jsx(C,{colSpan:6,className:"text-center py-8 text-muted-foreground",children:"No FAQs foun
4d"})}):S.map(y=>e.jsxs(le,{children:[e.jsx(C,{children:e.jsx("p",{className:"font-medium line-clamp-2 break-words whitespace-pre-wrap max-w-[300px]",children:y.question})}),e.jsx(C,{children:e.jsx("p",{className:"text-muted-foreground text-sm break-words whitespace-pre-wrap max-w-[400px]",children:y.answer})}),e.jsx(C,{children:y.category?e.jsx(ee,{variant:"secondary",children:y.category}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"-"})}),e.jsx(C,{children:y.sort_order}),e.jsx(C,{children:e.jsx(ee,{variant:y.is_active?"default":"outline",children:y.is_active?"Active":"Inactive"})}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>L(y),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>N(y.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})})]},y.id))})]}),j.last_page>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-4",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:a===1,onClick:()=>s(a-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",a," of ",j.last_page]}),e.jsx(u,{variant:"outline",size:"sm",disabled:a===j.last_page,onClick:()=>s(a+1),children:"Next"})]})]})]}),e.jsx(Fe,{open:i,onOpenChange:c,children:e.jsx(ze,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:e.jsxs("form",{onSubmit:I,children:[e.jsxs(Ee,{children:[e.jsx(De,{children:r?"Edit FAQ":"Add FAQ"}),e.jsx(Ge,{children:r?"Update FAQ details":"Create a new frequently asked question"})]}),e.jsxs("div",{className:"space-y-5 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"question",className:"font-medium",children:["Question *"," "]}),e.jsx(E,{id:"question",value:l.question,onChange:y=>{const F=y.target.value;if(F.length>500){v.error("Question cannot exceed 500 characters");return}_({...l,question:F})},placeholder:"e.g., How do I manage my team members?",className:"h-10",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"answer",className:"font-medium",children:["Answer *"," "]}),e.jsx(Ce,{id:"answer",value:l.answer,onChange:y=>{const F=y.target.value;if(F.length>1e3){v.error("Answer cannot exceed 1000 characters");return}_({...l,answer:F})},placeholder:"Provide a detailed answer to the question...",rows:6,className:"resize-none",style:{overflowY:"auto",overflowX:"hidden",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:"180px"},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"category",className:"font-medium",children:["Category (Optional)"," "]}),e.jsx(E,{id:"category",value:l.category,onChange:y=>{const F=y.target.value;if(F.length>100){v.error("Category cannot exceed 100 characters");return}_({...l,category:F})},placeholder:"e.g., General, Attendance, Leave",className:"h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"sort_order",className:"font-medium",children:"Sort Order"}),e.jsx(E,{id:"sort_order",type:"number",value:l.sort_order,onChange:y=>_({...l,sort_order:parseInt(y.target.value)||0}),className:"h-10"})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(Ve,{id:"is_active",checked:l.is_active,onCheckedChange:y=>_({...l,is_active:y})}),e.jsx(x,{htmlFor:"is_active",className:"cursor-pointer",children:"Active"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(u,{type:"submit",disabled:z||M,children:z||M?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):r?"Update":"Create"})]})]})})}),e.jsx(Fe,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Confirm Delete"}),e.jsx(Ge,{children:"Are you sure you want to delete this FAQ? This action cannot be undone."})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>N(null),children:"Cancel"}),e.jsx(u,{variant:"destructive",onClick:()=>h&&B(h),disabled:O,children:O?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):"Delete"})]})]})})]})})}const uu={pending:"bg-yellow-100 text-yellow-800 border-yellow-300",contacted:"bg-indigo-100 text-indigo-800 border-indigo-300",in_progress:"bg-blue-100 text-blue-800 border-blue-300",resolved:"bg-green-100 text-green-800 border-green-300",closed:"bg-gray-100 text-gray-800 border-gray-300"},xu={pending:"Pending",contacted:"Contacted",in_progress:"In Progress",resolved:"Resolved",closed:"Closed"};function hu(){const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(""),[r,o]=m.useState(null),[l,_]=m.useState(null),[h,N]=m.useState("pending"),[g,b]=m.useState(""),[P,z]=m.useState(""),{data:p,isLoading:M,error:A}=ad({page:a,search:t,status:i.trim()||void 0}),{data:O}=qi(),k=(O==null?void 0:O.data)??O,[j]=nd(),[S,{isLoading:d}]=td(),L=p?Array.isArray(p.data)?p.data:p.data&&Array.isArray(p.data.data)?p.data.data:[]:[],I=(()=>
4{if(p){if(p.meta)return p.meta;if(p.data&&typeof p.data=="object"&&!Array.isArray(p.data))return p.data}})(),B=async()=>{var q;if(l)try{await j(l).unwrap(),v.success("Contact submission deleted successfully"),_(null)}catch(U){v.error(((q=U==null?void 0:U.data)==null?void 0:q.message)||"Failed to delete contact submission")}},y=q=>{o(q),N(q.status),b(q.admin_notes??""),z(q.resolution_message??q.default_resolution_message??"")},F=!!r&&h==="resolved"&&r.status!=="resolved",K=async()=>{var q;if(r){if(F&&!P.trim()){v.error("Add a message to send to the enquirer, or leave the status unchanged.");return}try{await S({id:r.id,body:{status:h,admin_notes:g,...F?{resolution_message:P.trim()}:{}}}).unwrap(),v.success(F?`Marked as resolved - email sent to ${r.email}`:"Status updated successfully"),o(null)}catch(U){v.error(((q=U==null?void 0:U.data)==null?void 0:q.message)||"Failed to update status")}}};return e.jsxs(ye,{title:"",subtitle:"",children:[e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsx("h1",{className:"text-3xl font-bold",children:"Contact Submissions"})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-4",children:[e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:(k==null?void 0:k.total)||0})})]}),e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Pending"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:(k==null?void 0:k.pending)||0})})]}),e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Contacted"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-indigo-600",children:(k==null?void 0:k.contacted)||0})})]}),e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"In Progress"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:(k==null?void 0:k.in_progress)||0})})]}),e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Resolved"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:(k==null?void 0:k.resolved)||0})})]}),e.jsxs(hs,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Closed"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-gray-600",children:(k==null?void 0:k.closed)||0})})]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search by name, email, or company...",value:t,onChange:q=>n(q.target.value),className:"pl-10"})]}),e.jsxs(ke,{value:i,onValueChange:c,children:[e.jsxs(Se,{className:"w-full md:w-[200px]",children:[e.jsx(fa,{className:"h-4 w-4 mr-2"}),e.jsx(Ae,{placeholder:"Filter by status"})]}),e.jsxs(Pe,{children:[e.jsx(X,{value:" ",children:"All Statuses"}),e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"in_progress",children:"In Progress"}),e.jsx(X,{value:"resolved",children:"Resolved"}),e.jsx(X,{value:"closed",children:"Closed"})]})]})]})})}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:M?e.jsx("div",{className:"text-center py-10",children:"Loading..."}):A?e.jsx("div",{className:"text-center py-10 text-red-500",children:"Error loading submissions"}):L.length===0?e.jsx("div",{className:"text-center py-10 text-muted-foreground",children:"No submissions found"}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Email"}),e.jsx(T,{children:"Company"}),e.jsx(T,{children:"Subject"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Submitted"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:L.map(q=>e.jsxs(le,{children:[e.jsx(C,{className:"font-medium",children:q.name}),e.jsx(C,{children:q.email}),e.jsx(C,{children:q.company||"-"}),e.jsx(C,{className:"max-w-xs truncate",children:q.subject||"-"}),e.jsx(C,{children:e.jsx(ee,{className:uu[q.status]||"",children:xu[q.status]||q.status})}),e.jsx(C,{children:new Date(q.created_at).toLocaleDateString()}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>y(q),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>_(q.id),children:e.jsx(Le,{className:"h-4 w-4 text-red-500"})})]})})]},q.id))})]}),I&&I.last_page>1&&e.jsx("div",{className:"mt-4",children:e.jsx(ot,{children:e.jsxs(dt,{children:[e.jsx(Ns,{children:e.jsx(mt,{onClick:()=>s(q=>Math.max(1,q-1)),className:a===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:I.last_page},(q,U)=>U+1).map(q=>e.jsx(Ns,{children:e.jsx(ut,{onClick:()=>s(q),isActive:a===q,className:"cursor-pointer",children:q})},q)),e.jsx(Ns,{children:e.jsx(xt,{onClick:()=>s(q=>Math.min(I.last_page,q+1)),className:a===I.last_page?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})})})]}),e.jsx(Fe,{open:!!r,onOpenChange:()=>o(null),children:e.jsxs(ze,{className:"max-w-2xl",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Contact Submission Details"}),e.jsxs(Ge,{children:["Submitted on ",r&&new Date(r.created_at).toLocaleStr
4ing()]})]}),r&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Name"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:r.name})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Email"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:r.email})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Phone"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:r.phone||"-"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Company"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:r.company||"-"})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Subject"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:r.subject||"-"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Message"}),e.jsx(Ce,{value:r.message,readOnly:!0,rows:6,className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Status"}),e.jsxs(ke,{value:h,onValueChange:q=>N(q),disabled:d,children:[e.jsx(Se,{className:"mt-1",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"in_progress",children:"In Progress"}),e.jsx(X,{value:"resolved",children:"Resolved"}),e.jsx(X,{value:"closed",children:"Closed"})]})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Internal Notes"}),e.jsx(Ce,{value:g,onChange:q=>b(q.target.value),rows:3,className:"mt-1",placeholder:"Only visible here - never sent to the enquirer."})]}),F&&e.jsxs("div",{className:"rounded-lg border border-green-300 bg-green-50 p-3",children:[e.jsxs(x,{children:["Resolution email to ",r.email]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This is what will be sent when you save. Edit it however you like."}),e.jsx(Ce,{value:P,onChange:q=>z(q.target.value),rows:8,className:"mt-2 bg-white"})]}),!F&&r.resolution_message&&e.jsxs("div",{children:[e.jsx(x,{children:"Resolution email already sent"}),e.jsx(Ce,{value:r.resolution_message,readOnly:!0,rows:5,className:"mt-1"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>o(null),children:"Cancel"}),e.jsx(u,{onClick:K,disabled:d,children:d?"Saving...":F?"Resolve & Send Email":"Save Changes"})]})]})}),e.jsx(ss,{open:!!l,onOpenChange:()=>_(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete Contact Submission"}),e.jsx(is,{children:"Are you sure you want to delete this contact submission? This action cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:B,className:"bg-red-500 hover:bg-red-600",children:"Delete"})]})]})})]})}const pu=He.injectEndpoints({endpoints:a=>({getCustomerFeedback:a.query({query:s=>({url:"/admin/customer-feedback",method:"GET",params:{page:(s==null?void 0:s.page)??1,status:(s==null?void 0:s.status)||void 0,search:(s==null?void 0:s.search)||void 0,rating:(s==null?void 0:s.rating)||void 0,campaign_id:(s==null?void 0:s.campaign_id)||void 0,detractors_only:s!=null&&s.detractors_only?1:void 0}}),providesTags:["customer-feedback"]}),getCustomerFeedbackStats:a.query({query:()=>({url:"/admin/customer-feedback/stats",method:"GET"}),providesTags:["customer-feedback"]}),updateCustomerFeedbackStatus:a.mutation({query:({id:s,body:t})=>({url:`/admin/customer-feedback/${s}/status`,method:"PUT",body:t}),invalidatesTags:["customer-feedback"]}),deleteCustomerFeedback:a.mutation({query:s=>({url:`/admin/customer-feedback/${s}`,method:"DELETE"}),invalidatesTags:["customer-feedback"]}),getFeedbackCampaigns:a.query({query:()=>({url:"/admin/customer-feedback/campaigns",method:"GET"}),providesTags:["feedback-campaigns"]}),createFeedbackCampaign:a.mutation({query:s=>({url:"/admin/customer-feedback/campaigns",method:"POST",body:s}),invalidatesTags:["feedback-campaigns"]}),updateFeedbackCampaign:a.mutation({query:({id:s,body:t})=>({url:`/admin/customer-feedback/campaigns/${s}`,method:"PUT",body:t}),invalidatesTags:["feedback-campaigns"]}),deleteFeedbackCampaign:a.mutation({query:s=>({url:`/admin/customer-feedback/campaigns/${s}`,method:"DELETE"}),invalidatesTags:["feedback-campaigns"]}),previewFeedbackEmail:a.mutation({query:s=>({url:"/admin/customer-feedback/campaigns/email-preview",method:"POST",body:s})}),sendTestFeedbackEmail:a.mutation({query:s=>({url:"/admin/customer-feedback/campaigns/email-test",method:"POST",body:s})}),previewFeedbackCampaign:a.query({query:s=>({url:`/admin/customer-feedback/campaigns/${s}/preview`,method:"GET"}),providesTags:["feedback-campaigns"]}),runFeedbackCampaign:a.mutation({query:({id:s,dry_run:t})=>({url:`/admin/customer-feedback/campaigns/${s}/run`,method:"POST",body:{dry_run:t??!1}}),invalidatesTags:["feedback-campaigns","customer-feedback"]})}),overrideExisting:!0}),{useGetCustomerFeedbackQuery:gu,useGetCustomerFeedbackStatsQuery:ju,useUpdateCustomerFeedbackStatusMutation:fu,useDeleteCustomerFeedbackMutation:vu,useGetFeedbackCampaignsQuery:yu,useCreateFeedbackCampaignMutation:Nu,useUpdateFeedbackCampaignMutation:bu,useDeleteFeedbackCampaignMutation:_u,usePreviewFeedbackEmailMutation:wu,useSendTestFeedbackEmailMutation:Cu,useRunFeedbackCampaignMutation:ku}=pu,Su=He.injectEndpoints({endpoints:a=>({getOrganizationOwners:a.query({query:()=>({url:"/admin/organization-owners",method:"GET"}),providesTags:[{type:"organizations",id:"OWNERS"}]}),previewAdminBroadcast:a.mutation({query:s=>({url:"/admin/email-broadcasts/preview",method:"POST",body:s})}),sendAdminBroadcast:a.mutation({query:s=>({url:"/admin/email-broadcasts",method:"POST",body:s}),invalidatesTags:["adminEmailLogs"]}),getAdminEmailLogs:a.query({query:s=>({url:"/admin/email-logs",method:"GET",params:s}),providesTags:["adminEmailLogs"]}),getAdminEmailLog:a.query({query:s=>({url:`/admin/email-logs/${s}`,method:"GET"}),transformResponse:s=>s.data,providesTags:(s,t,n)=>[{type:"adminEmailLogs",id:n}]}),retryAdminEmailLog:a.mutation({query:s=>({url:`/admin/email-logs/${s}/retry`,method:"POST"}),invalidatesTags:["adminEmailLogs"]}),deleteAdminEmailLog:a.mutation({query:s=>({url:`/admin/email-logs/${s}`,method:"DELETE"}),invalidatesTags:["adminEmailLogs"]})})}),{useGetOrganizationOwnersQuery:Zi,usePreviewAdminBroadcastMutation:Au,useSendAdminBroadcastMutation:Pu,useGetAdminEmailLogsQuery:Tu,useRetryAdminEmailLogMutation:Fu,useDeleteAdminEmailLogMutation:zu}=Su;function er({owners:a,isLoading:s=!1,mode:t,onModeChange:n,selectedIds:i,onSelectedIdsChange:c}){const[r,o]=m.useState(""),l=m.useMemo(()=>a.filter(b=>b.organization_status==="active").length,[a]),_=m.useMemo(()=>new Set(i),[i]),h=m.useMemo(()=>{const b=r.trim().toLowerCase();return b?a.filter(P=>[P.organization_name,P.name??"",P.email].some(z=>z.toLowerCase().includes(b))):a},[a,r]),N=(b,P)=>{const z=new Set(_);P?z.add(b):z.delete(b),c(Array.from(z))},g=()=>c(Array.from(new Set([...i,...h.map(b=>b.organization_id)])));return e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ke,{value:t,onValueChange:b=>n(b),children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsxs(X,{value:"all",children:["All active organizations",s?"":` (${l})`]}),e.jsx(X,{value:"selected",children:"Only selected organizations"})]})]}),t==="selected"&&e.jsxs("div",{className:"rounded-md border",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b p-2",children:[e.jsxs("div",{className:"relative min-w-[180px] flex-1",children:[e.jsx(xs,{className:"absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(E,{value:r,onChange:b=>o(b.target.value),placeholder:"Search organization, owner or email",className:"h-9 pl-8"})]}),e.jsx(u,{type:"button",variant:"ghost",size:"sm",onClick:g,disabled:h.length===0,children:"Select shown"}),e.jsx(u,{type:"button",variant:"ghost",size:"sm",onClick:()=>c([]),disabled:i.length===0,children:"Clear"})]}),e.jsx(nn,{className:"h-56",children:s?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading organizations..."}):h.length===0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No organizations match."}):e.jsx("ul",{className:"divide-y",children:h.map(b=>e.jsx("li",{children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 p-2.5 hover:bg-muted/50",children:[e.jsx(bs,{checked:_.has(b.organization_id),onCheckedChange:P=>N(b.organization_id,P===!0),className:"mt-0.5"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{className:"truncate",children:b.organization_name}),b.organization_status&&b.organization_status!=="active"&&e.jsx(ee,{variant:"secondary",className:"text-[10px] capitalize",children:b.organization_status})]}),e.jsxs("span",{className:"block truncate text-xs text-muted-foreground",children:[b.name?`${b.name} · `:"",b.email]})]})]})},b.organization_id))})}),e.jsxs("div",{className:"border-t px-3 py-2 text-xs text-muted-foreground",children:[i.length," selected"]})]})]})}const Eu={new:"bg-blue-100 text-blue-800 border-blue-300",reviewed:"bg-yellow-100 text-yellow-800 border-yellow-300",actioned:"bg-green-100 text-green-800 border-green-300",archived:"bg-gray-100 text-gray-800 border-gray-300"}
4,Du={new:"New",reviewed:"Reviewed",actioned:"Actioned",archived:"Archived"},Lu=[{months:1,label:"Every month"},{months:2,label:"Every 2 months"},{months:3,label:"Every quarter"},{months:6,label:"Every 6 months"},{months:12,label:"Once a year"}],Yn={name:"",description:"",frequency_months:3,form_type:"builtin",external_url:"",subject:"How are we doing?",intro_message:"We would really value a few minutes of your time. Tell us how SovoHR is working for you - what is going well, and where we should improve.",button_label:"Share your feedback",link_valid_days:30,is_active:!0,target_organization_ids:null};function Jn({rating:a}){return e.jsx("span",{className:"inline-flex items-center gap-0.5","aria-label":`${a} out of 5`,children:[1,2,3,4,5].map(s=>e.jsx(Ea,{className:`h-4 w-4 ${s<=a?"fill-amber-400 text-amber-400":"text-gray-300"}`},s))})}function Mu(){var Ls,Bs,ua,Us,vs,Ca,$a,Hs;const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(""),[r,o]=m.useState(!1),[l,_]=m.useState(null),[h,N]=m.useState(null),[g,b]=m.useState(!1),[P,z]=m.useState(null),[p,M]=m.useState(Yn),[A,O]=m.useState(null),[k,j]=m.useState(null),[S,d]=m.useState("all"),[L,I]=m.useState(null),[B,y]=m.useState(""),{data:F,isLoading:K,error:q}=gu({page:a,search:t,status:i||void 0,detractors_only:r||void 0}),{data:U}=ju(),{data:re,isLoading:te}=yu(),[G,{isLoading:w}]=fu(),[Y]=vu(),[ue,{isLoading:J}]=Nu(),[ge,{isLoading:he}]=bu(),[me]=_u(),[Z]=ku(),[ne,{isLoading:_e}]=wu(),[qe,{isLoading:fe}]=Cu(),{data:Qe,isLoading:oe}=Zi(void 0,{skip:!g}),Te=F?Array.isArray(F.data)?F.data:F.data&&Array.isArray(F.data.data)?F.data.data:[]:[],we=(()=>{if(F){if(F.meta)return F.meta;if(F.last_page)return F}})(),Ze=(re==null?void 0:re.data)??[],f=async V=>{var Ne;if(l)try{await G({id:l.id,body:{status:V,admin_notes:l.admin_notes}}).unwrap(),v.success("Status updated successfully"),_(null)}catch(os){v.error(((Ne=os==null?void 0:os.data)==null?void 0:Ne.message)||"Failed to update status")}},ie=async()=>{var V;if(h)try{await Y(h).unwrap(),v.success("Feedback deleted successfully"),N(null)}catch(Ne){v.error(((V=Ne==null?void 0:Ne.data)==null?void 0:V.message)||"Failed to delete feedback")}},R=V=>{var Ne;V?(z(V),M({name:V.name,description:V.description??"",frequency_months:V.frequency_months,form_type:V.form_type,external_url:V.external_url??"",subject:V.subject,intro_message:V.intro_message??"",button_label:V.button_label,link_valid_days:V.link_valid_days,is_active:V.is_active,target_organization_ids:V.target_organization_ids??null})):(z(null),M(Yn)),d((Ne=V==null?void 0:V.target_organization_ids)!=null&&Ne.length?"selected":"all"),I(null),b(!0)},H=()=>{var V;return{subject:p.subject,intro_message:p.intro_message,button_label:p.button_label,form_type:p.form_type,external_url:p.form_type==="external"&&((V=p.external_url)==null?void 0:V.trim())||null,link_valid_days:p.link_valid_days}},$=async()=>{var V;try{const Ne=await ne(H()).unwrap();I(Ne.data.html)}catch(Ne){v.error(((V=Ne==null?void 0:Ne.data)==null?void 0:V.message)||"Could not build the preview")}},de=async()=>{var V;if(!B.trim()){v.error("Enter an address to send the test to.");return}try{const Ne=await qe({...H(),email:B.trim()}).unwrap();v.success(Ne.message||"Test email sent")}catch(Ne){v.error(((V=Ne==null?void 0:Ne.data)==null?void 0:V.message)||"Failed to send the test email")}},xe=async V=>{var os,ka,Sa,Aa;if(V.preventDefault(),p.form_type==="external"&&!((os=p.external_url)!=null&&os.trim())){v.error("An external form needs a URL.");return}if(S==="selected"&&!((ka=p.target_organization_ids)!=null&&ka.length)){v.error("Choose at least one organization, or send to all.");return}const Ne={...p,external_url:p.form_type==="external"?(Sa=p.external_url)==null?void 0:Sa.trim():null,target_organization_ids:S==="selected"?p.target_organization_ids:null};try{P?(await ge({id:P.id,body:Ne}).unwrap(),v.success("Campaign updated successfully")):(await ue(Ne).unwrap(),v.success("Campaign created successfully")),b(!1),z(null)}catch(xa){v.error(((Aa=xa==null?void 0:xa.data)==null?void 0:Aa.message)||"Failed to save campaign")}},Me=async()=>{var V;if(A)try{await me(A).unwrap(),v.success("Campaign deleted successfully"),O(null)}catch(Ne){v.error(((V=Ne==null?void 0:Ne.data)==null?void 0:V.message)||"Failed to delete campaign")}},be=async V=>{var Ne;j(V.id);try{const os=await Z({id:V.id}).unwrap();v.success(os.message||"Feedback requests queued")}catch(os){v.error(((Ne=os==null?void 0:os.data)==null?void 0:Ne.message)||"Failed to send feedback requests")}finally{j(null)}},We=(V,Ne)=>M(os=>({...os,[V]:Ne}));return e.jsxs(ye,{title:"",subtitle:"",children:[e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Customer Feedback"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"What customers told us, and how often we ask them."})]})}
4),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[e.jsxs(W,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:((Ls=U==null?void 0:U.data)==null?void 0:Ls.total)??0})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Average rating"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-amber-600",children:(Bs=U==null?void 0:U.data)!=null&&Bs.average_rating?U.data.average_rating.toFixed(1):"â"})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"New"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:((ua=U==null?void 0:U.data)==null?void 0:ua.new)??0})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Actioned"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:((Us=U==null?void 0:U.data)==null?void 0:Us.actioned)??0})})]}),e.jsxs(W,{className:(((vs=U==null?void 0:U.data)==null?void 0:vs.detractors)??0)>0?"border-red-300":"",children:[e.jsx(se,{className:"pb-3",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Needs attention"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:((Ca=U==null?void 0:U.data)==null?void 0:Ca.detractors)??0})})]})]}),e.jsxs(Qs,{defaultValue:"responses",className:"w-full",children:[e.jsxs(Ks,{children:[e.jsx(Ye,{value:"responses",children:"Feedback"}),e.jsxs(Ye,{value:"campaigns",children:[e.jsx(Uc,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsxs(Je,{value:"responses",className:"space-y-4",children:[e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 md:items-center",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search by organization, person, or what they said...",value:t,onChange:V=>{n(V.target.value),s(1)},className:"pl-10"})]}),e.jsxs(ke,{value:i,onValueChange:V=>{c(V===" "?"":V),s(1)},children:[e.jsxs(Se,{className:"w-full md:w-[200px]",children:[e.jsx(fa,{className:"h-4 w-4 mr-2"}),e.jsx(Ae,{placeholder:"Filter by status"})]}),e.jsxs(Pe,{children:[e.jsx(X,{value:" ",children:"All Statuses"}),e.jsx(X,{value:"new",children:"New"}),e.jsx(X,{value:"reviewed",children:"Reviewed"}),e.jsx(X,{value:"actioned",children:"Actioned"}),e.jsx(X,{value:"archived",children:"Archived"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"detractors_only",checked:r,onCheckedChange:V=>{o(V),s(1)}}),e.jsx(x,{htmlFor:"detractors_only",className:"whitespace-nowrap",children:"Only 1â2 stars"})]})]})})}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:K?e.jsx("div",{className:"text-center py-10",children:"Loading..."}):q?e.jsx("div",{className:"text-center py-10 text-red-500",children:"Error loading feedback"}):Te.length===0?e.jsx("div",{className:"text-center py-10 text-muted-foreground",children:"No feedback yet. Once a campaign runs, replies appear here."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Rating"}),e.jsx(T,{children:"What to improve"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Received"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:Te.map(V=>{var Ne;return e.jsxs(le,{children:[e.jsxs(C,{className:"font-medium",children:[V.organization_name||((Ne=V.organization)==null?void 0:Ne.name)||"â",e.jsx("div",{className:"text-xs text-muted-foreground",children:V.respondent_name||V.respondent_email||""})]}),e.jsx(C,{children:e.jsx(Jn,{rating:V.rating})}),e.jsx(C,{className:"max-w-xs truncate",children:V.what_to_improve||"â"}),e.jsx(C,{children:e.jsx(ee,{className:Eu[V.status]||"",children:Du[V.status]||V.status})}),e.jsx(C,{children:V.submitted_at?new Date(V.submitted_at).toLocaleDateString():new Date(V.created_at).toLocaleDateString()}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>_(V),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>N(V.id),children:e.jsx(Le,{className:"h-4 w-4 text-red-500"})})]})})]},V.id)})})]})}),we&&we.last_page>1&&e.jsx("div",{className:"mt-4",children:e.jsx(ot,{children:e.jsxs(dt,{children:[e.jsx(Ns,{children:e.jsx(mt,{onClick:()=>s(V=>Math.max(1,V-1)),className:a===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:we.last_page},(V,Ne)=>Ne+1).map(V=>e.jsx(Ns,{children:e.jsx(ut,{onClick:()=>s(V),isActive:a===V,className:"cursor-pointer",children:V})},V)),e.jsx(Ns,{children:e.jsx(xt,{onClick:()=>s(V=>Math.min(we.last_page,V+1)),className:a===we.last_page?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})})})]}),e.jsxs(Je,{value:"campaigns",className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Feedback schedule"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Each campaign emails the owner of every active organization - or only the organizations you choose - on its own cadence. The cadence counts from when that organization was last asked, so a customer onboarded this week is asked a full cycle from this week."})]}),e.jsxs(u,{onClick:()=>R(),className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"New campaign"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:te?e.jsx("div",{className:"text-center py-10",children:"Loading..."}):Ze.length===0?e.jsx("div",{className:"text-center py-10 text-muted-foreground",children:"No campaigns yet. Create one to start asking customers for feedback."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Frequency"}),e.jsx(T,{children:"Recipients"}),e.jsx(T,{children:"Form"}),e.jsx(T,{children:"Sent"}),e.jsx(T,{children:"Replies"}),e.jsx(T,{children:"Last run"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:Ze.map(V=>{var Ne;return e.jsxs(le,{children:[e.jsxs(C,{className:"font-medium",children:[V.name,V.description&&e.jsx("div",{className:"text-xs text-muted-foreground max-w-xs truncate",children:V.description})]}),e.jsx(C,{children:V.frequency_months===1?"Every month":V.frequency_months===12?"Once a year":`Every ${V.frequency_months} months`}),e.jsx(C,{children:(Ne=V.target_organization_ids)!=null&&Ne.length?`${V.target_organization_ids.length} selected`:"All organizations"}),e.jsx(C,{children:V.form_type==="external"?e.jsxs(ee,{variant:"outline",className:"gap-1",children:[e.jsx(Gc,{
4className:"h-3 w-3"}),"External"]}):e.jsx(ee,{variant:"outline",children:"Built-in"})}),e.jsx(C,{children:V.requests_count??0}),e.jsx(C,{children:V.responses_count??0}),e.jsx(C,{className:"text-sm text-muted-foreground",children:V.last_run_at?new Date(V.last_run_at).toLocaleDateString():"Never"}),e.jsx(C,{children:V.is_active?e.jsx(ee,{className:"bg-green-500",children:"Active"}):e.jsx(ee,{variant:"secondary",children:"Paused"})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",title:"Send to everyone who is due now",disabled:!V.is_active||k===V.id,onClick:()=>be(V),children:k===V.id?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(nt,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>R(V),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>O(V.id),children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},V.id)})})]})})})})]})]})]}),e.jsx(Fe,{open:!!l,onOpenChange:()=>_(null),children:e.jsxs(ze,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Customer feedback"}),e.jsx(Ge,{children:(l==null?void 0:l.submitted_at)&&`Received ${new Date(l.submitted_at).toLocaleString()}`})]}),l&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Organization"}),e.jsx("p",{className:"text-sm font-medium mt-1",children:l.organization_name||(($a=l.organization)==null?void 0:$a.name)||"â"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"From"}),e.jsxs("p",{className:"text-sm font-medium mt-1",children:[l.respondent_name||"â",e.jsx("span",{className:"block text-xs text-muted-foreground",children:l.respondent_email})]})]})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Rating"}),e.jsx("div",{className:"mt-1",children:e.jsx(Jn,{rating:l.rating})})]}),l.recommend_score!==null&&e.jsxs("div",{children:[e.jsx(x,{children:"Would recommend"}),e.jsxs("p",{className:"text-sm font-medium mt-1",children:[l.recommend_score," / 10"]})]})]}),e.jsxs("div",{children:[e.jsx(x,{children:"What went well"}),e.jsx(Ce,{value:l.what_went_well||"â",readOnly:!0,rows:4,className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Where we should improve"}),e.jsx(Ce,{value:l.what_to_improve||"â",readOnly:!0,rows:4,className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Status"}),e.jsxs(ke,{value:l.status,onValueChange:f,disabled:w,children:[e.jsx(Se,{className:"mt-1",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"new",children:"New"}),e.jsx(X,{value:"reviewed",children:"Reviewed"}),e.jsx(X,{value:"actioned",children:"Actioned"}),e.jsx(X,{value:"archived",children:"Archived"})]})]})]}),e.jsxs("div",{children:[e.jsx(x,{htmlFor:"admin_notes",children:"Internal notes"}),e.jsx(Ce,{id:"admin_notes",value:l.admin_notes||"",rows:3,className:"mt-1",onChange:V=>_({...l,admin_notes:V.target.value})})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>_(null),children:"Close"}),e.jsxs(u,{disabled:w,onClick:()=>l&&f(l.status),children:[w&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Save notes"]})]})]})}),e.jsx(Fe,{open:g,onOpenChange:b,children:e.jsxs(ze,{className:"max-h-[90vh] max-w-2xl overflow-y-auto lg:max-w-4xl xl:max-w-5xl",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:P?"Edit campaign":"New campaign"}),e.jsx(Ge,{children:"Choose how often customers are asked and what the email says."})]}),e.jsxs("form",{onSubmit:xe,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"campaign_name",children:"Campaign name *"}),e.jsx(E,{id:"campaign_name",value:p.name,onChange:V=>We("name",V.target.value),placeholder:"e.g. Quarterly check-in",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"frequency",children:"How often *"}),e.jsxs(ke,{value:String(p.frequency_months),onValueChange:V=>We("frequency_months",parseInt(V)),children:[e.jsx(Se,{id:"frequency",children:e.jsx(Ae,{})}),e.jsx(Pe,{children:Lu.map(V=>e.jsx(X,{value:String(V.months),children:V.label},V.months))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Counted per organization, from the last time that customer was asked."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"link_valid_days",children:"Link valid for (days)"}),e.jsx(E,{id:"link_valid_days",type:"number",min:1,max:365,value:p.link_valid_days??30,onChange:V=>We("link_valid_days",parseInt(V.target.value)||30)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The link stops working after this, so an old email is not a permanently open form."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Who receives it"}),e.jsx(er,{owners:((Hs=Qe==null?void 0:Qe.data)==null?void 0:Hs.recipients)??[],isLoading:oe,mode:S,onModeChange:d,selectedIds:p.target_organization_ids??[],onSelectedIdsChange:V=>We("target_organization_ids",V)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each organization's owner gets their own email. The cadence above still applies to each organization."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"form_type",children:"Where the link goes"}),e.jsxs(ke,{value:p.form_type,onValueChange:V=>We("form_type",V),children:[e.jsx(Se,{id:"form_type",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"builtin",children:"Built-in form â rating, what went well, what to improve"}),e.jsx(X,{value:"external",children:"Custom link â your own survey, booking page, or anything else"})]})]})]}),p.form_type==="external"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"external_url",children:"Link URL *"}),e.jsx(E,{id:"external_url",type:"url",value:p.external_url??"",onChange:V=>We("external_url",V.target.value),placeholder:"https://survey.example.com/...",required:!0}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["A ",e.jsx("code",{children:"ref"})," parameter carrying the request token is appended automatically, so replies can still be tied back to the organization. Responses collected this way live in your survey tool, not on this page."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"subject",children:"Email subject"}),e.jsx(E,{id:"subject",value:p.subject??"",onChange:V=>We("subject",V.target.value),placeholder:"How are we doing?"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"intro_message",children:"Email message"}),e.jsx(Ce,{id:"intro_message",rows:4,value:p.intro_message??"",onChange:V=>We("intro_message",V.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"button_label",children:"Button label"}),e.jsx(E,{id:"button_label",value:p.button_label??"",onChange:V=>We("button_label",V.target.value),placeholder:"Share your feedback"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Internal description"}),e.jsx(E,{id:"description",value:p.description??"",onChange:V=>We("description",V.target.value),placeholder:"Not shown to customers"})]})]}),e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Preview & test"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"See the email as customers will, or send it to yourself first. Uses the form as it is now - no need to save."})]}),e.jsxs(u,{type:"button",variant:"outline",size:"sm",onClick:$,disabled:_e,children:[_e?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Fs,{className:"mr-2 h-4 w-4"}),"Preview email"]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(E,{type:"email",value:B,onChange:V=>y(V.target.value),onKeyDown:V=>{V.key==="Enter"&&(V.preventDefault(),de())},placeholder:"[email protected]"}),e.jsxs(u,{type:"button",variant:"outline",onClick:de,disabled:fe,className:"shrink-0",children:[fe?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(nt,{className:"mr-2 h-4 w-4"}),"Send test"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The button in a test email is a sample and does not open a real form."}),L&&e.jsx("iframe",{title:"Feedback email preview",srcDoc:L,sandbox:"",className:"h-[480px] w-full rounded-md border bg-white"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{id:"is_active",checked:p.is_active??!0,onCheckedChange:V=>We("is_active",V)}),e.jsx(x,{htmlFor:"is_active",children:"Active"})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>b(!1),children:"Cancel"}),e.jsxs(u,{type:"submit",disabled:J||he,children:[(J||he)&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),P?"Update":"Create"]})]})]})]})}),e.jsx(ss,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete feedback"}),e.jsx(is,{children:"This permanently removes what the customer told you. This cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:ie,className:"bg-red-500 hover:bg-red-600",children:"Delete"})]})]})}),e.jsx(ss,{open:!!A,onOpenChange:()=>O(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete campaign"}),e.jsx(is,{children:"No further requests will be sent. Feedback already collected is kept."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:Me,className:"bg-red-500 hover:bg-red-600",children:"Delete"})]})]})})]})}const qu=He.injectEndpoints({endpoints:a=>({getLeadSubmissions:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.status&&n.push(`status=${encodeURIComponent(s.status)}`),s!=null&&s.search&&n.push(`search=${encodeURIComponent(s.search)}`),{url:`/admin/lead-submissions?${n.join("&")}`,method:"GET"}},providesTags:["lead-submissions"]}),getLeadSubmissionStats:a.query({query:()=>({url:"/admin/lead-submissions/stats",method:"GET"}),providesTags:["lead-submissions"]}),updateLeadSubmissionStatus:a.mutation({query:({id:s,body:t})=>({url:`/admin/lead-submissions/${s}/status`,method:"PUT",body:t}),invalidatesTags:["lead-submissions"]}),deleteLeadSubmission:a.mutation({query:s=>({url:`/admin/lead-submissions/${s}`,method:"DELETE"}),invalidatesTags:["lead-submissions"]})}),overrideExisting:!0}),{useGetLeadSubmissionsQuery:Ou,useGetLeadSubmissionStatsQuery:Ru,useUpdateLeadSubmissionStatusMutation:Iu,useDeleteLeadSubmissionMutation:$u}=qu,Bu={pending:"bg-yellow-100 text-yellow-800",contacted:"bg-blue-100 text-blue-800",resolved:"bg-green-100 text-green-800",spam:"bg-gray-100 text-gray-800"};function Uu(){const[a]=m.useState(1),[s,t]=m.useState(""),[n,i]=m.useState(""),[c,r]=m.useState(null),[o,l]=m.useState(null),{data:_,isLoading:h}=Ou({page:a,search:s,status:n||void 0}),{data:N}=Ru(),[g]=$u(),[b,{isLoading:P}]=Iu(),z=Array.isArray(_==null?void 0:_.data)?_.data:[],p=async()=>
4{if(o)try{await g(o).unwrap(),v.success("Lead deleted."),l(null)}catch{v.error("Failed to delete lead.")}},M=async A=>{if(c)try{await b({id:c.id,body:{status:A}}).unwrap(),v.success("Status updated."),r(null)}catch{v.error("Failed to update status.")}};return e.jsx(ye,{title:"Lead Submissions",subtitle:"Review marketing lead forms from the website",children:e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:["total","pending","contacted","resolved","spam"].map(A=>e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm capitalize text-muted-foreground",children:A})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:(N==null?void 0:N[A])??0})})]},A))}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(E,{placeholder:"Search...",value:s,onChange:A=>t(A.target.value),className:"max-w-sm"}),e.jsxs(ke,{value:n||"all",onValueChange:A=>i(A==="all"?"":A),children:[e.jsx(Se,{className:"w-40",children:e.jsx(Ae,{placeholder:"Status"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All"}),e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"resolved",children:"Resolved"}),e.jsx(X,{value:"spam",children:"Spam"})]})]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:h?e.jsx("p",{children:"Loading..."}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Email"}),e.jsx(T,{children:"Source"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Submitted"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:z.map(A=>e.jsxs(le,{children:[e.jsx(C,{children:A.name}),e.jsx(C,{children:A.email}),e.jsx(C,{className:"max-w-[180px] truncate",children:A.source_page}),e.jsx(C,{children:e.jsx(ee,{className:Bu[A.status],children:A.status})}),e.jsx(C,{children:new Date(A.created_at).toLocaleDateString()}),e.jsxs(C,{className:"space-x-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:()=>r(A),children:e.jsx(Fs,{className:"w-4 h-4"})}),e.jsx(u,{size:"sm",variant:"destructive",onClick:()=>l(A.id),children:e.jsx(Le,{className:"w-4 h-4"})})]})]},A.id))})]})})}),e.jsx(Fe,{open:!!c,onOpenChange:()=>r(null),children:e.jsxs(ze,{children:[e.jsx(Ee,{children:e.jsx(De,{children:"Lead Details"})}),c&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Reference"}),e.jsx("p",{children:c.reference_number})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Name"}),e.jsx("p",{children:c.name})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Email"}),e.jsx("p",{children:c.email})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Phone"}),e.jsx("p",{children:c.phone||"-"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Company"}),e.jsx("p",{children:c.company||"-"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Source page"}),e.jsx("p",{children:c.source_page})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Message"}),e.jsx("p",{children:c.message||"-"})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Status"}),e.jsxs(ke,{defaultValue:c.status,onValueChange:M,disabled:P,children:[e.jsx(Se,{children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"pending",children:"Pending"}),e.jsx(X,{value:"contacted",children:"Contacted"}),e.jsx(X,{value:"resolved",children:"Resolved"}),e.jsx(X,{value:"spam",children:"Spam"})]})]})]}),c.admin_notes&&e.jsxs("div",{children:[e.jsx(x,{children:"Admin notes"}),e.jsx(Ce,{readOnly:!0,value:c.admin_notes})]})]}),e.jsx(Re,{children:e.jsx(u,{variant:"outline",onClick:()=>r(null),children:"Close"})})]})}),e.jsx(ss,{open:!!o,onOpenChange:()=>l(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete lead submission?"}),e.jsx(is,{children:"This action cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:p,children:"Delete"})]})]})})]})})}function Gu(){var B;const a=Vs(),[s,t]=m.useState(1),[n,i]=m.useState(""),[c,r]=m.useState(null),{data:o,isLoading:l,error:_}=ln({page:s,per_page:15,search:n}),h=o?Array.isArray(o.data)?o.data:o.data&&Array.isArray(o.data.data)?o.data.data:[]:[],N=(()=>
4{if(o){if(o.meta)return o.meta;if(o.data&&typeof o.data=="object"&&!Array.isArray(o.data))return o.data}})(),[g,b]=m.useState(!1),[P,z]=m.useState(null),[p,M]=m.useState({first_name:"",last_name:"",email:"",username:"",phone:"",role_id:"",status:!0}),{data:A}=Mi(),[O,{isLoading:k}]=Zo(),[j,{isLoading:S}]=ed(),d=y=>{z(y),M({first_name:y.first_name||"",last_name:y.last_name||"",email:y.email||"",username:y.username||"",phone:y.phone||"",role_id:y.roles&&y.roles.length>0?String(y.roles[0].id):"",status:!!y.status}),b(!0)},L=async()=>{var y;if(P)try{await O({id:P.id,data:{first_name:p.first_name,last_name:p.last_name,email:p.email,username:p.username||void 0,phone:p.phone||void 0,role_id:p.role_id||void 0,status:p.status}}).unwrap(),v.success("Admin user updated successfully"),b(!1),z(null)}catch(F){v.error(((y=F==null?void 0:F.data)==null?void 0:y.message)||"Failed to update admin user")}},I=async()=>{var y;if(c)try{await j(c).unwrap(),v.success("Admin user deleted successfully"),r(null)}catch(F){v.error(((y=F==null?void 0:F.data)==null?void 0:y.message)||"Failed to delete admin user")}};return e.jsxs(ye,{title:"Admin Users",subtitle:"Manage system administrator accounts",children:[e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Admin Users"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage system administrator accounts"})]}),e.jsxs(u,{onClick:()=>a("/admin-dashboard/users/add"),children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add Admin User"]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search by name, email, or username...",value:n,onChange:y=>i(y.target.value),className:"pl-10"})]})})}),e.jsx(Q,{children:l?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):_?e.jsx("div",{className:"text-center py-8 text-destructive",children:"Error loading admin users"}):h.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No admin users found"}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Email"}),e.jsx(T,{children:"Username"}),e.jsx(T,{children:"Phone"}),e.jsx(T,{children:"Roles"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:h.map(y=>e.jsxs(le,{children:[e.jsxs(C,{className:"font-medium",children:[y.first_name," ",y.last_name]}),e.jsx(C,{children:y.email}),e.jsx(C,{children:y.username}),e.jsx(C,{children:y.phone||"N/A"}),e.jsx(C,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:y.roles.map(F=>e.jsx(ee,{variant:"secondary",children:F.display_name},F.id))})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>d(y),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>r(y.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})})]},y.id))})]}),N&&N.last_page>1&&e.jsx("div",{className:"mt-4",children:e.jsx(ot,{children:e.jsxs(dt,{children:[e.jsx(Ns,{children:e.jsx(mt,{onClick:()=>t(y=>Math.max(1,y-1)),className:s===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:Math.min(5,(N==null?void 0:N.last_page)||1)},(y,F)=>{let K;const q=(N==null?void 0:N.last_page)||1;return q<=5||s<=3?K=F+1:s>=q-2?K=q-4+F:K=s-2+F,e.jsx(Ns,{children:e.jsx(ut,{onClick:()=>t(K),isActive:s===K,className:"cursor-pointer",children:K})},K)}),e.jsx(Ns,{children:e.jsx(xt,{onClick:()=>t(y=>Math.min((N==null?void 0:N.last_page)||1,y+1)),className:s===(N==null?void 0:N.last_page)||s>=((N==null?void 0:N.last_page)||1)?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]})})]})]}),e.jsx(Fe,{open:g,onOpenChange:b,children:e.jsxs(ze,{className:"max-w-lg",children:[e.jsx(Ee,{children:e.jsx(De,{children:"Edit Admin User"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"edit_first_name",children:"First Name"}),e.jsx(E,{id:"edit_first_name",value:p.first_name,onChange:y=>M({...p,first_name:y.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"edit_last_name",children:"Last Name"}),e.jsx(E,{id:"edit_last_name",value:p.last_name,onChange:y=>M({...p,last_name:y.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"edit_email",children:"Email"}),e.jsx(E,{id:"edit_email",type:"email",value:p.email,onChange:y=>M({...p,email:y.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"edit_username",children:"Username"}),e.jsx(E,{id:"edit_username",value:p.username||"",onChange:y=>M({...p,username:y.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"edit_phone",children:"Phone"}),e.jsx(E,{id:"edit_phone",value:p.phone||"",onChange:y=>M({...p,phone:y.target.value})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 items-center",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Active"}),e.jsx(Ve,{checked:!!p.status,onCheckedChange:y=>M({...p,status:!!y})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Role"}),e.jsxs(ke,{value:p.role_id,onValueChange:y=>M({...p,role_id:y}),children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select role"})}),e.jsx(Pe,{children:(B=A==null?void 0:A.data)==null?void 0:B.map(y=>e.jsx(X,{value:String(y.id),children:y.display_name},y.id))})]})]})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),e.jsx(u,{onClick:L,disabled:k,children:k?"Updating...":"Update User"})]})]})}),e.jsx(ss,{open:!!c,onOpenChange:()=>r(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Are you sure?"}),e.jsx(is,{children:"This action cannot be undone. This will permanently delete the admin user account."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:I,disabled:S,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:S?"Deleting...":"Delete"})]})]})})]})}const Vu=lt({first_name:Ke().min(2,"First name must be at least 2 characters"),last_name:Ke().min(2,"Last name must be at least 2 characters"),email:Ke().email("Invalid email address"),username:Ke().min(3,"Username must be at least 3 characters"),phone:Ke().optional(),role_id:Ke().min(1,"Role is required"),password:Ke().min(8,"Password must be at least 8 characters"),password_confirmation:Ke()}).refine(a=>a.password===a.password_confirmation,{message:"Passwords don't match",path:["password_confirmation"]});function Qu(){const a=Vs(),[s,{isLoading:t}]=Xo(),{data:n,isLoading:i}=Mi();console.log("----------- Test ----------",n);const{register:c,handleSubmit:r,formState:{errors:o},setValue:l,watch:_}=Xa({resolver:Za(Vu)}),h=_("role_id"),N=async g=>{var P,z;const b={...g,role_id:Number(g.role_id)};try{await s(b).unwrap(),v.success("Admin user created successfully"),a("/admin-dashboard/users")}catch(p){const M=((P=p==null?void 0:p.data)==null?void 0:P.message)||"Failed to create admin user";
4v.error(M),(z=p==null?void 0:p.data)!=null&&z.errors&&Object.entries(p.data.errors).forEach(([A,O])=>{Array.isArray(O)&&O.forEach(k=>v.error(`${A}: ${k}`))})}};return e.jsx(ye,{title:"Add Admin User",subtitle:"",children:e.jsx("div",{className:"container mx-auto p-4",children:e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Create New Admin User"}),e.jsx(je,{children:"Add a new administrator to the system with specific role permissions."})]}),e.jsx(Q,{children:e.jsxs("form",{onSubmit:r(N),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"first_name",children:["First Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"first_name",...c("first_name"),placeholder:"John"}),o.first_name&&e.jsx("p",{className:"text-sm text-red-500",children:o.first_name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"last_name",children:["Last Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"last_name",...c("last_name"),placeholder:"Doe"}),o.last_name&&e.jsx("p",{className:"text-sm text-red-500",children:o.last_name.message})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"email",children:["Email ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"email",type:"email",...c("email"),placeholder:"[email protected]"}),o.email&&e.jsx("p",{className:"text-sm text-red-500",children:o.email.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"username",children:["Username ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"username",...c("username"),placeholder:"johndoe"}),o.username&&e.jsx("p",{className:"text-sm text-red-500",children:o.username.message})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"phone",children:"Phone (Optional)"}),e.jsx(E,{id:"phone",...c("phone"),placeholder:"+1234567890"}),o.phone&&e.jsx("p",{className:"text-sm text-red-500",children:o.phone.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"role_id",children:["Role ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(ke,{onValueChange:g=>l("role_id",g),value:h,children:[e.jsx(Se,{children:e.jsx(Ae,{placeholder:"Select a role"})}),e.jsx(Pe,{children:i?e.jsx(X,{value:"loading",disabled:!0,children:"Loading roles..."}):n!=null&&n.data&&n.data.length>0?n.data.map(g=>e.jsx(X,{value:String(g.id),children:g.display_name},g.id)):e.jsx(X,{value:"none",disabled:!0,children:"No roles available"})})]}),o.role_id&&e.jsx("p",{className:"text-sm text-red-500",children:o.role_id.message})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"password",children:["Password ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"password",type:"password",...c("password"),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢"}),o.password&&e.jsx("p",{className:"text-sm text-red-500",children:o.password.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"password_confirmation",children:["Confirm Password ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(E,{id:"password_confirmation",type:"password",...c("password_confirmation"),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢"}),o.password_confirmation&&e.jsx("p",{className:"text-sm text-red-500",children:o.password_confirmation.message})]})]}),e.jsxs("div",{className:"flex gap-4 justify-end",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>a("/admin-dashboard/users"),disabled:t,children:"Cancel"}),e.jsx(u,{type:"submit",disabled:t,children:t?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Admin User"})]})]})})]})})})}const Ku=He.injectEndpoints({endpoints:a=>({getAdminRoles:a.query({query:()=>({url:"/admin/admin-roles"}),providesTags:["AdminRoles"]}),getAdminRole:a.query({query:({id:s})=>({url:`/admin/admin-roles/${s}`}),providesTags:(s,t,{id:n})=>[{type:"AdminRoles",id:n}]}),createAdminRole:a.mutation({query:s=>({url:"/admin/admin-roles",method:"POST",data:s}),invalidatesTags:["AdminRoles"]}),updateAdminRole:a.mutation({query:({id:s,data:t})=>({url:`/admin/admin-roles/${s}`,method:"PUT",data:t}),invalidatesTags:(s,t,{id:n})=>[{type:"AdminRoles",id:n},"AdminRoles"]}),deleteAdminRole:a.mutation({query:s=>({url:`/admin/admin-roles/${s}`,method:"DELETE"}),invalidatesTags:["AdminRoles"]}),getAdminMenuItems:a.query({query:()=>({url:"/admin/admin-menu-items"}),providesTags:["AdminMenuItems"]}),assignRolesToUser:a.mutation({query:s=>({url:"/admin/admin-roles/assign-to-user",method:"POST",data:{user_id:s.user_id,role_ids:s.role_ids}}),invalidatesTags:["AdminUsers","AdminRoles"]}),getUserAdminRoles:a.query({query:s=>({url:`/admin/users/${s}/admin-roles`}),providesTags:(s,t,n)=>[{type:"AdminUsers",id:n}]})})}),{useGetAdminRolesQuery:Hu,useCreateAdminRoleMutation:Wu,useUpdateAdminRoleMutation:Yu,useDeleteAdminRoleMutation:Ju,useGetAdminMenuItemsQuery:Xu,useAssignRolesToUserMutation:Zu}=Ku;function sr(a){return(a.permissions||[]).map(s=>s.key)}function ar(a){return a.children.flatMap(sr)}function tr(a,s){if(a.length===0)return"none";const t=a.filter(n=>s.has(n)).length;return t===a.length?"all":t>0?"some":"none"}function ex({feature:a,selected:s,onTogglePermission:t,onToggleAll:n}){const i=sr(a),c=tr(i,s);return e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 py-1.5 pl-2 border-l-2 border-muted ml-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 cursor-pointer select-none min-w-[180px]",onClick:()=>n(i,c!=="all"),children:[e.jsx(bs,{checked:c==="all"?!0:c==="some"?"indeterminate":!1,onCheckedChange:r=>n(i,r===!0),onClick:r=>r.stopPropagation()}),e.jsx("span",{className:"text-sm font-medium",children:a.label})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:(a.permissions||[]).map(r=>e.jsxs("div",{className:"inline-flex items-center gap-1.5 cursor-pointer select-none",onClick:()=>t(r.key,!s.has(r.key)),children:[e.jsx(bs,{checked:s.has(r.key),onCheckedChange:o=>t(r.key,o===!0),onClick:o=>o.stopPropagation()}),e.jsx("span",{className:"text-xs capitalize",children:r.action})]},r.key))})]})}function sx({module:a,selected:s,expanded:t,onToggleExpand:n,onTogglePermission:i,onToggleAll:c}){const r=ar(a),o=tr(r,s);return e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 bg-muted/50 cursor-pointer hover:bg-muted/80",onClick:n,children:[t?e.jsx(ca,{className:"h-4 w-4 shrink-0"}):e.jsx(wa,{className:"h-4 w-4 shrink-0"}),e.jsx(bs,{checked:o==="all"?!0:o==="some"?"indeterminate":!1,onCheckedChange:l=>{c(r,l===!0)},onClick:l=>l.stopPropagation()}),e.jsx($t,{className:"h-4 w-4 shrink-0 text-primary"}),e.jsx("span",{className:"font-semibold text-sm",children:a.label}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[r.filter(l=>s.has(l)).length,"/",r.length," ","permissions"]})]}),t&&e.jsx("div",{className:"px-3 py-2 space-y-0.5",children:a.children.map(l
4=>e.jsx(ex,{feature:l,selected:s,onTogglePermission:i,onToggleAll:c},l.key))})]})}function ax(){const{data:a,isLoading:s}=Hu(),{data:t,isLoading:n}=Xu(),{data:i,isLoading:c}=ln({page:1,per_page:100}),[r,{isLoading:o}]=Wu(),[l,{isLoading:_}]=Yu(),[h,{isLoading:N}]=Ju(),[g,{isLoading:b}]=Zu(),[P,z]=m.useState("roles"),[p,M]=m.useState(""),[A,O]=m.useState(""),[k,j]=m.useState(!1),[S,d]=m.useState(null),[L,I]=m.useState(null),[B,y]=m.useState(""),[F,K]=m.useState(""),[q,U]=m.useState(new Set),[re,te]=m.useState(new Set),[G,w]=m.useState(!1),[Y,ue]=m.useState(""),[J,ge]=m.useState([]),he=m.useMemo(()=>(a==null?void 0:a.data)||[],[a]),me=m.useMemo(()=>{var $;return(($=t==null?void 0:t.data)==null?void 0:$.modules)||[]},[t]),Z=m.useMemo(()=>(i==null?void 0:i.data)||[],[i]),ne=m.useMemo(()=>{if(!p.trim())return he;const $=p.toLowerCase();return he.filter(de=>{var xe,Me;return((xe=de.name)==null?void 0:xe.toLowerCase().includes($))||((Me=de.display_name)==null?void 0:Me.toLowerCase().includes($))})},[he,p]),_e=m.useMemo(()=>{if(!A.trim())return Z;const $=A.toLowerCase();return Z.filter(de=>{var xe,Me,be;return((xe=de.first_name)==null?void 0:xe.toLowerCase().includes($))||((Me=de.last_name)==null?void 0:Me.toLowerCase().includes($))||((be=de.email)==null?void 0:be.toLowerCase().includes($))})},[Z,A]),qe=m.useCallback($=>{te(de=>{const xe=new Set(de);return xe.has($)?xe.delete($):xe.add($),xe})},[]),fe=m.useCallback(($,de)=>{U(xe=>{const Me=new Set(xe);return de?Me.add($):Me.delete($),Me})},[]),Qe=m.useCallback(($,de)=>{U(xe=>{const Me=new Set(xe);return de?$.forEach(be=>Me.add(be)):$.forEach(be=>Me.delete(be)),Me})},[]),oe=()=>{d(null),y(""),K(""),U(new Set),te(new Set),j(!0)},Te=$=>{d($),y($.display_name||$.name),K($.description||""),U(new Set($.permissions||[]));const de=new Set;for(const xe of me)ar(xe).some(be=>($.permissions||[]).includes(be))&&de.add(xe.key);te(de),j(!0)},we=async()=>{var de;if(!B.trim()){v.error("Role name is required");return}const $=Array.from(q);if($.length===0){v.error("Select at least one permission");return}try{S?(await l({id:S.id,data:{display_name:B,description:F||void 0,permission_keys:$}}).unwrap(),v.success("Role updated successfully")):(await r({display_name:B,description:F||void 0,permission_keys:$}).unwrap(),v.success("Role created successfully")),j(!1)}catch(xe){v.error(((de=xe==null?void 0:xe.data)==null?void 0:de.message)||`Failed to ${S?"update":"create"} role`)}},Ze=async()=>{var $;if(L!==null)try{await h(L).unwrap(),v.success("Role deleted successfully"),I(null)}catch(de){v.error((($=de==null?void 0:de.data)==null?void 0:$.message)||"Failed to delete role")}},f=$=>{var de;ue($.id),ge(((de=$.roles)==null?void 0:de.map(xe=>xe.id))||[]),w(!0)},ie=$=>{ge(de=>de.includes($)?de.filter(xe=>xe!==$):[...de,$])},R=async()=>{var $;if(Y)try{await g({user_id:Y,role_ids:J}).unwrap(),v.success("Roles assigned successfully"),w(!1)}catch(de){v.error((($=de==null?void 0:de.data)==null?void 0:$.message)||"Failed to assign roles")}},H=o||_;return e.jsxs(ye,{title:"Access Control",subtitle:"Admin Roles",children:[e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Admin Roles & Access Control"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage admin roles and assign them to admin users"})]}),e.jsxs(Qs,{value:P,onValueChange:z,children:[e.jsxs(Ks,{children:[e.jsxs(Ye,{value:"roles",children:[e.jsx($t,{className:"h-4 w-4 mr-2"}),"Manage Roles"]}
4),e.jsxs(Ye,{value:"assign",children:[e.jsx(qn,{className:"h-4 w-4 mr-2"}),"Assign to Users"]})]}),e.jsxs(Je,{value:"roles",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search roles...",value:p,onChange:$=>M($.target.value),className:"max-w-sm"})]}),e.jsxs(u,{onClick:oe,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Create Role"]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:s?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):ne.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx($t,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"font-medium",children:"No roles found"}),e.jsx("p",{className:"text-sm",children:"Create your first admin role"})]}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Role Name"}),e.jsx(T,{children:"Permissions"}),e.jsx(T,{children:"Users"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:ne.map($=>{var de;return e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:$.display_name||$.name}),$.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:$.description})]})}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",children:((de=$.permissions)==null?void 0:de.length)||0})}),e.jsx(C,{children:e.jsx(ee,{variant:"secondary",children:$.users_count||0})}),e.jsx(C,{children:e.jsx(ee,{variant:$.is_active?"default":"secondary",children:$.is_active?"Active":"Inactive"})}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>Te($),children:e.jsx(ds,{className:"h-4 w-4"})}),!$.is_default&&e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>I($.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})})]},$.id)})})]})})})]}),e.jsxs(Je,{value:"assign",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search admin users...",value:A,onChange:$=>O($.target.value),className:"max-w-sm"})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:c?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):_e.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(gs,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"font-medium",children:"No admin users found"})]}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Email"}),e.jsx(T,{children:"Current Roles"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Action"})]})}),e.jsx(Ue,{children:_e.map($=>{var de;return e.jsxs(le,{children:[e.jsxs(C,{className:"font-medium",children:[$.first_name," ",$.last_name]}),e.jsx(C,{className:"text-muted-foreground",children:$.email}),e.jsx(C,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:((de=$.roles)==null?void 0:de.length)>0?$.roles.map(xe=>e.jsx(ee,{variant:"secondary",className:"text-xs",children:xe.display_name||xe.name},xe.id)):e.jsx(ee,{variant:"outline",className:"text-muted-foreground",children:"No roles"})})}),e.jsx(C,{children:e.jsx(ee,{variant:$.status?"default":"secondary",children:$.status?"Active":"Inactive"})}),e.jsx(C,{className:"text-right",children:e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>
4f($),children:[e.jsx(qn,{className:"h-3.5 w-3.5 mr-1"}),"Manage Roles"]})})]},$.id)})})]})})})]})]})]}),e.jsx(Fe,{open:k,onOpenChange:j,children:e.jsxs(ze,{className:"max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:S?"Edit Admin Role":"Create Admin Role"}),e.jsx(Ge,{children:S?"Update the role name and permissions.":"Define a new admin role with specific permissions."})]}),e.jsxs("div",{className:"grid gap-4 py-2 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"adminRoleName",children:"Role Name *"}),e.jsx(E,{id:"adminRoleName",placeholder:"e.g. Support Manager",value:B,onChange:$=>y($.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"adminRoleDesc",children:"Description"}),e.jsx(E,{id:"adminRoleDesc",placeholder:"Optional description",value:F,onChange:$=>K($.target.value)})]})]}),e.jsx(ra,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Permissions"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[q.size," permission",q.size!==1?"s":""," selected"]})]}),n?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx(nn,{className:"h-[400px] border rounded-lg p-2",children:e.jsx("div",{className:"space-y-2",children:me.map($=>e.jsx(sx,{module:$,selected:q,expanded:re.has($.key),onToggleExpand:()=>qe($.key),onTogglePermission:fe,onToggleAll:Qe},$.key))})})]})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>j(!1),disabled:H,children:"Cancel"}),e.jsxs(u,{onClick:we,disabled:H,children:[H&&e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),S?"Update Role":"Create Role"]})]})]})}),e.jsx(Fe,{open:G,onOpenChange:w,children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Manage User Roles"}),e.jsx(Ge,{children:"Select roles to assign to this admin user. Changes take effect immediately."})]}),e.jsxs("div",{className:"py-4 space-y-3",children:[he.map($=>{var de;return e.jsxs("label",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsx(bs,{checked:J.includes($.id),onCheckedChange:()=>ie($.id)}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:$.display_name||$.name}),$.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:$.description})]}),e.jsxs(ee,{variant:"outline",className:"text-xs",children:[((de=$.permissions)==null?void 0:de.length)||0," perms"]})]},$.id)}),he.length===0&&e.jsx("p",{className:"text-center text-muted-foreground text-sm py-4",children:"No roles available. Create a role first."})]}),e.jsxs(Re,{children:[e.jsx(u,{variant:"outline",onClick:()=>w(!1),disabled:b,children:"Cancel"}),e.jsxs(u,{onClick:R,disabled:b,children:[b&&e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Roles"]})]})]})}),e.jsx(ss,{open:L!==null,onOpenChange:()=>I(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete Admin Role"}),e.jsx(is,{children:"Are you sure you want to delete this role? Users assigned to this role will lose associated permissions. This action cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:Ze,disabled:N,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:N?"Deleting...":"Delete"})]})]})})]})}const tx=lt({first_name:Ke().min(1,"First name is required").max(255,"First name cannot exceed 255 characters"),last_name:Ke().min(1,"Last name is required").max(255,"Last name cannot exceed 255 characters"),phone:Ke().max(15,"Phone number cannot exceed 15 characters").optional().or(et("")),email:Ke().email("Invalid email address").optional().or(et(""))}),nx=lt({current_password:Ke().min(1,"Current password is required"),password:Ke().min(8,"Password must be at least 8 characters").regex(/[A-Z]/,"Password must contain at least one uppercase letter").regex(/[a-z]/,"Password must contain at least one lowercase letter").regex(/[0-9]/,"Password must contain at least one number").regex(/[^A-Za-z0-9]/,"Password must contain at least one symbol"),password_confirmation:Ke().min(1,"Password confirmation is required")}).refine(a=>a.password===a.password_confirmation,{message:"Passwords don't match",path:["password_confirmation"]});function ix(){var y,F;const[a,s]=m.useState("profile"),{data:t,refetch:n}=zr(),{data:i,isLoading:c,refetch:r}=Er(),[o,{isLoading:l}]=Dr(),[_,{isLoading:h}]=Lr(),[N,{isLoading:g}]=Mr(),[b,{isLoading:P}]=qr(),z=Xa({resolver:Za(tx),defaultValues:{first_name:"",last_name:"",phone:"",email:""}}),p=Xa({resolver:Za(nx),defaultValues:{current_password:"",password:"",password_confirmation:""}});m.useEffect(()=>{if(i??t){const K=i??t;z.reset({first_name:K.first_name||"",last_name:K.last_name||"",phone:K.phone||"",email:K.email||""})}},[i,z]);const M=async K=>{var q;try{const U={...S??{},...K};await o(U).unwrap(),v.success("Profile updated successfully!");try{await r()}catch{}try{await n()}catch{}}catch(U){v.error(((q=U==null?void 0:U.data)==null?void 0:q.message)||"Failed to update profile")}},A=async K=>{var q;try{await _(K).unwrap(),v.success("Password changed successfully!"),p.reset()}catch(U){v.error(((q=U==null?void 0:U.data)==null?void 0:q.message)||"Failed to change password")}};function O(K,q=30){return K.length>q?K.slice(0,q)+"â¦":K}const k=async K=>{var re,te,G;const q=(re=K.target.files)==null?void 0:re[0];if(K.target.value="",!q)return;if(!/^image\/(jpeg|jpg|png|webp)$/i.test(q.type)){v.error("Please choose a JPG, PNG or WebP image.");return}if(q.size>2*1024*1024){v.error("Image must be 2MB or smaller.");return}const U=new FormData;U.append("profile_picture",q);try{const w=await N(U).unwrap(),Y=((te=w==null?void 0:w.data)==null?void 0:te.image)??(w==null?void 0:w.image)??null,ue=(Y==null?void 0:Y.url)??null;if(ue){const J=fs("user")??{};na("user",{...J,avatar:ue,image:Y})}await r(),v.success("Profile picture updated"),Rn()}catch(w){v.error(((G=w==null?void 0:w.data)==null?void 0:G.message)||"Failed to update profile picture")}},j=async()=>{var K;try{await b().unwrap();const q=fs("user")??{};na("user",{...q,avatar:null,image:null}),await r(),v.success("Profile picture removed"),Rn()}catch(q){v.error(((K=q==null?void 0:q.data)==null?void 0:K.message)||"Failed to remove profile picture")}},S=i??t,d=S?`${S.first_name??""} ${S.last_name??""}`.trim():"",L=(S==null?void 0:S.roles)??[],I=S!=null&&S.status?"Active":"Inactive",B=va((y=S==null?void 0:S.image)==null?void 0:y.url)??null;return c?e.jsx(Vc,{size:36}):e.jsx("div",{className:"w-full p-3 mx-auto",children:e.jsxs(Qs,{value:a,onValueChange:s,className:"w-full mt-2",children:[e.jsxs(Ks,{className:"grid w-full grid-cols-2 ",children:[e.jsxs(Ye,{value:"profile",className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"w-4 h-4"}),"Profile Information"]}),e.jsxs(Ye,{value:"password",className:"flex items-center gap-2",children:[e.jsx(Fa,{className:"w-4 h-4"}),"Change Password"]})]}),e.jsxs(Je,{value:"profile",className:"space-y-6",children:[e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"w-5 h-5"}),"Personal Information"]})}),e.jsxs(Q,{children:[e.jsxs("div",{className:"mb-4 flex items-center gap-4",children:[e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs(Oa,{className:"h-20 w-20",children:[e.jsx(Ra,{src:B||void 0,alt:d||"Profile"}),e.jsx(Ia,{className:"bg-sky-100 text-sky-700 text-2xl font-semibold",children:((F=S==null?void 0:S.first_name)==null?void 0:F[0])??"U"})]}),e.jsxs("label",{htmlFor:"profile_picture_input",title:"Change profile picture",className:"absolute -bottom-1 -right-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full bg-primary text-primary-foreground shadow ring-2 ring-background hover:opacity-90",children:[g?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(Qc,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Change profile picture"})]}),e.jsx("input",{id:"profile_picture_input",type:"file",accept:"image/jpeg,image/jpg,image/png,image/webp",className:"hidden",disabled:g,onChange:k})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-semibold",children:O(d)||"Profile"}),e.jsx("div",{className:"text-muted-foreground text-sm",children:S!=null&&S.username?`@${S.username}`:(S==null?void 0:S.email)??""}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[L.map(K=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md bg-gray-100 text-xs",children:K.name},K.id)),e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-md text-xs ${S!=null&&S.status?"bg-green-100 text-green-700":"bg-red-100 text-red-700"}`,children:I})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"JPG, PNG or WebP. Max 2MB."}),B&&e.jsxs(u,{type:"button",variant:"ghost",size:"sm",className:"h-auto p-0 text-xs text-destructive hover:text-destructive",disabled:P,onClick:j,children:[P?e.jsx(ce,{className:"mr-1 h-3 w-3 animate-spin"}):e.jsx(Le,{className:"mr-1 h-3 w-3"}),"Remove photo"]})]})]})]}),e.jsx(On,{...z,children:e.jsxs("form",{onSubmit:z.handleSubmit(M),className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(Js,{control:z.control,name:"first_name",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"First Name"}),e.jsx(ea,{children:e.jsx(E,{placeholder:"Enter your first name",...K})}),e.jsx(sa,{})]})}),e.jsx(Js,{control:z.control,name:"last_name",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"Last Name"}),e.jsx(ea,{children:e.jsx(E,{placeholder:"Enter your last name",...K})}),e.jsx(sa,{})]})})]}),e.jsx(Js,{control:z.control,name:"phone",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"Phone Number"}),e.jsx(ea,{children:e.jsx(E,{placeholder:"Enter your phone number",...K})}),e.jsx(sa,{})]})}),e.jsx(Js,{control:z.control,name:"email",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"Email"}),e.jsx(ea,{children:e.jsx(E,{placeholder:"Email",...K,disabled:!0})}),e.jsx(sa,{})]})}),e.jsxs("div",{className:"flex items-center gap-4 pt-4",children:[e.jsxs(u,{type:"submit",className:"flex items-center gap-2",children:[e.jsx(ht,{className:"w-4 h-4"}
4),l?"Updating...":"Update Profile"]}),e.jsx(u,{onClick:()=>{S&&z.reset({first_name:S.first_name??"",last_name:S.last_name??"",phone:S.phone??"",email:S.email??""})},children:"Reset"})]})]})})]})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsx(ae,{children:"Account Information"})}),e.jsx(Q,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(x,{className:"text-sm font-medium text-muted-foreground",children:"Username"}),e.jsx("p",{className:"text-sm mt-1 font-mono",children:(i==null?void 0:i.username)||(t==null?void 0:t.username)||"N/A"})]}),e.jsxs("div",{children:[e.jsx(x,{className:"text-sm font-medium text-muted-foreground",children:"Email"}),e.jsx("p",{className:"text-sm mt-1",children:(i==null?void 0:i.email)||"N/A"})]}),e.jsxs("div",{children:[e.jsx(x,{className:"text-sm font-medium text-muted-foreground",children:"Account Status"}),e.jsx("p",{className:"text-sm mt-1 text-green-600",children:"Active"})]})]})})]})]}),e.jsx(Je,{value:"password",className:"space-y-6",children:e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(Fa,{className:"w-5 h-5"}),"Change Password"]})}),e.jsx(Q,{children:e.jsx(On,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit(A),className:"space-y-6",children:[e.jsx(Js,{control:p.control,name:"current_password",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"Current Password"}),e.jsx(ea,{children:e.jsx(E,{type:"password",placeholder:"Enter your current password",...K})}),e.jsx(sa,{})]})}),e.jsx(Js,{control:p.control,name:"password",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"New Password"}),e.jsx(ea,{children:e.jsx(E,{type:"password",placeholder:"Enter your new password",...K})}),e.jsx(sa,{})]})}),e.jsx(Js,{control:p.control,name:"password_confirmation",render:({field:K})=>e.jsxs(Xs,{children:[e.jsx(Zs,{children:"Confirm New Password"}),e.jsx(ea,{children:e.jsx(E,{type:"password",placeholder:"Confirm your new password",...K})}),e.jsx(sa,{})]})}),e.jsx("div",{className:"flex items-center gap-4 pt-4",children:e.jsxs(u,{type:"submit",disabled:h,className:"flex items-center gap-2",children:[e.jsx(Fa,{className:"w-4 h-4"}),h?"Changing...":"Change Password"]})})]})})})]})})]})})}function rx(){return e.jsx(ye,{title:"Profile",subtitle:"Manage your account settings",children:e.jsx(ix,{})})}function lx(){var M;const[a,s]=m.useState(null),[t,n]=m.useState(!1),[i,c]=m.useState(!1),{data:r,isLoading:o,refetch:l}=ld(),[_,{isLoading:h}]=cd(),[N,{isLoading:g}]=od(),b=((M=r==null?void 0:r.data)==null?void 0:M.data)??[],P=async()=>{var A;if(a)try{const O=await _(a.id).unwrap();v.success(O.message||"Organization restored successfully"),n(!1),s(null)}catch(O){v.error(((A=O==null?void 0:O.data)==null?void 0:A.message)||"Failed to restore organization")}},z=async()=>{var A;if(a)try{const O=await N(a.id).unwrap();v.success(O.message||"Organization permanently deleted"),c(!1),s(null)}catch(O){v.error(((A=O==null?void 0:O.data)==null?void 0:A.message)||"Failed to delete organization")}},p=A=>{const O=A.days_until_permanent_deletion??0;return O<=0?e.jsx(ee,{variant:"destructive",children:"Ready for deletion"}):O<=2?e.jsxs(ee,{className:"bg-red-500",children:[O," days remaining"]}):O<=5?e.jsxs(ee,{className:"bg-yellow-500",children:[O," days remaining"]}):e.jsxs(ee,{className:"bg-blue-500",children:[O," days remaining"]})};return e.jsxs(ye,{title:"Pending Deletions",subtitle:"Organizations scheduled for deletion within the 30-day grace period",children:[e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs(u,{variant:"outline",onClick:()=>l(),children:[e.jsx(Es,{className:"h-4 w-4 mr-2"}),"Refresh"]})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Total Pending"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold",children:b.length})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Expiring Within 30 Days"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:b.filter(A=>
4(A.days_until_permanent_deletion??0)<=30).length})})]}),e.jsxs(W,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:"Ready for Deletion"})}),e.jsx(Q,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:b.filter(A=>(A.days_until_permanent_deletion??0)<=0).length})})]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Organizations Pending Deletion"}),e.jsx(je,{children:"Review and manage organizations that have been marked for deletion. You can restore them or force immediate deletion."})]}),e.jsx(Q,{children:o?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((A,O)=>e.jsx(js,{className:"h-16 w-full"},O))}):b.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Xe,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"No Pending Deletions"}),e.jsx("p",{className:"text-sm mt-1",children:"There are no organizations currently scheduled for deletion."})]}):e.jsx("div",{className:"rounded-lg border",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Organization"}),e.jsx(T,{children:"Contact"}),e.jsx(T,{children:"Deletion Reason"}),e.jsx(T,{children:"Marked At"}),e.jsx(T,{children:"Status"}),e.jsx(T,{className:"text-right",children:"Actions"})]})}),e.jsx(Ue,{children:b.map(A=>{var O;return e.jsxs(le,{children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[(O=A.logo)!=null&&O.url?e.jsx("img",{src:A.logo.url,alt:A.name,className:"h-10 w-10 rounded-lg object-cover"}):e.jsx("div",{className:"h-10 w-10 rounded-lg bg-muted flex items-center justify-center",children:e.jsx(Xe,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:A.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",A.id]})]})]})}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-1 text-sm",children:[A.organization_email&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(ms,{className:"h-3 w-3"}),A.organization_email]}),A.contact_number&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Is,{className:"h-3 w-3"}),A.contact_number]})]})}),e.jsx(C,{children:e.jsx("p",{className:"text-sm max-w-xs truncate",title:A.deletion_reason,children:A.deletion_reason||"No reason provided"})}),e.jsx(C,{children:A.marked_for_deletion_at?e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{children:us(new Date(A.marked_for_deletion_at),"MMM d, yyyy")}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(zs,{className:"h-3 w-3"}),Kt(new Date(A.marked_for_deletion_at),{addSuffix:!0})]})]}):"-"}),e.jsx(C,{children:p(A)}),e.jsx(C,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700",onClick:()=>{s(A),n(!0)},children:[e.jsx(bt,{className:"h-4 w-4 mr-1"}),"Restore"]}),e.jsxs(u,{size:"sm",variant:"destructive",onClick:()=>{s(A),c(!0)},children:[e.jsx(Le,{className:"h-4 w-4 mr-1"}),"Delete Now"]})]})})]},A.id)})})]})})})]})]}),e.jsx(ss,{open:t,onOpenChange:n,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsxs(ns,{className:"flex items-center gap-2",children:[e.jsx(bt,{className:"h-5 w-5 text-green-600"}),"Restore Organization"]}),e.jsxs(is,{children:["Are you sure you want to restore ",e.jsx("strong",{children:a==null?void 0:a.name}),"?",e.jsx("br",{}),e.jsx("br",{}),"This will cancel the scheduled deletion and restore full access to the organization. All employees will be able to login again."]})]}),e.jsxs(rs,{children:[e.jsx(ls,{disabled:h,children:"Cancel"}),e.jsx(cs,{onClick:P,className:"bg-green-600 hover:bg-green-700",disabled:h,children:h?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Restoring..."]}):e.jsxs(e.Fragment,{children:[e.jsx(bt,{className:"h-4 w-4 mr-2"}),"Restore Organization"]})})]})]})}),e.jsx(ss,{open:i,onOpenChange:c,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsxs(ns,{className:"flex items-center gap-2 text-red-600",children:[e.jsx(Or,{className:"h-5 w-5"}),"Permanently Delete Organization"]}),e.jsxs(is,{children:[e.jsx("span",{className:"text-red-600 font-medium",children:"This action cannot be undone!"}),e.jsx("br",{}),e.jsx("br",{}),"Are you sure you want to permanently delete ",e.jsx("strong",{children:a==null?void 0:a.name}),"?",e.jsx("br",{}),e.jsx("br",{}),"All data associated with this organization will be permanently removed, including:",e.jsxs("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[e.jsx("li",{children:"All employees and their records"}),e.jsx("li",{children:"Attendance and leave data"}),e.jsx("li",{children:"Documents and files"}),e.jsx("li",{children:"Subscription and billing history"})]})]})]}),e.jsxs(rs,{children:[e.jsx(ls,{disabled:g,children:"Cancel"}),e.jsx(cs,{onClick:z,className:"bg-red-600 hover:bg-red-700",disabled:g,children:g?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Delete Permanently"]})})]})]})})]})}function cx(){return e.jsx(ye,{title:"",subtitle:"",children:e.jsx(Kc,{})})}function Dt({title:a,value:s,description:t,icon:n,colorClass:i,delay:c=0}){return e.jsx(Wa.div,{initial:{opacity:0,y:20}
4,animate:{opacity:1,y:0},transition:{delay:c,duration:.4},children:e.jsxs(W,{className:`border-l-4 ${i} hover:shadow-lg transition-all duration-300`,children:[e.jsxs(se,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ae,{className:"text-sm font-medium text-muted-foreground",children:a}),n]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-3xl font-bold",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t})]})]})})}const ox={published:"bg-green-100 text-green-700",draft:"bg-gray-100 text-gray-700",paused:"bg-amber-100 text-amber-700",closed:"bg-red-100 text-red-700"};function dx({status:a,map:s}){const t=s[a==null?void 0:a.toLowerCase()]??"bg-slate-100 text-slate-700";return e.jsx(ee,{className:`border-0 text-xs font-medium ${t}`,children:a?a.charAt(0).toUpperCase()+a.slice(1):"-"})}function Xn({page:a,lastPage:s,total:t,perPage:n,onPage:i}){const c=(a-1)*n+1,r=Math.min(a*n,t);return e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Showing ",c,"â",r," of ",t]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",disabled:a<=1,onClick:()=>i(a-1),children:[e.jsx(Rr,{className:"w-4 h-4"}),"Prev"]}),e.jsxs("span",{className:"text-xs",children:["Page ",a," / ",s]}),e.jsxs(u,{variant:"outline",size:"sm",disabled:a>=s,onClick:()=>i(a+1),children:["Next",e.jsx(wa,{className:"w-4 h-4"})]})]})]})}function mx(){var q,U;const[a,s]=m.useState(1),[t,n]=m.useState(""),[i,c]=m.useState(""),[r,o]=m.useState(1),[l,_]=m.useState("published"),[h,N]=m.useState(""),[g,b]=m.useState(""),{data:P,isLoading:z,isFetching:p,refetch:M}=zi({page:a,per_page:15,...t&&{term:t}}),{data:A,isLoading:O,isFetching:k,refetch:j}=Oo({page:r,per_page:15,...l!=="all"&&{status:l},...h&&{term:h}}),{data:S}=Ro(),d=S==null?void 0:S.data,L=(d==null?void 0:d.total_applicants)??0,I=(d==null?void 0:d.live_job_postings)??0,B=(d==null?void 0:d.expired_job_postings)??0,y=(d==null?void 0:d.total_job_postings)??0,F=re=>{re.preventDefault(),n(i),s(1)},K=re=>{re.preventDefault(),N(g),o(1)};return e.jsx(ye,{title:"Recruitment Overview",subtitle:"All Applicants & Job Circulars",link:"/admin-dashboard",children:e.jsxs("div",{className:"flex flex-col gap-6 p-4 ",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Dt,{title:"Total Applicants",value:L,description:"Registered applicant users in system",icon:e.jsx(gs,{className:"w-5 h-5 text-blue-500"}),colorClass:"border-l-blue-500",delay:0}),e.jsx(Dt,{title:"Live Job Circulars",value:I,description:B>0?`Published and still open (${B} published but past closing date)`:"Published and still open",icon:e.jsx(pa,{className:"w-5 h-5 text-green-500"}),colorClass:"border-l-green-500",delay:.1}),e.jsx(Dt,{title:"Total Job Postings",value:y,description:d?`${d.published_job_postings} published · ${d.draft_job_postings} draft · ${d.closed_job_postings} closed`:"All statuses combined",icon:e.jsx(da,{className:"w-5 h-5 text-purple-500"}),colorClass:"border-l-purple-500",delay:.2})]}),e.jsxs(Qs,{defaultValue:"applicants",children:[e.jsxs(Ks,{className:"grid w-full max-w-sm grid-cols-2",children:[e.jsxs(Ye,{value:"applicants",children:[e.jsx(gs,{className:"w-4 h-4 mr-2"}),"Applicants"]}),e.jsxs(Ye,{value:"jobs",children:[e.jsx(pa,{className:"w-4 h-4 mr-2"}),"Job Circulars"]})]}),e.jsx(Je,{value:"applicants",className:"mt-4",children:e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"text-base flex items-center gap-2",children:[e.jsx(gs,{className:"w-4 h-4 text-blue-500"}),"Applicants"]}),e.jsx(je,{children:"Registered applicant users across all organisations"})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>M(),disabled:p,children:[e.jsx(Es,{className:`w-4 h-4 mr-1 ${p?"animate-spin":""}`}),"Refresh"]})]}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-3 mt-3",children:e.jsxs("form",{onSubmit:F,className:"flex gap-2 flex-1",children:[e.jsx(E,{placeholder:"Search by name, email or title...",value:i,onChange:re=>c(re.target.value),className:"flex-1"}),e.jsx(u,{type:"submit",variant:"secondary",size:"sm",children:e.jsx(xs,{className:"w-4 h-4"})})]})})]}),e.jsx(Q,{children:z?e.jsx("div",{className:"space-y-3",children:Array.from({length:8}).map((re,te)=>e.jsx("div",{className:"h-10 bg-muted rounded animate-pulse"},te))}):(q=P==null?void 0:P.data)!=null&&q.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Username"}),e.jsx(T,{children:"Email"}),e.jsx(T,{children:"Professional Title"}),e.jsx(T,{children:"Experience"}),e.jsx(T,{children:"Registered"})]})}),e.jsx(Ue,{children:P.data.map(re=>{var te;return e.jsxs(le,{className:"hover:bg-muted/40",children:[e.jsx(C,{className:"font-medium text-sm whitespace-nowrap",children:`${re.first_name} ${re.last_name}`}),e.jsx(C,{className:"text-sm text-muted-foreground",children:((te=re.user)==null?void 0:te.username)??"-"}),e.jsx(C,{className:"text-sm text-muted-foreground",children:re.email??"-"}),e.jsx(C,{className:"text-sm",children:re.professional_title??"-"}),e.jsx(C,{className:"text-sm text-muted-foreground whitespace-nowrap",children:re.experience_in_months!=null?`${Math.round(re.experience_in_months/12*10)/10} yrs`:"-"}),e.jsx(C,{className:"text-xs text-muted-foreground whitespace-nowrap",children:re.created_at?Kt(new Date(re.created_at),{addSuffix:!0}):"-"})]},re.id)})})]})}),P.meta&&e.jsx(Xn,{page:P.meta.current_page,lastPage:P.meta.last_page,total:P.meta.total,perPage:P.meta.per_page,onPage:s})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(gs,{className:"w-12 h-12 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm",children:"No applicants found"})]})})]})}),e.jsx(Je,{value:"jobs",className:"mt-4",children:e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"text-base flex items-center gap-2",children:[e.jsx(pa,{className:"w-4 h-4 text-green-500"}),"Job Circulars"]}),e.jsx(je,{children:"All job postings across all organisations"})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>j(),disabled:k,children:[e.jsx(Es,{className:`w-4 h-4 mr-1 ${k?"animate-spin":""}`}),"Refresh"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mt-3",children:[e.jsxs(ke,{value:l,onValueChange:re=>{_(re),o(1)},children:[e.jsx(Se,{className:"w-full sm:w-[180px]",children:e.jsx(Ae,{placeholder:"Filter by status"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All Statuses"}),e.jsx(X,{value:"published",children:"Published"}),e.jsx(X,{value:"draft",children:"Draft"}),e.jsx(X,{value:"paused",children:"Paused"}),e.jsx(X,{value:"closed",children:"Closed"})]})]}),e.jsxs("form",{onSubmit:K,className:"flex gap-2 flex-1",children:[e.jsx(E,{placeholder:"Search by job title...",value:g,onChange:re=>b(re.target.value),className:"flex-1"}),e.jsx(u,{type:"submit",variant:"secondary",size:"sm",children:e.jsx(xs,{className:"w-4 h-4"})})]})]})]}),e.jsx(Q,{children:O?e.jsx("div",{className:"space-y-3",children:Array.from({length:8}).map((re,te)=>e.jsx("div",{className:"h-10 bg-muted rounded animate-pulse"},te))}):(U=A==null?void 0:A.data)!=null&&U.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Job Title"}),e.jsx(T,{children:"Organisation"}),e.jsx(T,{children:"Vacancies"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Closing Date"}),e.jsx(T,{children:"Posted"})]})}),e.jsx(Ue,{children:A.data.map(re=>{var te,G;return e.jsxs(le,{className:"hover:bg-muted/40",children:[e.jsx(C,{className:"font-medium text-sm",children:re.job_post_title??((te=re.job_position)==null?void 0:te.job_title)??"-"}),e.jsx(C,{className:"text-sm text-muted-foreground",children:((G=re.organization)==null?void 0:G.name)??"-"}),e.jsx(C,{className:"text-sm",children:re.number_of_vacancies??"-"}),e.jsx(C,{children:e.jsx(dx,{status:re.status,map:ox})}),e.jsx(C,{className:"text-xs text-muted-foreground whitespace-nowrap",children:re.closing_date?new Date(re.closing_date).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"}):"-"}),e.jsx(C,{className:"text-xs text-muted-foreground whitespace-nowrap",children:re.created_at?Kt(new Date(re.created_at),{addSuffix:!0}):"-"})]},re.id)})})]})}),A.meta&&e.jsx(Xn,{page:A.meta.current_page,lastPage:A.meta.last_page,total:A.meta.total,perPage:A.meta.per_page,onPage:o})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(pa,{className:"w-12 h-12 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm",children:"No job postings found"})]})})]})})]})]})})}const Lt=5,ux=10*1024*1024,xx=15*1024*1024,hx=".pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.ppt,.pptx,.png,.jpg,.jpeg,.gif,.zip",px=a=>a<1024*1024?`${Math.max(1,Math.round(a/1024))} KB`:`${(a/1024/1024).toFixed(1)} MB`;function gx({open:a,onOpenChange:s}){var U,re;const{data:t,isLoading:n}=Zi(void 0,{skip:!a}),[i,{isLoading:c}]=Au(),[r,{isLoading:o}]=Pu(),[l,_]=m.useState(""),[h,N]=m.useState(""),[g,b]=m.useState("all"),[P,z]=m.useState([]),[p,M]=m.useState([]),[A,O]=m.useState(null),[k,j]=m.useState(!1),S=((U=t==null?void 0:t.data)==null?void 0:U.recipients)??[],d=(re=t==null?void 0:t.data)==null?void 0:re.from,L=m.useMemo(()=>g==="selected"?P.length:S.filter(te=>te.organization_status==="active").length,[g,P,S]),I=()=>{_(""),N(""),b("all"),z([]),M([]),O(null)},B=te=>{if(!te)return;const G=[...p];for(const w of Array.from(te)){if(G.length>=Lt){v.error(`You can attach up to ${Lt} files.`);break}if(w.size>ux){v.error(`${w.name} is larger than 10 MB.`);continue}G.push(w)}if(G.reduce((w,Y)=>w+Y.size,0)>xx){v.error("Attachments must add up to 15 MB or less.");return}M(G),O(null)},y=te=>{M(G=>G.filter((w,Y)=>Y!==te)),O(null)},F=()=>l.trim()?h.trim()?g==="selected"&&P.length===0?(v.error("Choose at least one organization, or send to all."),!1):!0:(v.error("Write a message."),!1):(v.error("Add a subject."),!1),K=async()=>{var te;try{const G=await i({subject:l,body:h,attachment_names:p.map(w=>w.name)}).unwrap();O(G.data.html)}catch(G){v.error(((te=G==null?void 0:G.data)==null?void 0:te.message)||"Could not build the preview")}},q=async()=>{var G;const te=new FormData;te.append("subject",l.trim()),te.append("body",h),te.append("recipient_mode",g),g==="selected"&&P.forEach(w=>te.append("organization_ids[]",w)),p.forEach(w=>te.append("attachments[]",w));try{const w=await r(te).unwrap();v.success(w.message||"Email queued"),j(!1),I(),s(!1)}catch(w){j(!1),v.error(((G=w==null?void 0:w.data)==null?void 0:G.message)||"Failed to send the email")}};return e.jsxs(e.Fragment,{children:[e.jsx(Fe,{open:a,onOpenChange:s,children:e.jsxs(ze,{className:"max-h-[90vh] max-w-3xl overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:"Compose email"}),e.jsx(Ge,{children:"Write to organization owners. Each owner receives their own copy, so nobody can see who else it was sent to."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"From"}),e.jsx("div",{className:"rounded-md border bg-muted/40 px-3 py-2 text-sm",children:d!=null&&d.address?d.name?`${d.name} <${d.address}>`:d.address:"Loading..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(d==null?void 0:d.source)==="env"?"No system SMTP is configured, so this uses the server's .env mail settings.":"Sent through the system admin SMTP configuration."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"To"}),e.jsx(er,{owners:S,isLoading:n,mode:g,onModeChange:b,selectedIds:P,onSelectedIdsChange:z})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"broadcast_subject",children:"Subject *"}),e.jsx(E,{id:"broadcast_subject",value:l,maxLength:255,onChange:te=>{_(te.target.value),O(null)},placeholder:"e.g. Scheduled maintenance this weekend"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"broadcast_body",children:"Message *"}),e.jsx(Ce,{id:"broadcast_body",rows:10,value:h,onChange:te=>{N(te.target.value),O(null)},placeholder:"Write your message..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Plain text; line breaks are kept. Each email opens with "Hi [owner name]," and is signed from the SovoHR Team.'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Attachments"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(u,{type:"button",variant:"outline",size:"sm",asChild:!0,children:e.jsxs("label",{htmlFor:"broadcast_files",className:"cursor-pointer",children:[e.jsx(Qt,{className:"mr-2 h-4 w-4"}
4),"Add files"]})}),e.jsx("input",{id:"broadcast_files",type:"file",multiple:!0,accept:hx,className:"hidden",onChange:te=>{B(te.target.files),te.target.value=""}}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Up to ",Lt," files, 10 MB each, 15 MB in total."]})]}),p.length>0&&e.jsx("ul",{className:"divide-y rounded-md border",children:p.map((te,G)=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2 text-sm",children:[e.jsxs("span",{className:"min-w-0 truncate",children:[te.name,e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:px(te.size)})]}),e.jsx(u,{type:"button",variant:"ghost",size:"sm",onClick:()=>y(G),"aria-label":`Remove ${te.name}`,children:e.jsx(st,{className:"h-4 w-4"})})]},`${te.name}-${G}`))})]}),A&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Preview"}),e.jsx("iframe",{title:"Email preview",srcDoc:A,sandbox:"",className:"h-[480px] w-full rounded-md border bg-white"})]})]}),e.jsxs(Re,{className:"gap-2",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsxs(u,{type:"button",variant:"outline",onClick:K,disabled:c,children:[c?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Fs,{className:"mr-2 h-4 w-4"}),"Preview"]}),e.jsxs(u,{type:"button",onClick:()=>F()&&j(!0),disabled:o||n,children:[e.jsx(nt,{className:"mr-2 h-4 w-4"}),"Send"]})]})]})}),e.jsx(ss,{open:k,onOpenChange:j,children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsxs(ns,{children:["Send to ",L," organization owner",L===1?"":"s","?"]}),e.jsxs(is,{children:['Each owner receives a separate copy of "',l.trim(),'"',p.length>0?` with ${p.length} attachment(s)`:"",". Emails are queued straight away and cannot be recalled."]})]}),e.jsxs(rs,{children:[e.jsx(ls,{disabled:o,children:"Cancel"}),e.jsxs(cs,{onClick:te=>{te.preventDefault(),q()},disabled:o,children:[o&&e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Send email"]})]})]})})]})}function jx(){const[a,s]=m.useState({page:1,per_page:20,status:"",purpose:"",to:"",organization_id:""}),[t,n]=m.useState(!1),{data:i,isLoading:c}=Tu(a),[r]=Fu(),[o]=zu(),l=(i==null?void 0:i.data)??[],_=i==null?void 0:i.meta,h=(_==null?void 0:_.last_page)??1,N=(_==null?void 0:_.total)??0,g=b=>{s(P=>({...P,...b}))};return e.jsx(ye,{title:"Email Logs",subtitle:"",children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(ms,{className:"h-6 w-6"}),"Email Logs"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"System-wide email log - all organisations and system-admin emails. Filter by organisation, status, purpose, or recipient. Retry any failed delivery."})]}),e.jsxs(u,{onClick:()=>n(!0),className:"flex items-center gap-2",children:[e.jsx(nt,{className:"h-4 w-4"}),"Compose email"]})]}),e.jsx(gx,{open:t,onOpenChange:n}),e.jsx(W,{children:e.jsx(Q,{className:"pt-4",children:e.jsx(Hc,{logs:l,isLoading:c,page:a.page,lastPage:h,total:N,params:a,showOrganization:!0,onParamsChange:g,onPageChange:b=>g({page:b}),onRetry:b=>r(b).unwrap(),onDelete:b=>o(b).unwrap()})})})]})})}const fx=He.injectEndpoints({endpoints:a=>({getSystemBackups:a.query({query:s=>({url:"/admin/system-backups",method:"GET",params:s??{}}),providesTags:["systemBackups"]}),getBackupConfig:a.query({query:()=>({url:"/admin/system-backups/config",method:"GET"}),providesTags:["systemBackupConfig"]}),saveBackupConfig:a.mutation({query:s=>({url:"/admin/system-backups/config",method:"POST",body:s}),invalidatesTags:["systemBackupConfig"]}),testBackupConnection:a.mutation({query:s=>({url:"/admin/system-backups/test-connection",method:"POST",body:s})}),runSystemBackup:a.mutation({query:()=>({url:"/admin/system-backups/run",method:"POST"}),invalidatesTags:["systemBackups"]}),deleteSystemBackup:a.mutation({query:s=>({url:`/admin/system-backups/${s}`,method:"DELETE"}),invalidatesTags:["systemBackups"]}),restoreSystemBackup:a.mutation({query:s=>({url:`/admin/system-backups/${s}/restore`,method:"POST"}),invalidatesTags:["systemBackups"]})})}),{useGetSystemBackupsQuery:vx,useGetBackupConfigQuery:yx,useSaveBackupConfigMutation:Nx,useTestBackupConnectionMutation:bx,useRunSystemBackupMutation:_x,useDeleteSystemBackupMutation:wx,useRestoreSystemBackupMutation:Cx}=fx;function kx(a){return a?a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:a<1024*1024*1024?`${(a/1024/1024).toFixed(1)} MB`:`${(a/1024/1024/1024).toFixed(2)} GB`:"-"}
4function Sx(a){return a?new Date(a).toLocaleString():"-"}function Ax({status:a}){const s={pending:{label:"Pending",variant:"secondary",icon:e.jsx(zs,{className:"h-3 w-3"})},processing:{label:"Processing",variant:"outline",icon:e.jsx(ce,{className:"h-3 w-3 animate-spin"})},completed:{label:"Completed",variant:"default",icon:e.jsx(ps,{className:"h-3 w-3"})},failed:{label:"Failed",variant:"destructive",icon:e.jsx(oa,{className:"h-3 w-3"})}},{label:t,variant:n,icon:i}=s[a]??s.pending;return e.jsxs(ee,{variant:n,className:"flex items-center gap-1 w-fit",children:[i,t]})}function Px({type:a}){const s={local:{label:"Local ZIP",icon:e.jsx(ya,{className:"h-3 w-3"})},azure_blob:{label:"Azure Blob",icon:e.jsx(rn,{className:"h-3 w-3"})},google_drive:{label:"Google Drive",icon:e.jsx(sn,{className:"h-3 w-3"})}},{label:t,icon:n}=s[a??"local"]??{label:a??"-",icon:null};return e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-sm",children:[n,t]})}function Tx({status:a}){if(!a)return null;const s={pending:{label:"Restore Queued",variant:"secondary",icon:e.jsx(zs,{className:"h-3 w-3"})},processing:{label:"Restoringâ¦",variant:"outline",icon:e.jsx(ce,{className:"h-3 w-3 animate-spin"})},completed:{label:"Restored",variant:"default",icon:e.jsx(ps,{className:"h-3 w-3"})},failed:{label:"Restore Failed",variant:"destructive",icon:e.jsx(oa,{className:"h-3 w-3"})}},{label:t,variant:n,icon:i}=s[a]??s.pending;return e.jsxs(ee,{variant:n,className:"flex items-center gap-1 w-fit text-xs",children:[i,t]})}const Fx="â¢â¢â¢â¢â¢â¢â¢â¢";function Zn(a){return a===Fx||a.includes("â¢")}function zx(){const{data:a,isLoading:s}=yx(),[t,{isLoading:n}]=Nx(),[i,{isLoading:c}]=bx(),r=a==null?void 0:a.data,[o,l]=m.useState({destination_type:(r==null?void 0:r.destination_type)??"local",azure_account_name:(r==null?void 0:r.azure_account_name)??"",azure_account_key:(r==null?void 0:r.azure_account_key)??"",azure_container:(r==null?void 0:r.azure_container)??"",azure_path_prefix:(r==null?void 0:r.azure_path_prefix)??"system-backups",google_client_email:(r==null?void 0:r.google_client_email)??"",google_private_key:(r==null?void 0:r.google_private_key)??"",google_folder_id:(r==null?void 0:r.google_folder_id)??""}),[_,h]=m.useState(!1);r&&!_&&(l({destination_type:r.destination_type??"local",azure_account_name:r.azure_account_name??"",azure_account_key:r.azure_account_key??"",azure_container:r.azure_container??"",azure_path_prefix:r.azure_path_prefix??"system-backups",google_client_email:r.google_client_email??"",google_private_key:r.google_private_key??"",google_folder_id:r.google_folder_id??""}),h(!0));const N=z=>({value:o[z],onChange:p=>l(M=>({...M,[z]:p.target.value}))});function g(){const z={destination_type:o.destination_type};return o.destination_type==="azure_blob"&&(z.azure_account_name=o.azure_account_name,Zn(o.azure_account_key)||(z.azure_account_key=o.azure_account_key),z.azure_container=o.azure_container,z.azure_path_prefix=o.azure_path_prefix||"system-backups"),o.destination_type==="google_drive"&&(z.google_client_email=o.google_client_email,Zn(o.google_private_key)||(z.google_private_key=o.google_private_key),z.google_folder_id=o.google_folder_id),z}async function b(){try{await t(g()).unwrap(),v.success("Backup configuration saved."),h(!1)}catch{v.error("Failed to save configuration.")}}async function P(){if(o.destination_type==="local"){v.info("Local storage needs no connection test.");return}try{const z=await i(g()).unwrap();z.success?v.success(z.message):v.error(z.message)}catch{v.error("Connection test failed. Check your credentials.")}}return s?e.jsx(W,{children:e.jsxs(Q,{className:"pt-6 space-y-4",children:[e.jsx(js,{className:"h-10 w-64"}),e.jsx(js,{className:"h-10 w-full"}),e.jsx(js,{className:"h-10 w-full"})]})}):e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Backup Destination"}),e.jsx(je,{children:"Choose where system backups should be stored. Configure the destination credentials, then save. A connection test is available for cloud destinations."})]}),e.jsxs(Q,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"destination_type",children:"Destination"}),e.jsxs(ke,{value:o.destination_type,onValueChange:z=>l(p=>({...p,destination_type:z})),children:[e.jsx(Se,{id:"destination_type",className:"w-64",children:e.jsx(Ae,{})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"local",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-4 w-4"})," Local ZIP (downloadable)"]})}),e.jsx(X,{value:"azure_blob",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(rn,{className:"h-4 w-4"})," Azure Blob Storage"]})}),e.jsx(X,{value:"google_drive",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(sn,{className:"h-4 w-4"})," Google Drive"]})})]})]}),o.destination_type==="local"&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Backups will be stored on the server and available for download from the History tab."})]}),o.destination_type==="azure_blob"&&e.jsxs("div",{className:"space-y-4 border rounded-lg p-4 bg-muted/30",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Azure Blob Storage Credentials"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"azure_account_name",children:"Storage Account Name"}),e.jsx(E,{id:"azure_account_name",placeholder:"mystorageaccount",...N("azure_account_name")}
4)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"azure_account_key",children:"Account Key"}),e.jsx(E,{id:"azure_account_key",type:"password",placeholder:r!=null&&r.azure_account_key?"Leave blank to keep existing":"Enter account key",...N("azure_account_key")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"azure_container",children:"Container Name"}),e.jsx(E,{id:"azure_container",placeholder:"backups",...N("azure_container")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"azure_path_prefix",children:"Path Prefix"}),e.jsx(E,{id:"azure_path_prefix",placeholder:"system-backups",...N("azure_path_prefix")})]})]})]}),o.destination_type==="google_drive"&&e.jsxs("div",{className:"space-y-4 border rounded-lg p-4 bg-muted/30",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Google Drive Service Account Credentials"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"google_client_email",children:"Service Account Email"}),e.jsx(E,{id:"google_client_email",placeholder:"[email protected]",...N("google_client_email")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"google_folder_id",children:"Folder ID"}),e.jsx(E,{id:"google_folder_id",placeholder:"1A2B3C4D5E6F7G8H...",...N("google_folder_id")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The ID from the Google Drive folder URL. Share the folder with the service account email."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"google_private_key",children:"Private Key (PEM)"}),e.jsx(Ce,{id:"google_private_key",rows:8,placeholder:r!=null&&r.google_private_key?"Leave blank to keep existing key":`-----BEGIN RSA PRIVATE KEY----- 5... 6-----END RSA PRIVATE KEY-----`,className:"font-mono text-xs",...N("google_private_key")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsxs(u,{onClick:b,disabled:n,children:[n?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ht,{className:"h-4 w-4 mr-2"}),"Save Configuration"]}),o.destination_type!=="local"&&e.jsxs(u,{variant:"outline",onClick:P,disabled:c,children:[c?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Yc,{className:"h-4 w-4 mr-2"}),"Test Connection"]})]})]})]})}function Ex(){const[a,s]=m.useState(1),[t,n]=m.useState(null),[i,c]=m.useState(null),{data:r,isLoading:o,isFetching:l,refetch:_}=vx({page:a,per_page:15}),[h,{isLoading:N}]=_x(),[g,{isLoading:b}]=wx(),[P,{isLoading:z}]=Cx(),p=(r==null?void 0:r.data)??[],M=r==null?void 0:r.meta,A=(M==null?void 0:M.last_page)??1,O=(M==null?void 0:M.total)??0;async function k(){var L;try{await h().unwrap(),v.success("Backup job queued. Refresh in a moment to see progress.")}catch(I){const B=I;v.error(((L=B==null?void 0:B.data)==null?void 0:L.message)??"Failed to start backup.")}}async function j(){if(t)try{await g(t).unwrap(),v.success("Backup deleted.")}catch{v.error("Failed to delete backup.")}finally{n(null)}}async function S(){var L;if(i)try{await P(i).unwrap(),v.success("Restore job queued. All application data will be replaced. Refresh to track progress.")}catch(I){const B=I;v.error(((L=B==null?void 0:B.data)==null?void 0:L.message)??"Failed to start restore.")}finally{c(null)}}function d(L){if(L.destination_type!=="local"){v.info("Downloads are only available for local backups. Cloud backups are stored in your configured destination.");return}const I=fs("token","admin"),y=`${"https://api.sovohr.com/api".replace(/\/$/,"")}/admin/system-backups/${L.id}/download`;fetch(y,{headers:{Authorization:`Bearer ${I}`}}).then(F=>{if(!F.ok)throw new Error(`HTTP ${F.status}`);return F.blob()}).then(F=>{const K=URL.createObjectURL(F),q=document.createElement("a");q.href=K,q.download=L.file_name??"system_backup.zip",document.body.appendChild(q),q.click(),document.body.removeChild(q),URL.revokeObjectURL(K)}).catch(()=>v.error("Download failed. The backup file may have been removed."))}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:O>0?`${O} backup${O!==1?"s":""} total`:"No backups yet"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>_(),disabled:l,children:[e.jsx(Es,{className:`h-4 w-4 mr-1 ${l?"animate-spin":""}`}),"Refresh"]}),e.jsxs(u,{size:"sm",onClick:k,disabled:N,children:[N?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Wc,{className:"h-4 w-4 mr-2"}),"Run Backup Now"]})]})]}),e.jsx(W,{children:e.jsx(Q,{className:"pt-0",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Started"}),e.jsx(T,{children:"Backup Status"}),e.jsx(T,{children:"Restore Status"}),e.jsx(T,{children:"Destination"}),e.jsx(T,{children:"File Name"}),e.jsx(T,{children:"Size"}),e.jsx(T,{children:"Tables"}),e.jsx(T,{className:"w-[120px]",children:"Actions"})]})}),e.jsx(Ue,{children:o?Array.from({length:5}).map((L,I)=>e.jsx(le,{children:Array.from({length:8}).map((B,y)=>e.jsx(C,{children:e.jsx(js,{className:"h-4 w-full"})},y))},I)):p.length===0?e.jsx(le,{children:e.jsxs(C,{colSpan:8,className:"text-center py-12 text-muted-foreground",children:[e.jsx(Zt,{className:"h-8 w-8 mx-auto mb-2 opacity-40"}),"No backups yet. Configure your destination and run a backup."]})}):p.map(L=>e.jsxs(le,{children:[e.jsx(C,{className:"text-sm",children:Sx(L.created_at)}),e.jsx(C,{children:e.jsx(Ax,{status:L.status})}),e.jsxs(C,{children:[e.jsx(Tx,{status:L.restore_status}),L.restore_error&&e.jsx("p",{className:"text-xs text-destructive mt-1 max-w-[160px] truncate",title:L.restore_error,children:L.restore_error})]}),e.jsx(C,{children:e.jsx(Px,{type:L.destination_type})}),e.jsx(C,{className:"font-mono text-xs truncate max-w-[150px]",title:L.file_name,children:L.file_name??"-"}),e.jsx(C,{className:"text-sm",children:kx(L.file_size)}),e.jsx(C,{className:"text-sm",children:L.tables_count!=null?`${L.tables_count}`:"-"}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[L.status==="completed"&&L.destination_type==="local"&&e.jsx(u,{variant:"ghost",size:"icon",className:"h-7 w-7",t
6itle:"Download backup ZIP",onClick:()=>d(L),children:e.jsx(ma,{className:"h-4 w-4"})}),L.status==="completed"&&L.restore_status!=="processing"&&L.restore_status!=="pending"&&e.jsx(u,{variant:"ghost",size:"icon",className:"h-7 w-7 text-blue-600 hover:text-blue-700",title:"Restore system from this backup",onClick:()=>c(L.id),disabled:z,children:e.jsx(Es,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive hover:text-destructive",title:"Delete backup record",onClick:()=>n(L.id),children:e.jsx(Le,{className:"h-4 w-4"})})]})})]},L.id))})]})})}),A>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:a<=1,onClick:()=>s(L=>L-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",a," of ",A]}),e.jsx(u,{variant:"outline",size:"sm",disabled:a>=A,onClick:()=>s(L=>L+1),children:"Next"})]}),e.jsx(ss,{open:!!t,onOpenChange:L=>!L&&n(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete Backup"}),e.jsx(is,{children:"This will permanently delete this backup record (and the local file if applicable). This action cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsxs(cs,{onClick:j,disabled:b,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[b?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):null,"Delete"]})]})]})}),e.jsx(ss,{open:!!i,onOpenChange:L=>!L&&c(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Restore System from Backup"}),e.jsx(is,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:["This will ",e.jsx("strong",{children:"replace all current application data"})," with the data from this backup. This includes all organizations, users, subscriptions, and configuration records."]}),e.jsx("p",{className:"text-destructive font-medium",children:"This action is irreversible. Make sure you have a recent backup of the current state before proceeding."})]})})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsxs(cs,{onClick:S,disabled:z,className:"bg-blue-600 text-white hover:bg-blue-700",children:[z?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):null,"Yes, Restore Now"]})]})]})})]})}function Dx(){return e.jsx(ye,{title:"System",subtitle:"Backup & Restore",children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(Zt,{className:"h-6 w-6"}),"System Backup"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Configure your backup destination (Azure Blob, Google Drive, or local ZIP) and trigger full system database exports. Backups are queued as background jobs."})]}),e.jsxs(Qs,{defaultValue:"history",children:[e.jsxs(Ks,{children:[e.jsxs(Ye,{value:"history",className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"Backup History"]}),e.jsxs(Ye,{value:"config",className:"flex items-center gap-2",children:[e.jsx(rn,{className:"h-4 w-4"}),"Configuration"]})]}),e.jsx(Je,{value:"history",className:"mt-6",children:e.jsx(Ex,{})}),e.jsx(Je,{value:"config",className:"mt-6",children:e.jsx(zx,{})})]})]})})}const Lx=He.injectEndpoints({endpoints:a=>({getActivityLogs:a.query({query:s=>({url:"/admin/activity-logs",method:"GET",params:s??{}}),providesTags:["activityLogs"]}),getActivityLogEvents:a.query({query:()=>({url:"/admin/activity-logs/events",method:"GET"}),providesTags:["activityLogEvents"]}),getActivityLogModules:a.query({query:()=>({url:"/admin/activity-logs/modules",method:"GET"}),providesTags:["activityLogEvents"]}),getActivityLogArchives:a.query({query:()=>({url:"/admin/activity-logs/archives",method:"GET"}),providesTags:["activityLogArchives"]})})}),{useGetActivityLogsQuery:Mx,useGetActivityLogModulesQuery:qx,useGetActivityLogArchivesQuery:Ox}=Lx,_a=15;function Rx(a){return a?a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:a<1024*1024*1024?`${(a/1024/1024).toFixed(1)} MB`:`${(a/1024/1024/1024).toFixed(2)} GB`:"-"}
6function hn(a){return a?new Date(a).toLocaleString():"-"}async function nr(a,s){const t=fs("token","admin"),n=await fetch(a,{headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=await n.blob(),c=URL.createObjectURL(i),r=document.createElement("a");r.href=c,r.download=s,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(c)}function ir(){return"https://api.sovohr.com/api".replace(/\/$/,"")}function Ix(){const{data:a,isLoading:s,isFetching:t,refetch:n}=Ox(),i=(a==null?void 0:a.data)??[],[c,r]=m.useState(null);async function o(l){r(l.name);try{await nr(`${ir()}/admin/activity-logs/archives/${encodeURIComponent(l.name)}/download`,l.name)}catch{v.error("Download failed. The archive may have been removed.")}finally{r(null)}}return e.jsxs(W,{children:[e.jsx(se,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(In,{className:"h-5 w-5"}),"Archived Backups"]}),e.jsxs(je,{children:["Entries older than ",_a," days, zipped and removed from the live log automatically."]})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>n(),disabled:t,children:[e.jsx(Es,{className:`h-4 w-4 mr-1 ${t?"animate-spin":""}`}),"Refresh"]})]})}),e.jsx(Q,{children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Archive File"}),e.jsx(T,{children:"Size"}),e.jsx(T,{children:"Created"}),e.jsx(T,{className:"w-[100px]",children:"Actions"})]})}),e.jsx(Ue,{children:s?Array.from({length:3}).map((l,_)=>e.jsx(le,{children:Array.from({length:4}).map((h,N)=>e.jsx(C,{children:e.jsx(js,{className:"h-4 w-full"})},N))},_)):i.length===0?e.jsx(le,{children:e.jsxs(C,{colSpan:4,className:"text-center py-10 text-muted-foreground",children:[e.jsx(In,{className:"h-8 w-8 mx-auto mb-2 opacity-40"}),"No archives yet. Once entries pass ",_a," days old, they will appear here."]})}):i.map(l=>e.jsxs(le,{children:[e.jsx(C,{className:"font-mono text-xs",children:l.name}),e.jsx(C,{className:"text-sm",children:Rx(l.size)}),e.jsx(C,{className:"text-sm",children:hn(l.created_at)}),e.jsx(C,{children:e.jsx(u,{variant:"ghost",size:"icon",className:"h-7 w-7",title:"Download archive ZIP",onClick:()=>o(l),disabled:c===l.name,children:c===l.name?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(ma,{className:"h-4 w-4"})})})]},l.name))})]})})]})}function rr(a){return new Date(a).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function lr(a){return new Date(a).toLocaleDateString([],{day:"numeric",month:"short",year:"numeric"})}function $x(a){const s=Math.max(0,Math.round((Date.now()-new Date(a).getTime())/1e3));if(s<60)return"just now";const t=Math.round(s/60);if(t<60)return`${t} minute${t===1?"":"s"} ago`;const n=Math.round(t/60);if(n<24)return`${n} hour${n===1?"":"s"} ago`;const i=Math.round(n/24);return`${i} day${i===1?"":"s"} ago`}function pn({result:a}){return a==="failed"?e.jsxs(ee,{variant:"outline",className:"border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950 dark:text-red-300",children:[e.jsx(oa,{className:"h-3 w-3 mr-1"}),"Failed"]}):e.jsxs(ee,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700 dark:border-green-900 dark:bg-green-950 dark:text-green-300",children:[e.jsx(ps,{className:"h-3 w-3 mr-1"}),"Success"]})}function Bx({entry:a}){var s;return!a.user_name&&!a.user_email?e.jsx("span",{className:"text-muted-foreground",children:"System"}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:a.user_name||a.user_email}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:((s=a.organization)==null?void 0:s.name)??(a.user_name?a.user_email:null)??"Platform"})]})}const Ux=new Set(["module","activity","record","result","changes"]);function ei(a){return a.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function Mt(a){return a==null||a===""?"-":typeof a=="boolean"?a?"Yes":"No":typeof a=="object"?JSON.stringify(a):String(a)}const Gx=15;function Vx({entry:a,onOpenChange:s}){var _,h;const[t,n]=m.useState(!1);m.useEffect(()=>{n(!1)},[a==null?void 0:a.id]);const i=((_=a==null?void 0:a.properties)==null?void 0:_.changes)??null,c=i?Object.entries(i):[],r=a!=null&&a.properties?Object.entries(a.properties).filter(([N])=>!Ux.has(N)):[],o=t?r:r.slice(0,Gx),l=r.length-o.length;return e.jsx(Fe,{open:!!a,onOpenChange:s,children:e.jsx(ze,{className:"sm:max-w-xl",children:a&&e.jsxs(e.Fragment,{children:[e.jsxs(Ee,{children:[e.jsxs(De,{className:"flex items-center gap-2 flex-wrap pr-6 break-words",children:[a.activity,e.jsx(pn,{result:a.result})]}),e.jsx(Ge,{className:"break-words",children:a.description})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Time"}),e.jsx("div",{children:hn(a.created_at)})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Module"}),e.jsx("div",{children:a.module})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"User"}),e.jsx("div",{className:"break-words",children:a.user_name||a.user_email||"System"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Organization"}),e.jsx("div",{className:"break-words",children:((h=a.organization)==null?void 0:h.name)??"-"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"IP Address"}),e.jsx("div",{className:"font-mono break-all",children:a.ip_address??"-"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Event"}),e.jsx("div",{className:"font-mono text-xs break-all",children:a.event})]}),a.record&&e.jsxs("div",{className:"col-span-1 sm:col-span-2 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Record"}),e.jsx("div",{className:"break-words",children:a.record})]})]}),c.length>0&&e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:"What changed"}),e.jsxs("div",{className:"rounded-md border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50",children:[e.jsx("span",{children:"Field"}),e.jsx("span",{children:"Previous"}),e.jsx("span",{children:"New"})]}),e.jsx("div",{className:"divide-y",children:c.map(([N,g])=>e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-3 py-2 text-sm",children:[e.jsx("div",{className:"font-medium min-w-0 break-words",children:ei(N)}),e.jsx("div",{className:"text-muted-foreground min-w-0 break-all line-through decoration-red-400",children:Mt
6(g==null?void 0:g.from)}),e.jsx("div",{className:"text-green-700 dark:text-green-400 min-w-0 break-all",children:Mt(g==null?void 0:g.to)})]},N))})]})]}),r.length>0&&e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:"Additional details"}),e.jsx("div",{className:"rounded-md border divide-y",children:o.map(([N,g])=>e.jsxs("div",{className:"flex items-start justify-between gap-4 px-3 py-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:ei(N)}),e.jsx("span",{className:"text-right min-w-0 break-all",children:Mt(g)})]},N))}),l>0&&e.jsxs(u,{variant:"ghost",size:"sm",className:"mt-1 h-7 text-xs w-full",onClick:()=>n(!0),children:["Show ",l," more"]})]})]})})})}function Qx({entries:a,onSelect:s}){const t=[];for(const n of a){const i=lr(n.created_at),c=t[t.length-1];c&&c.day===i?c.items.push(n):t.push({day:i,items:[n]})}return e.jsx("div",{className:"space-y-6",children:t.map(n=>e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-3",children:n.day}),e.jsx("ol",{className:"relative border-l border-border ml-[4.75rem] space-y-5",children:n.items.map(i=>{var c;return e.jsxs("li",{className:"relative pl-5 -ml-2 pr-2 py-1 rounded-md cursor-pointer hover:bg-muted/50",onClick:()=>s(i),children:[e.jsx("span",{className:"absolute -left-[5.25rem] top-1.5 w-16 text-right font-mono text-xs text-muted-foreground tabular-nums",children:rr(i.created_at)}),e.jsx("span",{className:`absolute -left-[5px] top-2.5 h-2.5 w-2.5 rounded-full ring-4 ring-background ${i.result==="failed"?"bg-red-500":"bg-green-500"}`}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-sm",children:i.activity}),i.result==="failed"&&e.jsx(pn,{result:"failed"})]}),e.jsx("p",{className:"text-sm text-foreground/90 break-words",children:i.description}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[i.module,i.record?e.jsxs(e.Fragment,{children:[" â ",i.record]}):null,(c=i.organization)!=null&&c.name?e.jsxs(e.Fragment,{children:[" · ",i.organization.name]}):null,i.ip_address?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"font-mono",children:i.ip_address})]}):null,e.jsx("span",{className:"mx-1",children:"·"}),e.jsx("span",{title:hn(i.created_at),children:$x(i.created_at)})]})]},i.id)})})]},n.day))})}const Kx=[15,25,50,100];function Hx(){const[a,s]=m.useState(1),[t,n]=m.useState(15),[i,c]=m.useState(""),[r,o]=m.useState("all"),[l,_]=m.useState("all"),[h,N]=m.useState(""),[g,b]=m.useState(""),[P,z]=m.useState("table"),[p,M]=m.useState(!1),[A,O]=m.useState(null),{data:k,isLoading:j,isFetching:S,refetch:d}=Mx({page:a,per_page:t,search:i||void 0,module:r==="all"?void 0:r,result:l==="all"?void 0:l,date_from:h||void 0,date_to:g||void 0}),{data:L}=qx(),I=(k==null?void 0:k.data)??[],B=k==null?void 0:k.meta,y=(B==null?void 0:B.last_page)??1,F=(B==null?void 0:B.total)??0,K=(L==null?void 0:L.data)??[];async function q(){M(!0);try{const U=new URLSearchParams;i&&U.set("search",i),r!=="all"&&U.set("module",r),l!=="all"&&U.set("result",l),h&&U.set("date_from",h),g&&U.set("date_to",g),await nr(`${ir()}/admin/activity-logs/export?${U.toString()}`,`activity_log_export_${new Date().toISOString().slice(0,10)}.csv`)}catch{v.error("Export failed. Please try again.")}finally{M(!1)}}return e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-5 w-5"}),"Live Activity Log"]}),e.jsx(je,{children:F>0?`${F} entr${F!==1?"ies":"y"} in the last ${_a} days`:`Last ${_a} days`})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"inline-flex rounded-md border p-0.5",children:[e.jsxs(u,{variant:P==="table"?"secondary":"ghost",size:"sm",className:"h-7",onClick:()=>z("table"),children:[e.jsx(eo,{className:"h-4 w-4 mr-1"}),"Table"]}),e.jsxs(u,{variant:P==="timeline"?"secondary":"ghost",size:"sm",className:"h-7",onClick:()=>z("timeline"),children:[e.jsx(so,{className:"h-4 w-4 mr-1"}),"Timeline"]})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>d(),disabled:S,children:[e.jsx(Es,{className:`h-4 w-4 mr-1 ${S?"animate-spin":""}`}),"Refresh"]}),e.jsxs(u,{size:"sm",onClick:q,disabled:p,children:[p?e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ma,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 pt-4 sm:grid-cols-2 lg:grid-cols-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(x,{htmlFor:"al-search",className:"text-xs",children:"Search"}),e.jsxs("div",{className:"relative",children:[e.jsx(xs,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(E,{id:"al-search",placeholder:"User, organisation, record...",className:"pl-8",value:i,onChange:U=>{c(U.target.value),s(1)}})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(x,{htmlFor:"al-module",className:"text-xs",children:"Module"}),e.jsxs(ke,{value:r,onValueChange:U=>{o(U),s(1)},children:[e.jsx(Se,{id:"al-module",children:e.jsx(Ae,{placeholder:"All modules"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All modules"}),K.map(U=>e.jsx(X,{value:U,children:U},U))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(x,{htmlFor:"al-result",className:"text-xs",children:"Result"}),e.jsxs(ke,{value:l,onValueChange:U=>{_(U),s(1)},children:[e.jsx(Se,{id:"al-result",children:e.jsx(Ae,{placeholder:"All results"})}),e.jsxs(Pe,{children:[e.jsx(X,{value:"all",children:"All results"}),e.jsx(X,{value:"success",children:"Success"}),e.jsx(X,{value:"failed",children:"Failed"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(x,{htmlFor:"al-from",className:"text-xs",children:"From"}),e.jsx(E,{id:"al-from",type:"date",value:h,onChange:U=>{N(U.target.value),s(1)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(x,{htmlFor:"al-to",className:"text-xs",children:"To"}),e.jsx(E,{id:"al-to",type:"date",value:g,onChange:U=>{b(U.target.value),s(1)}})]})]})]}),e.jsxs(Q,{className:"pt-0",children:[j?e.jsx("div",{className:"space-y-2",children:Array.from({length:8}).map((U,re)=>e.jsx(js,{className:"h-10 w-full"},re))}):I.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Ht,{className:"h-8 w-8 mx-auto mb-2 opacity-40"}),"No activity found for the current filters."]}):P==="timeline"?e.jsx(Qx,{entries:I,onSelect:O}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{className:"whitespace-nowrap",children:"Time"}),e.jsx(T,{children:"User"}),e.jsx(T,{children:"Module"}),e.jsx(T,{children:"Activity"}),e.jsx(T,{children:"Record"}),e.jsx(T,{children:"IP Address"}),e.jsx(T,{children:"Result"}),e.jsx(T,{className:"w-[80px]",children:"Details"})]})}),e.jsx(Ue,{children:I.map(U=>e.jsxs(le,{title:U.description,className:"cursor-pointer",onClick:()=>O(U),children:[e.jsxs(C,{className:"whitespace-nowrap",children:[e.jsx("div",{className:"font-mono text-sm tabular-nums",children:rr(U.created_at)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:lr(U.created_at)})]}),e.jsx(C,{className:"text-sm max-w-[220px]",children:e.jsx(Bx,{entry:U})}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",className:"whitespace-nowrap",children:U.module})}),e.jsxs(C,{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:U.activity}),e.jsx("div",{className:"text-xs text-muted-foreground max-w-[360px] truncate",children:U.description})]}),e.jsx(C,{className:"text-sm font-mono max-w-[200px] truncate",title:U.record??void 0,children:U.record||e.jsx("span",{className:"text-muted-foreground font-sans",children:"-"})}),e.jsx(C,{className:"text-sm font-mono whitespace-nowrap",children:U.ip_address||e.jsx("span",{className:"text-muted-foreground font-sans",children:"-"})}),e.jsx(C,{children:e.jsx(pn,{result:U.result})}),e.jsx(C,{children:e.jsx(u,{variant:"ghost",size:"icon",className:"h-7 w-7",t
6itle:"View details",onClick:re=>{re.stopPropagation(),O(U)},children:e.jsx(Fs,{className:"h-4 w-4"})})})]},U.id))})]})}),e.jsx(Vx,{entry:A,onOpenChange:U=>{U||O(null)}}),e.jsxs("div",{className:"flex flex-col gap-3 pt-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{htmlFor:"al-per-page",className:"text-xs text-muted-foreground whitespace-nowrap",children:"Rows per page"}),e.jsxs(ke,{value:String(t),onValueChange:U=>{n(Number(U)),s(1)},children:[e.jsx(Se,{id:"al-per-page",className:"h-8 w-[80px]",children:e.jsx(Ae,{})}),e.jsx(Pe,{children:Kx.map(U=>e.jsx(X,{value:String(U),children:U},U))})]})]}),y>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:a<=1,onClick:()=>s(U=>U-1),children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",a," of ",y]}),e.jsx(u,{variant:"outline",size:"sm",disabled:a>=y,onClick:()=>s(U=>U+1),children:"Next"})]})]})]})]})}function Wx(){return e.jsx(ye,{title:"Activity Log",subtitle:"Audit trail of admin and organization actions",link:"/admin-dashboard/activity-log",children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(Ht,{className:"h-6 w-6"}),"Activity Log"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Who did what, to which record, and whether it worked - every change made anywhere in the platform, plus sign-ins and the signup funnel. Only the action is recorded, never the data that was typed in."})]}),e.jsxs(Jc,{children:[e.jsx(Ci,{className:"h-4 w-4"}),e.jsx(Xc,{children:"Retention & backup"}),e.jsxs(Zc,{children:["The live log below only ever shows the last ",e.jsxs("strong",{children:[_a," days"]}),". Every night, entries older than that are automatically zipped into a dated archive and removed from this table - archives are never deleted automatically. Use"," ",e.jsx("strong",{children:"Export CSV"})," to download the current live log on demand, and check the"," ",e.jsx("strong",{children:"Archived Backups"})," section below to download older history. If you need to keep activity records for longer than ",_a," days, download the archives periodically and store your own copies."]})]}),e.jsx(Hx,{}),e.jsx(Ix,{})]})})}const Yx=He.injectEndpoints({endpoints:a=>({getMarketingMarqueeItems:a.query({query:s=>({url:`/admin/marketing-marquee-items?page=${(s==null?void 0:s.page)??1}`,method:"GET"}),providesTags:s=>s!=null&&s.data?[...s.data.map(t=>({type:"marketing-marquee-items",id:t.id})),{type:"marketing-marquee-items",id:"LIST"}]:[{type:"marketing-marquee-items",id:"LIST"}]}),createMarketingMarqueeItem:a.mutation({query:s=>({url:"/admin/marketing-marquee-items",method:"POST",body:s}),invalidatesTags:[{type:"marketing-marquee-items",id:"LIST"}]}),updateMarketingMarqueeItem:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-marquee-items/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"marketing-marquee-items",id:n},{type:"marketing-marquee-items",id:"LIST"}]}),deleteMarketingMarqueeItem:a.mutation({query:s=>({url:`/admin/marketing-marquee-items/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-marquee-items",id:"LIST"}]}),getMarketingTestimonials:a.query({query:s=>({url:`/admin/marketing-testimonials?page=${(s==null?void 0:s.page)??1}`,method:"GET"}),providesTags:s=>s!=null&&s.data?[...s.data.map(t=>({type:"marketing-testimonials",id:t.id})),{type:"marketing-testimonials",id:"LIST"}]:[{type:"marketing-testimonials",id:"LIST"}]}),createMarketingTestimonial:a.mutation({query:s=>({url:"/admin/marketing-testimonials",method:"POST",body:s}),invalidatesTags:[{type:"marketing-testimonials",id:"LIST"}]}),updateMarketingTestimonial:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-testimonials/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"marketing-testimonials",id:n},{type:"marketing-testimonials",id:"LIST"}]}),deleteMarketingTestimonial:a.mutation({query:s=>({url:`/admin/marketing-testimonials/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-testimonials",id:"LIST"}]}),getMarketingTrustedCompanies:a.query({query:s=>({url:`/admin/marketing-trusted-companies?page=${(s==null?void 0:s.page)??1}`,method:"GET"}),providesTags:s=>s!=null&&s.data?[...s.data.map(t=>
6({type:"marketing-trusted-companies",id:t.id})),{type:"marketing-trusted-companies",id:"LIST"}]:[{type:"marketing-trusted-companies",id:"LIST"}]}),createMarketingTrustedCompany:a.mutation({query:s=>({url:"/admin/marketing-trusted-companies",method:"POST",body:s}),invalidatesTags:[{type:"marketing-trusted-companies",id:"LIST"}]}),updateMarketingTrustedCompany:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-trusted-companies/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"marketing-trusted-companies",id:n},{type:"marketing-trusted-companies",id:"LIST"}]}),deleteMarketingTrustedCompany:a.mutation({query:s=>({url:`/admin/marketing-trusted-companies/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-trusted-companies",id:"LIST"}]}),getMarketingFaqs:a.query({query:s=>({url:`/admin/marketing-faqs?page=${(s==null?void 0:s.page)??1}`,method:"GET"}),providesTags:s=>s!=null&&s.data?[...s.data.map(t=>({type:"marketing-faqs",id:t.id})),{type:"marketing-faqs",id:"LIST"}]:[{type:"marketing-faqs",id:"LIST"}]}),createMarketingFaq:a.mutation({query:s=>({url:"/admin/marketing-faqs",method:"POST",body:s}),invalidatesTags:[{type:"marketing-faqs",id:"LIST"}]}),updateMarketingFaq:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-faqs/${s}`,method:"PUT",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"marketing-faqs",id:n},{type:"marketing-faqs",id:"LIST"}]}),deleteMarketingFaq:a.mutation({query:s=>({url:`/admin/marketing-faqs/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-faqs",id:"LIST"}]}),getMarketingPromoPopups:a.query({query:s=>({url:`/admin/marketing-promo-popups?page=${(s==null?void 0:s.page)??1}`,method:"GET"}),providesTags:s=>s!=null&&s.data?[...s.data.map(t=>({type:"marketing-promo-popup",id:t.id})),{type:"marketing-promo-popup",id:"LIST"}]:[{type:"marketing-promo-popup",id:"LIST"}]}),createMarketingPromoPopup:a.mutation({query:s=>({url:"/admin/marketing-promo-popups",method:"POST",body:s}),invalidatesTags:[{type:"marketing-promo-popup",id:"LIST"}]}),updateMarketingPromoPopup:a.mutation({query:({id:s,body:t})=>(t.has("_method")||t.append("_method","PUT"),{url:`/admin/marketing-promo-popups/${s}`,method:"POST",body:t}),invalidatesTags:(s,t,{id:n})=>[{type:"marketing-promo-popup",id:n},{type:"marketing-promo-popup",id:"LIST"}]}),deleteMarketingPromoPopup:a.mutation({query:s=>({url:`/admin/marketing-promo-popups/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-promo-popup",id:"LIST"}]}),getMarketingSettings:a.query({query:()=>({url:"/admin/marketing-settings",method:"GET"}),providesTags:[{type:"marketing-settings",id:"SINGLE"}]}),updateMarketingSettings:a.mutation({query:s=>({url:"/admin/marketing-settings",method:"PUT",body:s}),invalidatesTags:[{type:"marketing-settings",id:"SINGLE"}]})}),overrideExisting:!0}),{useGetMarketingMarqueeItemsQuery:Jx,useCreateMarketingMarqueeItemMutation:Xx,useUpdateMarketingMarqueeItemMutation:Zx,useDeleteMarketingMarqueeItemMutation:eh,useGetMarketingTestimonialsQuery:sh,useCreateMarketingTestimonialMutation:ah,useUpdateMarketingTestimonialMutation:th,useDeleteMarketingTestimonialMutation:nh,useGetMarketingTrustedCompaniesQuery:ih,useCreateMarketingTrustedCompanyMutation:rh,useUpdateMarketingTrustedCompanyMutation:lh,useDeleteMarketingTrustedCompanyMutation:ch,useGetMarketingFaqsQuery:oh,useCreateMarketingFaqMutation:dh,useUpdateMarketingFaqMutation:mh,useDeleteMarketingFaqMutation:uh,useGetMarketingPromoPopupsQuery:xh,useCreateMarketingPromoPopupMutation:hh,useUpdateMarketingPromoPopupMutation:ph,useDeleteMarketingPromoPopupMutation:gh,useGetMarketingSettingsQuery:jh,useUpdateMarketingSettingsMutation:fh}=Yx,si={message:"",sort_order:0,is_active:!0},ai={quote:"",author:"",role:"",company:"",image_url:"",sort_order:0,is_active:!0,site:"both"},ti={name:"",logo_url:"",sort_order:0,is_active:!0},ni={question:"",answer:"",category:"General",page_slug:"",sort_order:0,is_active:!0},vh=["ai-hr-software","hr-software-small-business","best-hr-software-uk","ats-software","sponsor-compliance-software","ai-recruitment-software","right-to-work-software","employee-management-software","cheap-hr-software-uk","hr-compliance-software","employee-management","right-to-work","access-control","document-management","job-posting","applicant-tracking","ai-interview","candidate-assessment","leave-management","rota-management","attendance-tracking","holiday-management","employee-corner","job-corner","sponsor-compliance","reports-analytics"],Os={badge_text:"",title:"",message:"",highlight_text:"",audience_text:"",cta_label:"",is_active:!1},ii=a=>{const s=(a||"").trim();if(!s)return"";if(/^https?:\/\//i.test(s))return s;if(s.startsWith("//"))return`https:${s}`;const n="http://localhost:8000/api".replace(/\/$/,"").replace(/\/api$/,"");return s.startsWith("/")?`${n}${s}`:`${n}/${s}`};function yh(){const{data:a,isLoading:s}=Jx({page:1}),{data:t,isLoading:n}=sh({page:1}),{data:i,isLoading:c}=ih({page:1}),{data:r,isLoading:o}=oh({page:1}),{data:l,isLoading:_}=xh({page:1}),{data:h,isLoading:N}=jh(),[g,{isLoading:b}]=fh(),P=(a==null?void 0:a.data)||[],z=(t==null?void 0:t.data)||[],p=(i==null?void 0:i.data)||[],M=(r==null?void 0:r.data)||[],A=(l==null?void 0:l.data)||[],[O]=Xx(),[k]=Zx(),[j]=eh(),[S]=ah(),[d]=th(),[L]=nh(),[I]=rh(),[B]=lh(),[y]=ch(),[F]=dh(),[K]=mh(),[q]=uh(),[U,{isLoading:re}]=hh(),[te,{isLoading:G}]=ph(),[w]=gh(),[Y,ue]=m.useState(!1),[J,ge]=m.useState(null),[he,me]=m.useState(si),[Z,ne]=m.useState(!1),[_e,qe]=m.useState(null),[fe,Qe]=m.useState(ai),[oe,Te]=m.useState(!1),[we,Ze]=m.useState(null),[f,ie]=m.useState(ti),[R,H
6]=m.useState(!1),[$,de]=m.useState(null),[xe,Me]=m.useState(ni),[be,We]=m.useState(Os),[Ls,Bs]=m.useState(null),[ua,Us]=m.useState(""),[vs,Ca]=m.useState(null),[$a,Hs]=m.useState(!1),[V,Ne]=m.useState(""),[os,ka]=m.useState(""),[Sa,Aa]=m.useState(""),[xa,jn]=m.useState(""),fn=re||G;m.useEffect(()=>{h!=null&&h.data&&(Ne(h.data.hero_video_url||""),ka(h.data.pricing_compare_eyebrow||""),Aa(h.data.pricing_compare_title||""),jn(h.data.pricing_compare_description||""))},[h]),m.useEffect(()=>{A.length>0||vs||(We(Os),Bs(null),Us(""))},[A.length,vs]);const or=()=>{ge(null),me(si),ue(!0)},dr=D=>{ge(D),me({message:D.message,sort_order:D.sort_order,is_active:D.is_active}),ue(!0)},mr=()=>{qe(null),Qe(ai),ne(!0)},ur=D=>{qe(D),Qe({quote:D.quote,author:D.author,role:D.role||"",company:D.company,image_url:D.image_url||"",sort_order:D.sort_order,is_active:D.is_active,site:D.site||"both"}),ne(!0)},xr=()=>{Ze(null),ie(ti),Te(!0)},hr=D=>{Ze(D),ie({name:D.name,logo_url:D.logo_url||"",sort_order:D.sort_order,is_active:D.is_active}),Te(!0)},pr=()=>{de(null),Me(ni),H(!0)},gr=D=>{de(D),Me({question:D.question,answer:D.answer,category:D.category||"General",page_slug:D.page_slug||"",sort_order:D.sort_order,is_active:D.is_active}),H(!0)},vn=()=>{Ca(null),We(Os),Bs(null),Us(""),Hs(!0)},jr=D=>{Ca(D.id),We({badge_text:D.badge_text||Os.badge_text,title:D.title||Os.title,message:D.message||Os.message,highlight_text:D.highlight_text||Os.highlight_text,audience_text:D.audience_text||Os.audience_text,cta_label:D.cta_label||Os.cta_label,is_active:D.is_active}),Bs(null),Us(ii(D.image_url)),Hs(!0)},fr=async D=>{try{await w(D).unwrap(),vs===D&&vn(),v.success("Promo popup deleted")}catch{v.error("Failed to delete promo popup")}},vr=async()=>{var D;if(!((D=he.message)!=null&&D.trim())){v.error("Message is required");return}try{J?(await k({id:J.id,body:he}).unwrap(),v.success("Marquee item updated")):(await O(he).unwrap(),v.success("Marquee item created")),ue(!1)}catch{v.error("Failed to save marquee item")}},yr=async()=>{var D,_s,Ws;if(!((D=fe.quote)!=null&&D.trim())||!((_s=fe.author)!=null&&_s.trim())||!((Ws=fe.company)!=null&&Ws.trim())){v.error("Quote, author, and company are required");return}try{_e?(await d({id:_e.id,body:fe}).unwrap(),v.success("Testimonial updated")):(await S(fe).unwrap(),v.success("Testimonial created")),ne(!1)}catch{v.error("Failed to save testimonial")}},Nr=async()=>{var D;if(!((D=f.name)!=null&&D.trim())){v.error("Company name is required");return}try{we?(await B({id:we.id,body:f}).unwrap(),v.success("Trusted company updated")):(await I(f).unwrap(),v.success("Trusted company created")),Te(!1)}catch{v.error("Failed to save trusted company")}},br=async()=>{var D,_s;if(!((D=xe.question)!=null&&D.trim())||!((_s=xe.answer)!=null&&_s.trim())){v.error("Question and answer are required");return}try{$?(await K({id:$.id,body:xe}).unwrap(),v.success("Marketing FAQ updated")):(await F(xe).unwrap(),v.success("Marketing FAQ created")),H(!1)}catch{v.error("Failed to save marketing FAQ")}},_r=async()=>{var D,_s,Ws;if(!vs&&!Ls){v.error("Please upload a popup image");return}if(!((D=be.title)!=null&&D.trim())||!((_s=be.message)!=null&&_s.trim())){v.error("Title and message are required");return}try{const ws=new FormData;Ls&&ws.append("image_file",Ls),ws.append("badge_text",(be.badge_text||"").trim()),ws.append("title",(be.title||"").trim()),ws.append("message",(be.message||"").trim()),ws.append("highlight_text",(be.highlight_text||"").trim()),ws.append("audience_text",(be.audience_text||"").trim()),ws.append("cta_label",(be.cta_label||"").trim()),ws.append("is_active",be.is_active?"1":"0");const Cr=vs?await te({id:vs,body:ws}).unwrap():await U(ws).unwrap();Bs(null),Us(ii(((Ws=Cr.data)==null?void 0:Ws.image_url)||ua)),vs?v.success("Marketing promo popup updated"):(v.success("Marketing promo popup created"),We(Os),Bs(null),Us("")),Hs(!1)}catch{v.error("Failed to save promo popup")}},wr=async()=>{const D=V.trim();try{await g({hero_video_url:D||null,pricing_compare_eyebrow:os.trim()||null,pricing_compare_title:Sa.trim()||null,pricing_compare_description:xa.trim()||null}).unwrap(),v.success("Marketing settings saved")}catch{v.error("Failed to save marketing settings")}};return e.jsxs(ye,{title:"Marketing Content",subtitle:"",link:"",children:[e.jsx("div",{className:"p-4",children:e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Marketing Website Content"}),e.jsx(je,{children:"Manage homepage marquee, testimonials, trusted companies, dedicated marketing FAQs, and popup campaigns."})]}),e.jsx(Q,{children:e.jsxs(Qs,{defaultValue:"marquee",children:[e.jsx("div",{className:"mb-4 overflow-x-auto pb-1",children:e.jsxs(Ks,{className:"inline-flex h-auto min-w-max gap-1",children:[e.jsx(Ye,{value:"marquee",className:"h-9 min-w-[120px]",children:"Marquee"}),e.jsx(Ye,{value:"testimonials",className:"h-9 min-w-[120px]",children:"Testimonials"}),e.jsx(Ye,{value:"trusted",className:"h-9 min-w-[150px]",children:"Trusted Companies"}),e.jsx(Ye,{value:"faqs",className:"h-9 min-w-[130px]",children:"Marketing FAQs"}),e.jsx(Ye,{value:"promo",className:"h-9 min-w-[145px]",children:"Promo Popup"}),e.jsx(Ye,{value:"settings",className:"h-9 min-w-[120px]",children:"Settings"})]})}),e.jsxs(Je,{value:"marquee",children:[e.jsx("div",{className:"mb-3 flex items-center justify-end",children:e.jsxs(u,{onClick:or,className:"w-full sm:w-auto",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add Marquee Item"]})}),s?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{className:"min-w-[680px]",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Message"}),e.jsx(T,{children:"Order"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:P.map(D=>e.jsxs(le,{children:[e.jsx(C,{children:D.message}),e.jsx(C,{children:D.sort_order}),e.jsx(C,{children:e.jsx(ee,{variant:D.is_active?"default":"outline",children:D.is_active?"Active":"Inactive"})}),e.jsxs(C,{children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>dr(D),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>j(D.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})]},D.id))})]})})]}),e.jsxs(Je,{value:"testimonials",children:[e.jsx("div",{className:"mb-3 flex items-center justify-end",children:e.jsxs(u,{onClick:mr,className:"w-full sm:w-auto",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add Testimonial"]})}),n?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{className:"min-w-[820px]",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Author"}),e.jsx(T,{children:"Company"}),e.jsx(T,{children:"Quote"}),e.jsx(T,{children:"Site"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:z.map(D=>e.jsxs(le,{children:[e.jsx(C,{children:D.author}),e.jsx(C,{children:D.company}),e.jsx(C,{className:"max-w-[300px] truncate",children:D.quote}),e.jsx(C,{children:e.jsx(ee,{variant:"outline",children:D.site==="both"?"Both":D.site==="marketing"?"Marketing":"Job Portal"})}),e.jsx(C,{children:e.jsx(ee,{variant:D.is_active?"default":"outline",children:D.is_active?"Active":"Inactive"})}),e.jsxs(C,{children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>ur(D),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>L(D.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})]},D.id))})]})})]}),e.jsxs(Je,{value:"trusted",children:[e.jsx("div",{className:"mb-3 flex items-center justify-end",children:e.jsxs(u,{onClick:xr,className:"w-full sm:w-auto",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add Company"]})}),c?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{className:"min-w-[720px]",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Name"}),e.jsx(T,{children:"Logo URL"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:p.map(D=>e.jsxs(le,{children:[e.jsx(C,{children:D.name}),e.jsx(C,{className:"max-w-[320px] truncate",children:D.logo_url||"-"}),e.jsx(C,{children:e.jsx(ee,{variant:D.is_active?"default":"outline",children:D.is_active?"Active":"Inactive"})}),e.jsxs(C,{children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>hr(D),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>y(D.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})]},D.id))})]})})]}),e.jsxs(Je,{value:"faqs",children:[e.jsx("div",{className:"mb-3 flex items-center justify-end",children:e.jsxs(u,{onClick:pr,className:"w-full sm:w-auto",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add Marketing FAQ"]})}),o?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs($e,{className:"min-w-[760px]",children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Question"}),e.jsx(T,{children:"Category"}),e.jsx(T,{children:"Page"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:M.map(D=>e.jsxs(le,{children:[e.jsx(C,{className:"max-w-[450px] truncate",children:D.question}),e.jsx(C,{children:D.category||"-"}),e.jsx(C,{children:D.page_slug?e.jsx(ee,{variant:"secondary",children:D.page_slug}):"-"}),e.jsx(C,{children:e.jsx(ee,{variant:D.is_active?"default":"outline",children:D.is_active?"Active":"Inactive"})}),e.jsxs(C,{children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>gr(D),children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>q(D.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})]},D.id))})]})})]}),e.jsx(Je,{value:"promo",className:"space-y-4",children:_?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsxs("div",{className:"grid gap-4",children:[e.jsx("div",{className:"mb-3 flex items-center justify-end",children:e.jsxs(u,{onClick:vn,className:"w-full sm:w-auto",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"}),"Add New Campaign"]})}),A.length>0?e.jsx("div",{className:"grid gap-3",children:A.map(D=>e.jsx("div",{className:`rounded-lg border p-3 ${vs===D.id?"border-primary":"border-slate-200"}`,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:D.title||"Untitled Campaign"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.badge_text||"No badge"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{variant:D.is_active?"default":"outline",children:D.is_active?"Active":"Inactive"}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>jr(D),children:"Edit"}),e.jsx(u,{size:"sm",variant:"ghost",onClick:()=>fr(D.id),children:e.jsx(Le,{className:"h-4 w-4 text-destructive"})})]})]})},D.id))}):e.jsx("div",{className:"rounded-lg border border-dashed p-4 text-sm text-muted-foreground",children:"No promo campaigns yet. Add your first one."})]})}),e.jsx(Je,{value:"settings",className:"space-y-4",children:N?e.jsx(ce,{className:"h-5 w-5 animate-spin"}):e.jsxs("div",{className:"max-w-lg space-y-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Marketing Video URL"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:'The video shown when visitors click "Watch Demo" on the marketing homepage. Supports YouTube embed URLs and direct video links.'}),e.jsx(E,{placeholder:"https://www.youtube.com/embed/...",value:V,onChange:D=>Ne(D.target.value)})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Pricing Compare Eyebrow"}),e.jsx(E,{placeholder:"Compare Plans",value:os,onChange:D=>ka(D.target.value)})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Pricing Compare Title"}),e.jsx(E,{placeholder:"Full feature comparison",value:Sa,onChange:D=>Aa(D.target.value)})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Pricing Compare Description"}),e.jsx(Ce,{rows:3,placeholder:"See exactly what's included in each plan. No surprises - just transparency.",value:xa,onChange:D=>jn(D.target.value)})]}),e.jsxs(u,{onClick:wr,disabled:b,children:[b?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save Settings"]})]})})]})})]})}),e.jsx(Fe,{open:Y,onOpenChange:ue,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:J?"Edit Marquee Item":"Add Marquee Item"}),e.jsx(Ge,{children:"Shown in the scrolling strip under hero section."})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(x,{children:"Message"}),e.jsx(E,{value:he.message,onChange:D=>me({...he,message:D.target.value})}),e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:he.sort_order??0,onChange:D=>me({...he,sort_order:Number(D.target.value)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{checked:!!he.is_active,onCheckedChange:D=>me({...he,is_active:D})}),e.jsx("span",{className:"text-sm",children:"Active"})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:vr,children:"Save"})})]})}),e.jsx(Fe,{open:Z,onOpenChange:ne,children:e.jsxs(ze,{className:"max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:_e?"Edit Testimonial":"Add Testimonial"}),e.jsx(Ge,{children:"Used in homepage testimonial carousel."})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(x,{children:"Quote"}),e.jsx(Ce,{rows:4,value:fe.quote,onChange:D=>Qe({...fe,quote:D.target.value})}),e.jsx(x,{children:"Author"}),e.jsx(E,{value:fe.author,onChange:D=>Qe({...fe,author:D.target.value})}),e.jsx(x,{children:"Role"}),e.jsx(E,{value:fe.role||"",onChange:D=>Qe({...fe,role:D.target.value})}),e.jsx(x,{children:"Company"}),e.jsx(E,{value:fe.company,onChange:D=>Qe({...fe,company:D.target.value})}),e.jsx(x,{children:"Image URL"}),e.jsx(E,{value:fe.image_url||"",onChange:D=>Qe({...fe,image_url:D.target.value})}),e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:fe.sort_order??0,onChange:D=>Qe({...fe,sort_order:Number(D.target.value)})}),e.jsx(x,{children:"Show On"}),e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
6ing-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",value:fe.site||"both",onChange:D=>Qe({...fe,site:D.target.value}),children:[e.jsx("option",{value:"both",children:"Both Sites"}),e.jsx("option",{value:"marketing",children:"Marketing Site Only"}),e.jsx("option",{value:"job_portal",children:"Job Portal Only"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{checked:!!fe.is_active,onCheckedChange:D=>Qe({...fe,is_active:D})}),e.jsx("span",{className:"text-sm",children:"Active"})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:yr,children:"Save"})})]})}),e.jsx(Fe,{open:oe,onOpenChange:Te,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:we?"Edit Trusted Company":"Add Trusted Company"}),e.jsx(Ge,{children:"Shown under Trusted by innovative companies worldwide."})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(x,{children:"Name"}),e.jsx(E,{value:f.name,onChange:D=>ie({...f,name:D.target.value})}),e.jsx(x,{children:"Logo URL"}),e.jsx(E,{value:f.logo_url||"",onChange:D=>ie({...f,logo_url:D.target.value})}),e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:f.sort_order??0,onChange:D=>ie({...f,sort_order:Number(D.target.value)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{checked:!!f.is_active,onCheckedChange:D=>ie({...f,is_active:D})}),e.jsx("span",{className:"text-sm",children:"Active"})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:Nr,children:"Save"})})]})}),e.jsx(Fe,{open:R,onOpenChange:H,children:e.jsxs(ze,{className:"max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:$?"Edit Marketing FAQ":"Add Marketing FAQ"}),e.jsx(Ge,{children:"This table is separate from organization support FAQs."})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(x,{children:"Question"}),e.jsx(E,{value:xe.question,onChange:D=>Me({...xe,question:D.target.value})}),e.jsx(x,{children:"Answer"}),e.jsx(Ce,{rows:4,value:xe.answer,onChange:D=>Me({...xe,answer:D.target.value})}),e.jsx(x,{children:"Category"}),e.jsx(E,{value:xe.category||"",onChange:D=>Me({...xe,category:D.target.value}),placeholder:"General"}),e.jsx(x,{children:"Page (optional)"}),e.jsx(E,{list:"marketing-page-slugs",value:xe.page_slug||"",onChange:D=>Me({...xe,page_slug:D.target.value}),placeholder:"e.g. ai-hr-software - leave blank to only use Category"}),e.jsx("datalist",{id:"marketing-page-slugs",children:vh.map(D=>e.jsx("option",{value:D},D))}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"If set, this FAQ shows only on that specific page instead of the shared Category. Pages with no page-specific FAQs fall back to Category, then to that page's own built-in defaults."}),e.jsx(x,{children:"Sort Order"}),e.jsx(E,{type:"number",value:xe.sort_order??0,onChange:D=>Me({...xe,sort_order:Number(D.target.value)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{checked:!!xe.is_active,onCheckedChange:D=>Me({...xe,is_active:D})}),e.jsx("span",{className:"text-sm",children:"Active"})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:br,children:"Save"})})]})}),e.jsx(Fe,{open:$a,onOpenChange:Hs,children:e.jsxs(ze,{className:"max-h-[90vh] overflow-y-auto sm:max-w-2xl",children:[e.jsxs(Ee,{children:[e.jsx(De,{children:vs?"Edit Promo Campaign":"Add Promo Campaign"}),e.jsx(Ge,{children:"Configure one campaign at a time. Active campaigns will appear in the marketing popup stack."})]}),e.jsxs("div",{className:"grid gap-3 py-2 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Badge Text"}),e.jsx(E,{value:be.badge_text||"",onChange:D=>We({...be,badge_text:D.target.value}),placeholder:"Winter Campaign"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Popup Title"}),e.jsx(E,{value:be.title||"",onChange:D=>We({...be,title:D.target.value}),placeholder:"Winter Sale Is Live"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Message"}),e.jsx(Ce,{rows:4,value:be.message||"",onChange:D=>We({...be,message:D.target.value}),placeholder:"Describe the offer details clearly."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Highlight Text"}),e.jsx(E,{value:be.highlight_text||"",onChange:D=>We({...be,highlight_text:D.target.value}),placeholder:"Up to 35% savings on annual plans"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Audience Text"}),e.jsx(E,{value:be.audience_text||"",onChange:D=>We({...be,audience_text:D.target.value}),placeholder:"For growing organizations"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Label Text"}),e.jsx(E,{value:be.cta_label||"",onChange:D=>We({...be,cta_label:D.target.value}),placeholder:"Limited Time"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Upload Popup Image"}),e.jsx(E,{type:"file",accept:"image/*",onChange:D=>{var Ws;const _s=((Ws=D.target.files)==null?void 0:Ws[0])||null;if(Bs(_s),_s){const ws=URL.createObjectURL(_s);Us(ws)}}}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload image only. Recommended: 730 x 260 px (approx. 3:1 ratio) for best display quality."})]}),ua?e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(x,{children:"Preview"}),e.jsx("div",{className:"overflow-hidden rounded-xl border bg-slate-50",children:e.jsx("img",{src:ua,alt:"Promo preview",className:"h-auto max-h-[260px] w-full object-contain"})})]}):null,e.jsxs("div",{className:"md:col-span-2 flex items-center gap-2 rounded-lg border p-3",children:[e.jsx(Ve,{checked:!!be.
6is_active,onCheckedChange:D=>We({...be,is_active:D})}),e.jsx("span",{className:"text-sm",children:"Is Active (show on marketing homepage)"})]})]}),e.jsxs(Re,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>Hs(!1),children:"Cancel"}),e.jsxs(u,{onClick:_r,disabled:fn,children:[fn?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):null,vs?"Update Campaign":"Create Campaign"]})]})]})})]})}const cr=He.injectEndpoints({endpoints:a=>({getPlatformComparisonMatrix:a.query({query:()=>({url:"/admin/marketing-platform-comparison-matrix",method:"GET"}),providesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),savePlatformComparisonMatrix:a.mutation({query:s=>({url:"/admin/marketing-platform-comparison-matrix",method:"PUT",data:s}),async onQueryStarted(s,{dispatch:t,queryFulfilled:n}){try{const{data:i}=await n;t(cr.util.updateQueryData("getPlatformComparisonMatrix",void 0,()=>i))}catch{}}}),createPlatformCompetitor:a.mutation({query:s=>({url:"/admin/marketing-platform-competitors",method:"POST",data:s}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),updatePlatformCompetitor:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-platform-competitors/${s}`,method:"PUT",data:t}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),deletePlatformCompetitor:a.mutation({query:s=>({url:`/admin/marketing-platform-competitors/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),createPlatformComparisonFeature:a.mutation({query:s=>({url:"/admin/marketing-platform-comparison-features",method:"POST",data:s}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),updatePlatformComparisonFeature:a.mutation({query:({id:s,body:t})=>({url:`/admin/marketing-platform-comparison-features/${s}`,method:"PUT",data:t}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]}),deletePlatformComparisonFeature:a.mutation({query:s=>({url:`/admin/marketing-platform-comparison-features/${s}`,method:"DELETE"}),invalidatesTags:[{type:"marketing-platform-comparison",id:"MATRIX"}]})})}),{useGetPlatformComparisonMatrixQuery:Nh,useSavePlatformComparisonMatrixMutation:bh,useCreatePlatformCompetitorMutation:_h,useUpdatePlatformCompetitorMutation:wh,useDeletePlatformCompetitorMutation:Ch,useCreatePlatformComparisonFeatureMutation:kh,useUpdatePlatformComparisonFeatureMutation:Sh,useDeletePlatformComparisonFeatureMutation:Ah}=cr,ri={name:"",tagline:"",is_primary:!1,sort_order:0,is_active:!0},li={name:"",value_type:"boolean",sort_order:0,is_active:!0};function ks(a){return a.value_type==="price"||a.name.toLowerCase().includes("starting price")}function gn(a){return["true","1","yes"].includes(a.trim().toLowerCase())?"true":"false"}function Ph(a){const s={},t=a.values;if(!t)return s;if(Array.isArray(t)){for(const n of t)n!=null&&n.competitor_id&&(s[n.competitor_id]=String(n.value??""));return s}if(typeof t=="object")for(const[n,i]of Object.entries(t))typeof i=="string"?s[n]=i:i&&typeof i=="object"&&"value"in i&&(s[n]=String(i.value??""));return s}function qt(a,s,t){const n={};for(const i of a){n[i.id]={};const c=Ph(i);for(const r of s){const o=c[r.id]??(ks(i)?"":"false");r.is_primary&&ks(i)?n[i.id][r.id]=t:ks(i)?n[i.id][r.id]=o:n[i.id][r.id]=gn(o)}}return n}function Th({value:a,onChange:s}){const t=gn(a)==="true";return e.jsxs("div",{className:"flex justify-center gap-1",children:[e.jsx(u,{type:"button",size:"icon",variant:t?"default":"outline",className:t?"h-8 w-8 bg-green-600 hover:bg-green-600":"h-8 w-8",onClick:()=>s("true"),"aria-label":"Yes",children:e.jsx(Ps,{className:"h-4 w-4"})}),e.jsx(u,{type:"button",size:"icon",variant:t?"outline":"default",className:"h-8 w-8",onClick:()=>s("false"),"aria-label":"No",children:e.jsx(st,{className:"h-4 w-4"})})]})}function Fh(a){return[...a].sort((s,t)=>{const n=ks(s)?1:0,i=ks(t)?1:0;return n!==i?n-i:(s.sort_order??0)-(t.sort_order??0)})}function zh(){var oe,Te,we,Ze;const{data:a,isLoading:s}=Nh(),[t,{isLoading:n}]=bh(),[i,{isLoading:c}]=_h(),[r,{isLoading:o}]=wh(),[l,{isLoading:_}]=Ch(),[h,{isLoading:N}]=kh(),[g,{isLoading:b}]=Sh(),[P,{isLoading:z}]=Ah(),[p,M]=m.useState({}),[A,O]=m.useState(null),[k,j]=m.useState(!1),[S,d]=m.useState(!1),[L,I]=m.useState(null),[B,y]=m.useState(null),[F,K]=m.useState(ri),[q,U]=m.useState(li),re=((oe=a==null?void 0:a.data)==null?void 0:oe.competitors)??[],te=Fh(((Te=a==null?void 0:a.data)==null?void 0:Te.features)??[]),G=((we=a==null?void 0:a.data)==null?void 0:we.sovohr_starting_price)??"",w=re.find(f=>f.is_primary),Y=m.useMemo(()=>`${re.map(f=>f.id).join(",")}|${te.map(f=>f.id).join(",")}`,[re,te]);m.useEffect(()=>{a!=null&&a.data&&M(qt(a.data.features,a.data.competitors,a.data.sovohr_starting_price??""))},[Y,(Ze=a==null?void 0:a.data)==null?void 0:Ze.sovohr_starting_price]);const ue=m.useMemo(()=>a!=null&&a.data?qt(a.data.features,a.data.competitors,a.data.sovohr_starting_price??""):{},[a]),J=m.useMemo(()=>JSON.stringify(p)!==JSON.stringify(ue),[p,ue]),ge=(f,ie,R)=>{M(H=>({...H,[f]:{...H[f]??{},[ie]:R}}))},he=async()=>{const f=te.flatMap(ie=>re.filter(R=>!(R.is_primary&&ks(ie))).map(R=>{var $;const H=(($=p[ie.id])==null?void 0:$[R.id])??(ks(ie)?"":"false");return{feature_id:ie.id,competitor_id:R.id,value:ks(ie)?H:gn(H)}}));try{const ie=await t({cells:f}).unwrap();M(qt(ie.data.features,ie.data.competitors,ie.data.sovohr_starting_price??"")),v.success("Platform comparison saved")}catch{v.error("Failed to save platform comparison")}},me=()=>{I(null),K(ri),j(!0)},Z=f=>{I(f),K({name:f.name,tagline:f.tagline||"",is_primary:f.is_primary,sort_order:f.sort_order,is_active:f.is_active}),j(!0)},ne=()=>{y(null),U(li),d(!0)},_e=f=>{y(f),U({name:f.name,value_type:f.value_type??"boolean",sort_order:f.sort_order,is_active:f.is_active}),d(!0)},qe=async()=>{var f;if(!((f=F.name)!=null&&f.trim())){v.error("Competitor name is required");return}try{L?(await r({id:L.id,body:F}).unwrap(),v.success("Competitor updated")):(await i(F).unwrap(),v.success("Competitor created")),j(!1)}catch{v.error("Failed to save competitor")}},fe=async()=>
6{if(A)try{A.type==="competitor"?(await l(A.id).unwrap(),v.success("Competitor deleted")):(await P(A.id).unwrap(),v.success("Feature deleted")),O(null)}catch{v.error(`Failed to delete ${A.type}`)}},Qe=async()=>{var f;if(!((f=q.name)!=null&&f.trim())){v.error("Feature name is required");return}try{B?(await g({id:B.id,body:q}).unwrap(),v.success("Feature updated")):(await h(q).unwrap(),v.success("Feature created")),d(!1)}catch{v.error("Failed to save feature")}};return s?e.jsx(W,{children:e.jsx(Q,{className:"py-12 flex items-center justify-center",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-primary"})})}):e.jsxs(e.Fragment,{children:[e.jsxs(W,{children:[e.jsxs(se,{className:"flex flex-row items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(ae,{children:"Platform Comparison"}),e.jsx(je,{children:"Feature rows use tick/cross. Only price rows use text. SovoHR price is auto from Micro (includes employee cap when set)."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",onClick:me,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Competitor"]}),e.jsxs(u,{variant:"outline",onClick:ne,children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Add Feature"]}),e.jsxs(u,{onClick:he,disabled:n||!J,children:[n?e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Save Changes"]})]})]}),e.jsxs(Q,{className:"space-y-6",children:[w&&G?e.jsxs("div",{className:"rounded-lg border bg-muted/30 px-4 py-3 text-sm",children:[e.jsx("span",{className:"font-medium",children:w.name})," starting price:"," ",e.jsx("span",{className:"text-primary font-semibold",children:G}),e.jsx("span",{className:"text-muted-foreground",children:" (auto from Micro plan)"})]}):null,e.jsx("div",{className:"overflow-x-auto border rounded-lg",children:e.jsxs("table",{className:"w-full min-w-[720px] text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"text-left p-3",children:"Feature"}),re.map(f=>e.jsxs("th",{className:"text-center p-3 min-w-[140px]",children:[e.jsx("div",{className:"font-medium",children:f.name}),f.is_primary?e.jsx(ee,{className:"mt-1",children:"SovoHR"}):null,f.is_primary?null:e.jsxs("div",{className:"flex justify-center gap-1 mt-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:()=>Z(f),children:e.jsx(ds,{className:"h-3.5 w-3.5"})}),e.jsx(u,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>O({type:"competitor",id:f.id,name:f.name}),disabled:_,children:e.jsx(Le,{className:"h-3.5 w-3.5"})})]})]},f.id))]})}),e.jsx("tbody",{children:te.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Math.max(re.length+1,1),className:"p-4 text-muted-foreground",children:"No comparison features yet."})}):te.map(f=>e.jsxs("tr",{className:"border-b",children:[e.jsxs("td",{className:"p-3 align-top",children:[e.jsx("div",{className:"font-medium",children:f.name}),e.jsx(ee,{variant:"outline",className:"mt-1",children:ks(f)?"Price":"Feature"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:()=>_e(f),children:e.jsx(ds,{className:"h-3.5 w-3.5"})}),e.jsx(u,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>O({type:"feature",id:f.id,name:f.name}),disabled:z,children:e.jsx(Le,{className:"h-3.5 w-3.5"})})]})]}),re.map(ie=>{var H;const R=((H=p[f.id])==null?void 0:H[ie.id])??(ks(f)?"":"false");return ie.is_primary&&ks(f)?e.jsx("td",{className:"p-3 text-center align-top",children:e.jsx("span",{className:"text-xs font-medium text-primary",children:G||R})},`${f.id}-${ie.id}`):ks(f)?e.jsx("td",{className:"p-3 text-center align-top",children:e.jsx(E,{value:R,onChange:$=>ge(f.id,ie.id,$.target.value),placeholder:"e.g. From £24/user/month",className:"h-8 text-xs"})},`${f.id}-${ie.id}`):e.jsx("td",{className:"p-3 text-center align-top",children:e.jsx(Th,{value:R,onChange:$=>ge(f.id,ie.id,$)})},`${f.id}-${ie.id}`)})]},f.id))})]})})]})]}),e.jsx(ss,{open:A!==null,onOpenChange:f=>!f&&O(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsxs(ns,{children:["Delete ",(A==null?void 0:A.type)==="competitor"?"competitor":"feature","?"]}),e.jsx(is,{children:(A==null?void 0:A.type)==="competitor"?`Remove "${A.name}" from the comparison table? This cannot be undone.`:`Remove "${A==null?void 0:A.name}" row from the comparison table? This cannot be undone.`})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:fe,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:_||z,children:"Delete"})]})]})}),e.jsx(Fe,{open:k,onOpenChange:j,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:L?"Edit Competitor":"Add Competitor"}),e.jsx(Ge,{children:"Competitor columns appear on the homepage comparison table."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Name"}),e.jsx(E,{value:F.name,onChange:f=>K(ie=>({...ie,name:f.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Tagline"}),e.jsx(E,{value:F.tagline||"",onChange:f=>K(ie=>({...ie,tagline:f.target.value}))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Active"}),e.jsx(Ve,{checked:F.is_active!==!1,onCheckedChange:f=>K(ie=>({...ie,is_active:f}))})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:qe,disabled:c||o,children:"Save"})})]})}),e.jsx(Fe,{open:S,onOpenChange:d,children:e.jsxs(ze,{children:[e.jsxs(Ee,{children:[e.jsx(De,{children:B?"Edit Feature":"Add Feature"}),e.jsx(Ge,{children:"Choose Feature for tick/cross rows, or Price for text pricing rows."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Name"}),e.jsx(E,{value:q.name,onChange:f=>U(ie=>({...ie,name:f.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Row Type"}),e.jsxs("select",{className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",value:q.value_type??"boolean",onChange:f=>U(ie=>({...ie,value_type:f.target.value})),children:[e.jsx("option",{value:"boolean",children:"Feature (tick / cross)"}),e.jsx("option",{value:"price",children:"Price (text input)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Active"}),e.jsx(Ve,{checked:q.is_active!==!1,onCheckedChange:f=>U(ie=>({...ie,is_active:f}))})]})]}),e.jsx(Re,{children:e.jsx(u,{onClick:Qe,disabled:N||b,children:"Save"})})]})})]})}function Eh(){return e.jsx(ye,{title:"Platform Comparison",subtitle:"",link:"",children:e.jsxs("div",{className:"p-4",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Platform Comparison"}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1 pb-4",children:"Manage the SovoHR vs competitors table on the marketing homepage."}),e.jsx(zh,{})]})})}function Dh(){return e.jsx(ye,{title:"Pricing Comparison",subtitle:"",link:"",children:e.jsxs("div",{className:"p-4",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Pricing Comparison"}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1 pb-4",children:"Manage plan feature comparison groups and package inclusion for the pricing page."}),e.jsx(Oi,{})]})})}function ci(a){const s=new FormData;
6return Object.entries(a).forEach(([t,n])=>{n!=null&&(n instanceof File?s.append(t,n):typeof n=="boolean"?s.append(t,n?"1":"0"):typeof n=="object"?s.append(t,JSON.stringify(n)):s.append(t,String(n)))}),s}const Lh=He.injectEndpoints({endpoints:a=>({getBlogPosts:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.search&&n.push(`search=${encodeURIComponent(s.search)}`),s!=null&&s.category&&n.push(`category=${encodeURIComponent(s.category)}`),(s==null?void 0:s.is_published)!==void 0&&n.push(`is_published=${s.is_published?"1":"0"}`),{url:`/admin/blog-posts?${n.join("&")}`,method:"GET"}},providesTags:["blog-posts"]}),getBlogPost:a.query({query:s=>({url:`/admin/blog-posts/${s}`,method:"GET"}),providesTags:["blog-posts"]}),createBlogPost:a.mutation({query:s=>({url:"/admin/blog-posts",method:"POST",body:ci(s)}),invalidatesTags:["blog-posts"]}),updateBlogPost:a.mutation({query:({id:s,body:t})=>{const n=ci(t);return n.append("_method","PUT"),{url:`/admin/blog-posts/${s}`,method:"POST",body:n}},invalidatesTags:["blog-posts"]}),deleteBlogPost:a.mutation({query:s=>({url:`/admin/blog-posts/${s}`,method:"DELETE"}),invalidatesTags:["blog-posts"]}),uploadBlogMedia:a.mutation({query:s=>{const t=new FormData;return t.append("file",s),{url:"/admin/blog-posts/upload-media",method:"POST",body:t}}})}),overrideExisting:!0}),{useGetBlogPostsQuery:Mh,useCreateBlogPostMutation:qh,useUpdateBlogPostMutation:Oh,useDeleteBlogPostMutation:Rh}=Lh,Ih=He.injectEndpoints({endpoints:a=>({getBlogComments:a.query({query:s=>{const n=[`page=${(s==null?void 0:s.page)??1}`];return s!=null&&s.blog_post_id&&n.push(`blog_post_id=${encodeURIComponent(s.blog_post_id)}`),s!=null&&s.search&&n.push(`search=${encodeURIComponent(s.search)}`),{url:`/admin/blog-comments?${n.join("&")}`,method:"GET"}},providesTags:["blog-comments"]}),updateBlogComment:a.mutation({query:({id:s,body:t})=>({url:`/admin/blog-comments/${s}`,method:"PUT",body:t}),invalidatesTags:["blog-comments"]}),deleteBlogComment:a.mutation({query:s=>({url:`/admin/blog-comments/${s}`,method:"DELETE"}),invalidatesTags:["blog-comments"]})}),overrideExisting:!0}),{useGetBlogCommentsQuery:$h,useUpdateBlogCommentMutation:Bh,useDeleteBlogCommentMutation:Uh}=Ih,Gh="https://api.sovohr.com/api".replace(/\/api$/,"")||"";function Ka(a){return a?a.startsWith("http")?a:`${Gh}${a}`:""}const oi=()=>({title:"",slug:"",description:"",author_name:"",author_role:"",category:"",tags:[],content:[],meta_title:"",meta_description:"",meta_keywords:[],is_published:!1,featured_image_file:null});function Vh(){const[a,s]=m.useState("list"),[t,n]=m.useState(null),[i,c]=m.useState(oi()),[r,o]=m.useState(""),[l,_]=m.useState(""),[h,N]=m.useState(null),[g,b]=m.useState(""),[P,z]=m.useState(""),{data:p,isLoading:M,refetch:A}=Mh({page:1}),{data:O}=$h({page:1}),[k,{isLoading:j}]=qh(),[S,{isLoading:d}]=Oh(),[L]=Rh(),[I]=Bh(),[B]=Uh(),y=m.useRef(null),F=m.useMemo(()=>{const w=fs("token");return{readonly:!1,height:420,toolbarButtonSize:"middle",buttons:["bold","italic","underline","|","ul","ol","|","h2","h3","h4","|","link","image","|","align","|","undo","redo","|","source"],uploader:{insertImageAsBase64URI:!1,url:"https://api.sovohr.com/api/admin/blog-posts/upload-media",format:"json",headers:w?{Authorization:`Bearer ${w}`}:{},imagesExtensions:["jpg","jpeg","png","webp","gif"],isSuccess:Y=>!!(Y!=null&&Y.url),getMessage:Y=>(Y==null?void 0:Y.message)||"",process:Y=>({files:Y!=null&&Y.url?[Ka(Y.url)]:[],path:Y!=null&&Y.url?Ka(Y.url):"",baseurl:"",error:Y!=null&&Y.url?0:1,msg:Y!=null&&Y.url?"":"Upload failed"})}}},[]),K=m.useMemo(()=>p?Array.isArray(p.data)?p.data:[]:[],[p]),q=m.useMemo(()=>O?Array.isArray(O.data)?O.data:[]:[],[O]),U=()=>{n(null),c(oi()),o(""),_(""),b(""),z(""),s("edit")},re=w=>{var ue,J,ge;n(w.id),c({...w,featured_image_file:null});let Y="";if(Array.isArray(w.content)&&w.content.length>0){const he=w.content.find(me=>me.section_type==="text");he?Y=((ue=he.content)==null?void 0:ue.html)||((ge=(J=he.content)==null?void 0:J.paragraphs)==null?void 0:ge.join(` 7`))||"":Y=w.content.map(me=>{var Z,ne,_e;return((Z=me.content)==null?void 0:Z.html)||((_e=(ne=me.content)==null?void 0:ne.paragraphs)==null?void 0:_e.join(` 8`))||""}).join(` 9`)}else typeof w.content=="string"&&(Y=w.content);o(Y),_(Ka(w.featured_image_url)),b((w.tags||[]).join(", ")),z((w.meta_keywords||[]).join(", ")),s("edit")},te=async()=>{var J,ge,he,me,Z;if(!i.title||!i.description||!i.author_name){v.error("Title, description, and author name are required.");return}const w=((J=y.current)==null?void 0:J.value)??r;if(!w||!w.replace(/<[^>]*>/g,"").trim()){v.error("Post content is required.");return}const Y=((ge=i.slug)==null?void 0:ge.trim())||i.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),ue={...i,slug:Y,meta_title:((he=i.meta_title)==null?void 0:he.trim())||i.title,meta_description:((me=i.meta_description)==null?void 0:me.trim())||i.description,tags:g.split(",").map(ne=>
9ne.trim()).filter(Boolean),meta_keywords:P.split(",").map(ne=>ne.trim()).filter(Boolean),featured_image_file:i.featured_image_file,content:[{id:"content-section",section_type:"text",title:"",content:{html:w},sort_order:0,is_active:!0}]};try{t?(await S({id:t,body:ue}).unwrap(),v.success("Blog post updated.")):(await k(ue).unwrap(),v.success("Blog post created.")),A(),s("list")}catch(ne){v.error(((Z=ne==null?void 0:ne.data)==null?void 0:Z.message)||"Failed to save blog post.")}},G=async()=>{if(h)try{await L(h).unwrap(),v.success("Blog post deleted."),N(null),A()}catch{v.error("Failed to delete blog post.")}};return a==="edit"?e.jsx(ye,{title:"",subtitle:"",children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(u,{variant:"ghost",onClick:()=>s("list"),children:[e.jsx(ct,{className:"w-4 h-4 mr-2"})," Back to list"]}),e.jsxs(u,{onClick:te,disabled:j||d,children:[j||d?e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ht,{className:"w-4 h-4 mr-2"}),"Save"]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(W,{children:[e.jsx(se,{children:e.jsx(ae,{children:"Post details"})}),e.jsxs(Q,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Featured image"}),e.jsx(E,{type:"file",accept:"image/*",onChange:w=>{var ue;const Y=((ue=w.target.files)==null?void 0:ue[0])||null;c({...i,featured_image_file:Y}),_(Y?URL.createObjectURL(Y):"")}}),l&&e.jsx("img",{src:l,alt:"Preview",className:"mt-2 h-40 max-w-xs object-cover rounded-md border"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Title"}),e.jsx(E,{value:i.title||"",onChange:w=>c({...i,title:w.target.value,slug:i.slug||w.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Slug"}),e.jsx(E,{value:i.slug||"",onChange:w=>c({...i,slug:w.target.value}),placeholder:"auto-generated if empty"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Author name"}),e.jsx(E,{value:i.author_name||"",onChange:w=>c({...i,author_name:w.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Author role"}),e.jsx(E,{value:i.author_role||"",onChange:w=>c({...i,author_role:w.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Description"}),e.jsx(Ce,{value:i.description||"",onChange:w=>c({...i,description:w.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Category"}),e.jsx(E,{value:i.category||"",onChange:w=>c({...i,category:w.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Tags (comma separated)"}),e.jsx(E,{value:g,onChange:w=>b(w.target.value)})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ve,{checked:!!i.is_published,onCheckedChange:w=>c({...i,is_published:w})}),e.jsx(x,{children:"Published"})]})]})]}),e.jsxs(W,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Content"}),e.jsx(je,{children:"Write your post content using the rich editor below."})]}),e.jsx(Q,{children:e.jsx("div",{className:"space-y-2",children:e.jsx(ao,{ref:y,value:r,config:F,onBlur:w=>o(w),onChange:w=>o(w)})})})]}),e.jsxs(W,{children:[e.jsx(se,{children:e.jsx(ae,{children:"SEO"})}),e.jsxs(Q,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Meta title"}),e.jsx(E,{value:i.meta_title||"",onChange:w=>c({...i,meta_title:w.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Meta description"}),e.jsx(Ce,{value:i.meta_description||"",onChange:w=>c({...i,meta_description:w.target.value})})]}),e.jsxs("div",{children:[e.jsx(x,{children:"Meta keywords (comma separated)"}),e.jsx(E,{value:P,onChange:w=>z(w.target.value)})]})]})]})]})})]})}):e.jsx(ye,{title:"Blog Posts",subtitle:"Manage marketing blog articles and moderate comments",children:e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create, edit, and publish articles for the marketing site."}),e.jsxs(u,{onClick:U,children:[e.jsx(Ie,{className:"w-4 h-4 mr-2"})," New Post"]})]}),e.jsxs(Qs,{defaultValue:"posts",children:[e.jsxs(Ks,{children:[e.jsx(Ye,{value:"posts",children:"Posts"}),e.jsx(Ye,{value:"comments",children:"Comments"})]}),e.jsx(Je,{value:"posts",children:e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:M?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Image"}),e.jsx(T,{children:"Title"}),e.jsx(T,{children:"Category"}),e.jsx(T,{children:"Status"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:K.map(w=>e.jsxs(le,{children:[e.jsx(C,{children:w.featured_image_url?e.jsx("img",{src:Ka(w.featured_image_url),alt:"",className:"h-10 w-16 object-cover rounded"}):"-"}),e.jsx(C,{className:"font-medium",children:w.title}
9),e.jsx(C,{children:w.category||"-"}),e.jsx(C,{children:e.jsx(ee,{variant:w.is_published?"default":"secondary",children:w.is_published?"Published":"Draft"})}),e.jsxs(C,{className:"space-x-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:()=>re(w),children:e.jsx(Fs,{className:"w-4 h-4"})}),e.jsx(u,{size:"sm",variant:"destructive",onClick:()=>N(w.id),children:e.jsx(Le,{className:"w-4 h-4"})})]})]},w.id))})]})})})}),e.jsx(Je,{value:"comments",children:e.jsx(W,{children:e.jsx(Q,{className:"pt-6",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:"Post"}),e.jsx(T,{children:"Author"}),e.jsx(T,{children:"Comment"}),e.jsx(T,{children:"Visible"}),e.jsx(T,{children:"Actions"})]})}),e.jsx(Ue,{children:q.map(w=>{var Y,ue;return e.jsxs(le,{children:[e.jsx(C,{children:((Y=w.blog_post)==null?void 0:Y.title)||w.blog_post_id}),e.jsx(C,{children:((ue=w.user)==null?void 0:ue.name)||w.display_name||"Anonymous"}),e.jsx(C,{className:"max-w-xs truncate",children:w.body}),e.jsx(C,{children:w.is_visible?"Yes":"Hidden"}),e.jsxs(C,{className:"space-x-2",children:[e.jsx(u,{size:"sm",variant:"outline",onClick:async()=>{await I({id:w.id,body:{is_visible:!w.is_visible}}).unwrap(),v.success("Comment updated.")},children:w.is_visible?"Hide":"Show"}),e.jsx(u,{size:"sm",variant:"destructive",onClick:async()=>{await B(w.id).unwrap(),v.success("Comment deleted.")},children:e.jsx(Le,{className:"w-4 h-4"})})]})]},w.id)})})]})})})})]}),e.jsx(ss,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(as,{children:[e.jsxs(ts,{children:[e.jsx(ns,{children:"Delete blog post?"}),e.jsx(is,{children:"This action cannot be undone."})]}),e.jsxs(rs,{children:[e.jsx(ls,{children:"Cancel"}),e.jsx(cs,{onClick:G,children:"Delete"})]})]})})]})})}function Qh(){var O;const{t:a}=Xt("global"),[s,t]=m.useState(1),[n,i]=m.useState(""),[c,r]=m.useState(!1),[o,l]=m.useState(null),{data:_,isLoading:h,isFetching:N,refetch:g}=to({page:s,term:n}),[b,{isLoading:P}]=no(),z=(_==null?void 0:_.data)||[],p=((O=_==null?void 0:_.meta)==null?void 0:O.last_page)||1,M=k=>{l(k),r(!0)},A=async k=>{if(window.confirm(a("socCodes.confirmDelete","Are you sure you want to delete this SOC code?")))try{await b({id:k}).unwrap(),v.success(a("socCodes.deleted","SOC code deleted")),g()}catch{v.error(a("socCodes.deleteFailed","Failed to delete SOC code"))}};return e.jsx(ye,{title:a("socCodes.title","SOC Codes"),subtitle:"",link:"/admin-dashboard/settings/soc-codes",children:e.jsxs("div",{className:"p-4",children:[e.jsxs(W,{className:"shadow-xl rounded-2xl border border-muted",children:[e.jsxs(se,{className:"pb-4 flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx(ae,{className:"text-2xl font-semibold text-primary",children:a("socCodes.title","SOC Codes")}),e.jsx(E,{className:"w-full sm:w-72",placeholder:a("socCodes.searchPlaceholder","Search SOC codes..."),value:n,onChange:k=>{i(k.target.value),t(1)}})]}),e.jsx(u,{onClick:()=>{l(null),r(!0)},className:"self-start sm:self-auto",children:a("socCodes.addButton","Add SOC Code")})]}),e.jsx(Q,{className:"overflow-x-auto max-h-[60vh]",children:e.jsxs($e,{children:[e.jsx(Be,{children:e.jsxs(le,{children:[e.jsx(T,{children:a("socCodes.code","Code")}),e.jsx(T,{children:a("socCodes.name","Name")}),e.jsx(T,{children:a("socCodes.descriptionLabel","Description")}),e.jsx(T,{children:a("socCodes.actions","Actions")})]})}),e.jsx(Ue,{children:(h||N)&&z.length===0?Array.from({length:5}).map((k,j)=>e.jsxs(le,{children:[e.jsx(C,{children:e.jsx("div",{className:"h-4 w-20 rounded bg-muted"})}),e.jsx(C,{children:e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})}),e.jsx(C,{children:e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})}),e.jsx(C,{children:e.jsx("div",{className:"h-4 w-40 rounded bg-muted"})})]},j)):z.length>0?z.map(k=>{var j;return e.jsxs(le,{children:[e.jsx(C,{className:"font-mono",children:k.code}),e.jsx(C,{children:k.name}),e.jsx(C,{className:"max-w-[420px] truncate",title:k.description||"",children:((j=k.description)==null?void 0:j.trim())||"-"}),e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"ghost",size:"icon","aria-label":"Edit SOC Code",onClick:()=>M(k),children:[e.jsx("span",{className:"sr-only",children:a("socCodes.edit","Edit")}),e.jsx("span",{className:"text-primary",children:"â"})]}),e.jsxs(u,{variant:"ghost",size:"icon","aria-label":"Delete SOC Code",onClick:()=>A(k.id),disabled:P,children:[e.jsx("span",{className:"sr-only",children:a("socCodes.delete","Delete")}),e.jsx("span",{className:"text-destructive",children:"ðï¸"})]})]})]},k.id)}):e.jsx(le,{children:e.jsx(C,{colSpan:4,className:"text-center p-20 text-muted-foreground",children:a("socCodes.noData","No SOC codes found. Add one to get started.")})})})]})})]}),p>1&&e.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:s===1,onClick:()=>t(k=>Math.max(k-1,1)),children:a("pagination.previous","Previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a("pagination.pageOf","Page {{page}} of {{total}}",{page:s,total:p})}),e.jsx(u,{variant:"outline",size:"sm",disabled:s===p,onClick:()=>t(k=>Math.min(k+1,p)),children:a("pagination.next","Next")})]}),e.jsx(io,{open:c,onOpenChange:k=>{r(k),k||l(null)},socCode:o,onSaved:()=>{r(!1),l(null),g()}})]})})}const Yh=()=>(m.useEffect(()=>{document.title="SovoHR Admin Dashboard"},[]),e.jsxs(Ir,{children:[e.jsxs(ve,{path:"/",element:e.jsx(ho,{}),children:[e.jsx(ve,{index:!0,element:e.jsx(id,{})}),e.jsx(ve,{path:"profile",element:e.jsx(rx,{})}),e.jsxs(ve,{path:"users",children:[e.jsx(ve,{index:!0,element:e.jsx(Gu,{})}),e.jsx(ve,{path:"add",element:e.jsx(Qu,{})}),e.jsx(ve,{path:"reset-password",element:e.jsx(cx,{})})]}),e.jsx(ve,{path:"activity-log",element:e.jsx(Wx,{})}),e.jsx(ve,{path:"access-control",children:e.jsx(ve,{path:"roles",element:e.jsx(ax,{})})}),e.jsxs(ve,{path:"organizations",children:[e.jsx(ve,{index:!0,element:e.jsx(xd,{})}),e.jsx(ve,{path:"add",element:e.jsx(_d,{})}),e.jsx(ve,{path:"pending-deletions",element:e.jsx(lx,{})}),e.jsx(ve,{path:"cancel-subscription",element:e.jsx(wd,{})})]}),e.jsx(ve,{path:"subscription",element:e.jsx(Od,{})}),e.jsx(ve,{path:"coupons",element:e.jsx(Rd,{})}),e.jsx(ve,{path:"coupons/:couponId/redemptions",element:e.jsx(Id,{})}),e.jsxs(ve,{path:"licenses",children:[e.jsx(ve,{index:!0,element:e.jsx(Bd,{})}),e.jsx(ve,{path:"expired",element:e.jsx(Ud,{})}),e.jsx(ve,{path:"revenue",element:e.jsx(Kn,{})}),e.jsx(ve,{path:":licenseId",element:e.jsx(Gd,{})})]}),e.jsxs(ve,{path:"reports",children:[e.jsx(ve,{path:"organizations",element:e.jsx(Wd,{})}),e.jsx(ve,{path:"revenue",element:e.jsx(Kn,{})})]}),e.jsxs(ve,{path:"settings",children:[e.jsx(ve,{path:"configurations",element:e.jsx(xm,{})}),e.jsx(ve,{path:"change-password",element:e.jsx(ro,{})}),e.jsx(ve,{path:"site-pages",element:e.jsx(Jm,{})}),e.jsx(ve,{path:"marketing-content",element:e.jsx(yh,{})}),e.jsx(ve,{path:"platform-comparison",element:e.jsx(Eh,{})}),e.jsx(ve,{path:"pricing-comparison",element:e.jsx(Dh,{})}),e.jsx(ve,{path:"blog-posts",element:e.jsx(Vh,{})}),e.jsx(ve,{path:"soc-codes",element:e.jsx(Qh,{})}),e.jsx(ve,{path:"email-logs",element:e.jsx(jx,{})}),e.jsx(ve,{path:"system-backup",element:e.jsx(Dx,{})})]}),e.jsx(ve,{path:"support",element:e.jsx(Zm,{})}),e.jsx(ve,{path:"support/video-tutorials",element:e.jsx(iu,{})}),e.jsx(ve,{path:"support/faqs",element:e.jsx(mu,{})}),e.jsx(ve,{path:"recruitment",element:e.jsx(mx,{})}),e.jsx(ve,{path:"contact-submissions",element:e.jsx(hu,{})}),e.jsx(ve,{path:"customer-feedback",element:e.jsx(Mu,{})}),e.jsx(ve,{path:"lead-submissions",element:e.jsx(Uu,{})})]}),e.jsx(ve,{path:"*",element:e.jsx($r,{})})]}));export{Yh as AdminSection};
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.