PageSourceSearch

https://chat.aidx.ai/_next/static/chunks/pages/agency/[slug]-7efc9b1a51e1b12d.js

js aidx.ai collected 2026-10-05 11:50:46 UTC 40,368 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1775],{59872:(e,t,s)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/agency/[slug]",function(){return s(60499)}])},60499:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>I});var a=s(37876),i=s(14232),l=s(89099),n=s(42254),r=s(9625),c=s(93494),o=s(11041),d=s(66036),m=s(35891);let x=e=>{let{analytics:t,onClick:s}=e,i=(()=>{let e=(t.companies||[]).filter(e=>"company"===e.type),s=e.length;if(0===s)return{high:0,medium:0,low:0,total:0,averageEngagement:0,worstCompany:null,worstEngagement:0};let a=e.filter(e=>e.analytics.engagementRate>=2).length,i=e.filter(e=>e.analytics.engagementRate>=1&&e.analytics.engagementRate<2).length,l=e.filter(e=>e.analytics.engagementRate<1).length,n=e.reduce((e,t)=>e+t.analytics.engagementRate,0)/s,r=[...e].sort((e,t)=>e.analytics.engagementRate-t.analytics.engagementRate)[0];return{high:a,medium:i,low:l,total:s,averageEngagement:n,worstCompany:r,worstEngagement:(null==r?void 0:r.analytics.engagementRate)||0}})();return(0,a.jsxs)(m.A,{title:"Engagement Breakdown",emoji:"\uD83D\uDCCA",value:0===i.total?"No Data":i.low>0?"".concat(i.low," Low"):i.medium>0?"".concat(i.medium," Medium"):"Fully Engaged",description:"",statusLevel:0===i.total?"gray":i.low>0?"red":i.medium>0?"yellow":"green",onClick:s,tooltip:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"What this measures:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:["Engagement Breakdown shows the distribution of client companies across engagement levels. Uses the same ",(0,a.jsx)("span",{className:"text-white font-medium",children:"Weekly Engagement Rate"})," calculation as individual dashboards."]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Company Distribution:"}),(0,a.jsxs)("div",{className:"text-gray-300 space-y-1",children:[(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{children:"\uD83D\uDFE2 High Engagement (≥2.0):"}),(0,a.jsxs)("span",{className:"text-green-400 font-medium",children:[i.high," companies"]})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{children:"\uD83D\uDFE1 Medium Engagement (1.0-2.0):"}),(0,a.jsxs)("span",{className:"text-yellow-400 font-medium",children:[i.medium," companies"]})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{children:"\uD83D\uDD34 Low Engagement (<1.0):"}),(0,a.jsxs)("span",{className:"text-red-400 font-medium",children:[i.low," companies"]})]})]})]}),i.worstCompany&&(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Attention Needed:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsx)("span",{className:"text-red-400 font-medium",children:i.worstCompany.name})," has lowest engagement at ",(0,a.jsxs)("span",{className:"text-white",children:[i.worstEngagement.toFixed(1)," sessions/week"]})]})]})]}),children:[(0,a.jsx)("p",{className:"text-xs font-medium leading-tight mb-3 ".concat(i.low>0?"text-red-400":i.medium>0?"text-yellow-400":"text-green-400"),children:(()=>{if(0===i.total)return"No companies configured";if(i.low>0){let e=1===i.low?"company needs":"companies need";return"".concat(i.low," ").concat(e," engagement support")}if(i.medium>0){let e=1===i.medium?"company at":"companies at";return"".concat(i.medium," ").concat(e," moderate engagement - opportunity to improve")}return"Excellent engagement across all companies"})()}),i.total>0&&(0,a.jsx)("div",{className:"pt-3 border-t border-white/10",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Average Engagement:"}),(0,a.jsxs)("span",{className:"text-sm font-medium text-white",children:[i.averageEngagement.toFixed(1)," sessions/week"]})]})})]})},h=e=>{let{analytics:t,onClick:s}=e,i=(()=>{var e,s,a;let i=(null==(e=t.aggregatedMetrics)?void 0:e.totalRiskUsers)||0,l=(null==(s=t.companies)?void 0:s.reduce((e,t)=>
1e+(t.analytics.riskUsers||0),0))||0,n={critical:Math.floor(.6*l),moderate:Math.floor(.4*l)};return{totalUsers:i,critical:n.critical,moderate:n.moderate,companiesAffected:(null==(a=t.companies)?void 0:a.filter(e=>e.analytics.riskUsers>0).length)||0}})();return(0,a.jsxs)(m.A,{title:"Immediate Attention",emoji:"⚠️",value:i.totalUsers,description:"",statusLevel:i.critical>0?"red":i.moderate>0?"yellow":"green",onClick:s,tooltip:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"What this measures:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:["Immediate Attention aggregates users across all client companies who show",(0,a.jsx)("span",{className:"text-white font-medium",children:" high burnout risk, low confidence, poor work satisfaction, low team belonging, poor emotional wellbeing, poor work-life balance, or high stress"}),"."]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Current Status:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsxs)("div",{className:"mb-2",children:[(0,a.jsxs)("span",{className:"text-white font-medium",children:[i.totalUsers," users"]})," flagged across",(0,a.jsxs)("span",{className:"text-white font-medium",children:[" ",i.companiesAffected," companies"]})]}),i.totalUsers>0&&(0,a.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{children:"\uD83D\uDD34 Critical Risk:"}),(0,a.jsxs)("span",{className:"text-red-400 font-medium",children:[i.critical," users"]})]}),(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsx)("span",{children:"\uD83D\uDFE1 Moderate Risk:"}),(0,a.jsxs)("span",{className:"text-yellow-400 font-medium",children:[i.moderate," users"]})]})]})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Action Required:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[i.critical>0&&"Immediate coach intervention recommended for critical cases.",0===i.critical&&i.moderate>0&&"Monitor moderate cases and check in with assigned coaches.",0===i.totalUsers&&"Continue regular monitoring and preventive care."]})]})]}),children:[(0,a.jsx)("p",{className:"text-xs font-medium leading-tight mb-3 ".concat(i.critical>0?"text-red-400":i.moderate>0?"text-yellow-400":"text-green-400"),children:0===i.totalUsers?"No users requiring immediate intervention":i.critical>0?"".concat(i.critical," users need critical intervention"):i.moderate>0?"".concat(i.moderate," users need moderate intervention"):"All users stable"}),i.totalUsers>0&&(0,a.jsxs)("div",{className:"pt-3 border-t border-white/10",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Companies Affected:"}),(0,a.jsx)("span",{className:"text-sm font-medium text-white",children:i.companiesAffected})]}),i.critical>0&&(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Critical Cases:"}),(0,a.jsx)("span",{className:"text-sm font-medium text-red-400",children:i.critical})]})]})]})},g=e=>{let{analytics:t,onClick:s}=e,i=t.aggregatedMetrics,l=(null==i?void 0:i.overallHealthScore)||0,n=null==i?void 0:i.worstPerformingCompany;return(0,a.jsxs)(m.A,{title:"Overall Company Health",emoji:"\uD83C\uDFE5",value:"".concat(l.toFixed(0),"%"),trendDirection:l>=80?"↑":l<=60?"↓":"→",trendValue:Math.abs(5.2).toFixed(1),trendLabel:"vs last week",description:"",statusLevel:l>=80?"green":l>=60?"yellow":l>=40?"orange":"red",onClick:s,tooltip:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"What this measures:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:["Overall Company Health is a weighted composite score combining",(0,a.jsx)("span",{className:"text-white font-medium",children:" multiple metrics including wellbeing, engagement, confidence, and burnout risk"}),"across all client companies. Each metric is weighted by importance, with critical factors like burnout risk given higher priority."]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Current Assessment:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsxs)("div",{className:"mb-2",children:["Agency-wide health score: ",(0,a.jsxs)("span",{className:"text-white font-medium",children:[l.toFixed(1),"/100"]})]}),(0,a.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,a.jsxs)("div",{children:["Total users monitored: ",(0,a.jsx)("span",{className:"text-white",children:(null==i?void 0:i.totalUsers)||0})]}),(0,a.jsxs)("div",{children:["Average engagement: ",(0,a.jsxs)("span",{className:"text-white",children:[((null==i?void 0:i.averageEngagement)||0).toFixed(1)," sessions/week"]})]}),(0,a.jsxs)("div",{children:["Average burnout risk: ",(0,a.jsxs)("span",{className:"text-white",children:[((null==i?void 0:i.averageBurnoutRisk)||0).toFixed(1),"%"]})]})]})]})]}),n&&(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Attention Required:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsx)("span",{className:"text-red-400 font-medium",children:n.name})," shows lowest health at ",(0,a.jsxs)("span",{className:"text-white",children:[n.healthScore.toFixed(1),"/100"]})," - prioritize for intervention"]})]})]}),children:[(0,a.jsx)("p",{className:"text-xs font-medium leading-tight mb-3 ".concat(l>=80?"text-green-400":l>=60?"text-yellow-400":l>=40?"text-orange-400":"text-red-400"),children:l>=80?"Excellent overall health across companies":l>=60?"Good health with some areas for improvement":l>=40?"Moderate health - attention needed":"Poor health - immediate intervention required"}),n&&(0,a.jsx)("div",{className:"pt-3 border-t border-white/10",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Worst Performer:"}),(0,a.jsxs)("span",{className:"text-sm font-medium text-red-400",children:[n.name," 
1(",n.healthScore.toFixed(0),")"]})]})})]})},u=e=>{var t,s;let{analytics:i,onClick:l}=e,n=(null==(t=i.aggregatedMetrics)?void 0:t.totalStalledUsers)||0,r=(null==(s=i.companies)?void 0:s.filter(e=>e.analytics.stalledUsers>0).length)||0,c=i.companies?i.companies.filter(e=>e.analytics.stalledUsers>0).sort((e,t)=>t.analytics.stalledUsers-e.analytics.stalledUsers)[0]:null;return(0,a.jsxs)(m.A,{title:"Stalemate Watch",emoji:"⏸️",value:n,description:"",statusLevel:0===n?"green":n<=3?"yellow":"red",onClick:l,tooltip:(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"What this measures:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:["Stalemate Watch identifies users across all client companies who have shown",(0,a.jsx)("span",{className:"text-white font-medium",children:" no progress and low engagement for 2+ weeks"}),". These users may need renewed intervention or different coaching approaches."]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Cross-Company Overview:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsxs)("div",{className:"mb-2",children:[(0,a.jsxs)("span",{className:"text-white font-medium",children:[n," users"]})," are currently stalled across ",(0,a.jsxs)("span",{className:"text-white font-medium",children:[r," companies"]})]}),i.companies&&i.companies.length>0&&(0,a.jsx)("div",{className:"space-y-1 text-sm",children:i.companies.filter(e=>e.analytics.stalledUsers>0).sort((e,t)=>t.analytics.stalledUsers-e.analytics.stalledUsers).slice(0,3).map(e=>(0,a.jsxs)("div",{className:"flex justify-between",children:[(0,a.jsxs)("span",{children:[e.name,":"]}),(0,a.jsxs)("span",{className:"text-orange-400 font-medium",children:[e.analytics.stalledUsers," users"]})]},e.organizationId))})]})]}),c&&(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Priority Focus:"}),(0,a.jsxs)("div",{className:"text-gray-300",children:[(0,a.jsx)("span",{className:"text-orange-400 font-medium",children:c.name})," has the most stalled users (",c.analytics.stalledUsers,") - coordinate with assigned coaches"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-semibold text-white mb-1",children:"Coach Action:"}),(0,a.jsx)("div",{className:"text-gray-300",children:"Review coach assignments and engagement strategies for stalled users. Consider reassigning or providing additional coaching support."})]})]}),children:[(0,a.jsx)("p",{className:"text-xs font-medium leading-tight mb-3 ".concat(0===n?"text-green-400":n<=3?"text-yellow-400":"text-red-400"),children:0===n?"No stalled users across all companies":1===r?"Users stalled in ".concat(r," company"):"Users stalled across ".concat(r," companies")}),n>0&&(0,a.jsxs)("div",{className:"pt-3 border-t border-white/10",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Companies Affected:"}),(0,a.jsx)("span",{className:"text-sm font-medium text-white",children:r})]}),c&&(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Most Affected:"}),(0,a.jsxs)("span",{className:"text-sm font-medium text-orange-400",children:[c.name," (",c.analytics.stalledUsers,")"]})]})]})]})};var p=s(3573),v=s(60108),j=s(11457);let y=e=>{let{agencySlug:t}=e;(0,l.useRouter)();let{fetchWithAuth:s}=(0,v.A)(),[n,r]=(0,i.useState)("all"),[c,o]=(0,i.useState)("all"),[d,m]=(0,i.useState)("all"),[x,h]=(0,i.useState)([]),[g,u]=(0,i.useState)([]),[y,b]=(0,i.useState)(!0),[f,N]=(0,i.useState)(),[w,C]=(0,i.useState)(new Set);(0,i.useEffect)(()=>{let e=async()=>{try{b(!0);let e=await s("/api/organizations/".concat(t,"/agency/users"));if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to load agency users")}let a=await e.json();h(a.users||[]),u(a.practitioners||[])}catch(e){N(e instanceof Error?e.message:"Failed to load agency users"),console.error("Error loading agency users:",e)}finally{b(!1)}};t&&e()},[t,s]);let k=async(e,a)=>{try{C(t=>new Set(t).add(e));let i=x.map(t=>{if(t.userId===e){let e=g.find(e=>e.id===parseInt(a));return{...t,assignedPractitionerId:a?parseInt(a):void 0,assignedPractitioner:(null==e?void 0:e.handle)||void 0}}return t});h(i);let l=await s("/api/organizations/".concat(t,"/agency/users/").concat(e,"/assign"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({practitionerId:a||null})});if(!l.ok){let e=await l.json();throw Error(e.error||"Failed to assign practitioner")}let n=await l.json();h(t=>t.map(t=>{if(t.userId===e){var s,a;return{...t,assignedPractitionerId:(null==(s=n.assignedPractitioner)?void 0:s.id)||void 0,assignedPractitioner:(null==(a=n.assignedPractitioner)?void 0:a.handle)||void 0}}return t}))}catch(e){console.error("Error assigning practitioner:",e),h(x),alert(e instanceof Error?e.message:"Failed to assign practitioner")}finally{C(t=>{let s=new Set(t);return s.delete(e),s})}},S=[{value:"all",label:"All Companies"},...Array.from(new Set(x.filter(e=>"company"===e.companyType).map(e=>({id:e.companyId,name:e.companyName})).map(e=>JSON.stringify(e)))).map(e=>JSON.parse(e)).map(e=>({value:e.id,label:e.name}))],A=[{value:"all",label:"All Practitioners"},...g.map(e=>({value:e.id,label:e.handle}))];if(y)return(0,a.jsx)("div",{className:"text-center py-8",children:(0,a.jsx)(j.A,{size:"medium"})});if(f)return(0,a.jsxs)("div",{className:"text-center py-8 text-red-400",children:["Error: ",f]});let E=x.filter(e=>("all"===n||"company"!==e.companyType||e.companyId===n)&&("all"===c||e.assignedPractitionerId===c)&&("all"===d||e.role===d));return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"bg-black/20 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"text-white font-medium mb-3",children:"Filter Users"}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Company"}),(0,a.jsx)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:n,onChange:e=>r("all"===e.target.value?"all":Number(e.target.value)),children:S.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Practitioner"}),(0,a.jsx)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:c,onChange:e=>o("all"===e.target.value?"all":Number(e.target.value)),children:A.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Role"}),(0,a.jsx)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:d,onChange:e=>m(e.target.value),children:[{value:"all",label:"All Roles"},{value:"member",label:"Members"},{value:"manager",label:"Practitioners"},{value:"owner",label:"Owners"}].map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))})]})]})]}),(0,a.jsx)(p.Ay,{businessSlug:t,customUsers:E,title:"All Users (".concat(E.length,")"),description:"Manage user assignments and monitor wellbeing across all client companies and practitioners",userLabel:"User",columns:[{key:"user",label:"User",render:e=>(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"font-medium text-white",children:e.handle||"Anonymous"}),(0,a.jsx)("div",{className:"text-sm text-gray-400",children:e.email||"No email"})]})},{key:"company",label:"Company",render:e=>(0,a.jsx)("span",{className:"text-gray-300",children:e.companyName||"Unknown"})},{key:"role",label:"Role",render:e=>{let t={member:"Member",manager:"Practitioner",owner:"Owner"}[e.role]||e.role;return(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-white/10 text-gray-300",children:t})}},{key:"assignedPractitioner",label:"Assigned Practitioner",render:e=>(0,a.jsxs)("select",{className:"bg-black/30 border border-white/20 rounded px-2 py-1 text-xs text-white disabled:opacity-50",value:e.assignedPractitionerId||"",disabled:w.has(e.userId),onChange:t=>{k(e.userId,t.target.value)},onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("option",{value:"",children:"Unassigned"}),g.map(e=>(0,a.jsx)("option",{value:e.id,children:e.handle},e.id))]})}],showQuickStats:!1,onUserClick:e=>{console.log("User clicked:",e)},emptyMessage:"No users match the current filters."})]})};var b=s(24372),f=s(97460);let N=e=>{let{agencyId:t,agencySlug:s,companies:n}=e,r=(0,l.useRouter)(),[c,d]=(0,i.useState)("health"),[m,x]=(0,i.useState)("all"),[h,g]=(0,i.useState)(new Set),u=[...n].sort((e,t)=>
1{switch(c){case"name":return e.name.localeCompare(t.name);case"health":return t.analytics.overallHealth-e.analytics.overallHealth;case"engagement":return t.analytics.engagementRate-e.analytics.engagementRate;case"risk":return t.analytics.burnoutRisk-e.analytics.burnoutRisk;default:return 0}}).filter(e=>{if("all"===m)return!0;let t=e.analytics.overallHealth;return"high"===m?t<60:"medium"===m?t>=60&&t<80:"low"!==m||t>=80}),p=async(e,t)=>{e.stopPropagation();let a=window.location.origin,i="".concat(a,"/agency/join/").concat(s,"/").concat(t.slug);try{await navigator.clipboard.writeText(i),g(e=>new Set(e).add(t.organizationId)),setTimeout(()=>{g(e=>{let s=new Set(e);return s.delete(t.organizationId),s})},5e3)}catch(s){console.error("Failed to copy link:",s);let e=document.createElement("textarea");e.value=i,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),g(e=>new Set(e).add(t.organizationId)),setTimeout(()=>{g(e=>{let s=new Set(e);return s.delete(t.organizationId),s})},2e3)}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"bg-black/20 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"text-white font-medium mb-3",children:"Company Overview"}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Sort by"}),(0,a.jsxs)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:c,onChange:e=>d(e.target.value),children:[(0,a.jsx)("option",{value:"health",children:"Health Score"}),(0,a.jsx)("option",{value:"name",children:"Company Name"}),(0,a.jsx)("option",{value:"engagement",children:"Engagement Rate"}),(0,a.jsx)("option",{value:"risk",children:"Burnout Risk"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Risk Level"}),(0,a.jsxs)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:m,onChange:e=>x(e.target.value),children:[(0,a.jsx)("option",{value:"all",children:"All Companies"}),(0,a.jsx)("option",{value:"high",children:"High Risk (<60)"}),(0,a.jsx)("option",{value:"medium",children:"Medium Risk (60-80)"}),(0,a.jsx)("option",{value:"low",children:"Low Risk (≥80)"})]})]})]})]}),(0,a.jsx)("div",{className:"space-y-4",children:0===u.length?(0,a.jsx)("div",{className:"text-center py-8 text-gray-400",children:"No companies match the current filters."}):u.map((e,t)=>{let s=(e=>e>=80?{color:"bg-green-500/20 text-green-400",label:"Excellent"}:e>=60?{color:"bg-yellow-500/20 text-yellow-400",label:"Good"}:e>=40?{color:"bg-orange-500/20 text-orange-400",label:"Moderate"}:{color:"bg-red-500/20 text-red-400",label:"Poor"})(e.analytics.overallHealth);return(0,a.jsxs)(b.P.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.1*t},className:"bg-black/30 rounded-lg p-4 border border-white/10 hover:border-white/20 transition-colors cursor-pointer",onClick:()=>{r.push("/organizations/".concat(e.slug))},children:[(0,a.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)(f.g,{icon:o.URI,className:"text-blue-400 text-lg"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h5",{className:"font-semibold text-white",children:e.name}),(0,a.jsxs)("p",{className:"text-sm text-gray-400 capitalize",children:[e.type," organization"]})]})]}),(0,a.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat(s.color),children:s.label})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Health Score"}),(0,a.jsxs)("div",{className:"font-semibold ".concat((e=>e>=80?"text-green-400":e>=60?"text-yellow-400":e>=40?"text-orange-400":"text-red-400")(e.analytics.overallHealth)),children:[e.analytics.overallHealth.toFixed(0),"/100"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Members"}),(0,a.jsxs)("div",{className:"font-semibold text-white flex items-center gap-1",children:[(0,a.jsx)(f.g,{icon:o.gdJ,className:"text-blue-400 text-xs"}),e.memberCount]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Engagement"}),(0,a.jsxs)("div",{className:"font-semibold text-white flex items-center gap-1",children:[(0,a.jsx)(f.g,{icon:o.gK3,className:"text-green-400 text-xs"}),e.analytics.engagementRate.toFixed(1)]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"At Risk"}),(0,a.jsxs)("div",{className:"font-semibold flex items-center gap-1 ".concat(e.analytics.riskUsers>0?"text-red-400":"text-green-400"),children:[e.analytics.riskUsers>0&&(0,a.jsx)(f.g,{icon:o.zpE,className:"text-xs"}),e.analytics.riskUsers]})]})]}),(0,a.jsx)("div",{className:"mt-4 pt-3 border-t border-white/10",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-400",children:"Click to view company dashboard"}),(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsxs)(b.P.button,{onClick:t=>p(t,e),className:"px-3 py-1.5 border rounded-md text-xs font-medium transition-all duration-200 flex items-center gap-1.5 ".concat(h.has(e.organizationId)?"bg-green-500/20 border-green-500/50 text-green-400":"bg-aidx/20 hover:bg-aidx/30 border-aidx/30 hover:border-aidx/50 text-aidx"),whileHover:{scale:1.02},whileTap:{scale:.98},title:"Copy join link for ".concat(e.name),children:[(0,a.jsx)(f.g,{icon:h.has(e.organizationId)?o.e68:o.jPR,className:"text-xs"}
1),h.has(e.organizationId)?"Copied!":"Copy Join Link"]})})]})})]},e.organizationId)})}),(0,a.jsxs)("div",{className:"bg-black/20 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"text-white font-medium mb-3",children:"Summary"}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-center",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-white",children:n.length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Total Companies"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-green-400",children:n.filter(e=>e.analytics.overallHealth>=80).length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Healthy"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-yellow-400",children:n.filter(e=>e.analytics.overallHealth>=60&&e.analytics.overallHealth<80).length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Moderate"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-red-400",children:n.filter(e=>e.analytics.overallHealth<60).length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"At Risk"})]})]})]})]})},w=e=>{let{agencyId:t,coaches:s}=e,[l,n]=(0,i.useState)("performance"),[r,c]=(0,i.useState)("all"),d=[...s].sort((e,t)=>{switch(l){case"name":return e.handle.localeCompare(t.handle);case"performance":return t.performance.avgClientImprovement-e.performance.avgClientImprovement;case"clientCount":return t.clientCount-e.clientCount;case"riskClients":return t.performance.riskClients-e.performance.riskClients;default:return 0}}).filter(e=>"all"===r||("available"===r?e.clientCount<20:"full"!==r||e.clientCount>=20));return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"bg-black/20 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"text-white font-medium mb-3",children:"Coach Performance Overview"}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Sort by"}),(0,a.jsxs)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:l,onChange:e=>n(e.target.value),children:[(0,a.jsx)("option",{value:"performance",children:"Performance Score"}),(0,a.jsx)("option",{value:"name",children:"Coach Name"}),(0,a.jsx)("option",{value:"clientCount",children:"Client Count"}),(0,a.jsx)("option",{value:"riskClients",children:"Risk Clients"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm text-gray-400 mb-2",children:"Availability"}),(0,a.jsxs)("select",{className:"w-full bg-black/30 border border-white/20 rounded px-3 py-2 text-white",value:r,onChange:e=>c(e.target.value),children:[(0,a.jsx)("option",{value:"all",children:"All Coaches"}),(0,a.jsx)("option",{value:"available",children:"Available (<20 clients)"}),(0,a.jsx)("option",{value:"full",children:"Full Capacity (≥20 clients)"})]})]})]})]}),(0,a.jsx)("div",{className:"space-y-4",children:0===d.length?(0,a.jsx)("div",{className:"text-center py-8 text-gray-400",children:"No coaches match the current filters."}):d.map((e,t)=>{let s=(e=>e>=15?{color:"bg-green-500/20 text-green-400",label:"Excellent"}:e>=10?{color:"bg-yellow-500/20 text-yellow-400",label:"Good"}:e>=5?{color:"bg-orange-500/20 text-orange-400",label:"Fair"}:{color:"bg-red-500/20 text-red-400",label:"Needs Support"})(e.performance.avgClientImprovement),i=(e=>e>=20?{color:"bg-red-500/20 text-red-400",label:"Full Capacity"}:e>=15?{color:"bg-yellow-500/20 text-yellow-400",label:"High Load"}:{color:"bg-green-500/20 text-green-400",label:"Available"})(e.clientCount);return(0,a.jsxs)(b.P.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.1*t},className:"bg-black/30 rounded-lg p-4 border border-white/10 hover:border-white/20 transition-colors",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)(f.g,{icon:o.X46,className:"text-blue-400 text-lg"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h5",{className:"font-semibold text-white",children:e.handle}),(0,a.jsx)("p",{className:"text-sm text-gray-400",children:e.email})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat(s.color),children:s.label}),(0,a.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat(i.color),children:i.label})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Performance"}),(0,a.jsxs)("div",{className:"font-semibold ".concat((e=>e>=15?"text-green-400":e>=10?"text-yellow-400":e>=5?"text-orange-400":"text-red-400")(e.performance.avgClientImprovement)),children:["+",e.performance.avgClientImprovement.toFixed(1),"%"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Total Clients"}),(0,a.jsxs)("div",{className:"font-semibold text-white flex items-center gap-1",children:[(0,a.jsx)(f.g,{icon:o.gdJ,className:"text-blue-400 text-xs"}),e.clientCount]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Active Clients"}),(0,a.jsxs)("div",{className:"font-semibold text-white flex items-center gap-1",children:[(0,a.jsx)(f.g,{icon:o.gK3,className:"text-green-400 text-xs"}),e.performance.activeClients]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Risk Clients"}),(0,a.jsxs)("div",{className:"font-semibold flex items-center gap-1 ".concat(e.performance.riskClients>0?"text-red-400":"text-green-400"),children:[e.performance.riskClients>0&&(0,a.jsx)(f.g,{icon:o.zpE,className:"text-xs"}),e.performance.riskClients]})]})]}),e.assignedCompanies&&e.assignedCompanies.length>0&&(0,a.jsxs)("div",{className:"pt-3 border-t border-white/10",children:[(0,a.jsx)("div",{className:"text-xs text-gray-400 mb-2",children:"Assigned Companies:"}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:e.assignedCompanies.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-white/10 rounded text-xs text-gray-300",children:[(0,a.jsx)(f.g,{icon:o.URI,className:"text-xs"}),e]},e))})]})]},e.userId)})}),(0,a.jsxs)("div",{className:"bg-black/20 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"text-white font-medium mb-3",children:"Coach Performance Summary"}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-center",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-white",children:s.length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Total Coaches"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-green-400",children:s.filter(e=>e.performance.avgClientImprovement>=15).length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Top Performers"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-blue-400",children:s.reduce((e,t)=>
1e+t.clientCount,0)}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"Total Clients"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-2xl font-bold text-yellow-400",children:s.filter(e=>e.clientCount>=20).length}),(0,a.jsx)("div",{className:"text-xs text-gray-400",children:"At Capacity"})]})]})]})]})};var C=s(27212),k=s(62591),S=s(18158);let A=e=>{let{businessId:t,businessSlug:s}=e,[l,n]=(0,i.useState)("materials"),[r,c]=(0,i.useState)([]),[d,m]=(0,i.useState)([]),[x,h]=(0,i.useState)(!0),{fetchWithAuth:g}=(0,v.A)();(0,i.useEffect)(()=>{u(),p()},[s]);let u=async()=>{try{let e=await g("/api/organizations/".concat(s,"/library")),t=await e.json();c(t.items||[])}catch(e){console.error("Failed to load items:",e)}finally{h(!1)}},p=async()=>{try{m([])}catch(e){console.error("Failed to load client organizations:",e)}},j=async(e,t,a)=>{try{await g("/api/organizations/".concat(s,"/library/").concat(e,"/access"),{method:a?"POST":"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetOrganizationId:t})}),u()}catch(e){console.error("Failed to update delegation:",e)}},y=async e=>{if(confirm("Are you sure you want to delete this item?"))try{await g("/api/organizations/".concat(s,"/library/").concat(e),{method:"DELETE"}),u()}catch(e){console.error("Failed to delete item:",e)}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"flex bg-white/5 backdrop-blur-sm rounded-lg p-1 mb-6",children:[(0,a.jsxs)("button",{onClick:()=>n("materials"),className:"flex-1 py-2 px-4 rounded-md transition-colors ".concat("materials"===l?"bg-blue-500 text-white":"text-gray-400 hover:text-white hover:bg-white/10"),children:[(0,a.jsx)(f.g,{icon:o.Uj9,className:"mr-2"}),"Materials"]}),(0,a.jsxs)("button",{onClick:()=>n("upload"),className:"flex-1 py-2 px-4 rounded-md transition-colors ".concat("upload"===l?"bg-blue-500 text-white":"text-gray-400 hover:text-white hover:bg-white/10"),children:[(0,a.jsx)(f.g,{icon:o.QLR,className:"mr-2"}),"Upload"]})]}),(0,a.jsxs)(C.N,{mode:"wait",children:["materials"===l&&(0,a.jsx)(b.P.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.2},children:x?(0,a.jsx)("div",{className:"flex justify-center py-12",children:(0,a.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-400"})}):(0,a.jsx)(S.A,{items:r,organizationType:"agency",clientOrganizations:d,onDelegationChange:j,onDeleteItem:y})},"materials"),"upload"===l&&(0,a.jsx)(b.P.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.2},children:(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold text-white mb-2",children:"Upload Training Materials"}),(0,a.jsx)("p",{className:"text-gray-400 text-sm mb-6",children:"Upload documents that will be available to practitioners and can be delegated to client organizations."})]}),(0,a.jsx)(k.A,{uploadType:"documents",entityType:"agency",entityId:t.toString(),onUploadSuccess:e=>{u(),n("materials")},onUploadError:e=>console.error("Upload error:",e),className:"w-full"}),(0,a.jsx)("div",{className:"bg-blue-500/10 border border-blue-500/20 rounded-lg p-4",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(f.g,{icon:o.iW_,className:"text-blue-400 mt-1"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h4",{className:"text-blue-300 font-medium mb-1",children:"Automatic Access"}),(0,a.jsx)("p",{className:"text-blue-200 text-sm",children:"Practitioner organizations automatically receive access to all agency materials. You can delegate specific materials to company organizations using the controls in the Materials tab."})]})]})})]})},"upload")]})]})};var E=s(32948),U=s(95572);let R=()=>{let{slug:e}=(0,l.useRouter)().query;return(0,a.jsx)(c.A,{createDashboardConfig:e=>{let t=(e=>{let t={type:"organization",apiEndpointType:"agency",redirectPath:"/agency",businessTypeLabel:"Agency",chatMode:"manager",analyticsTitle:"Agency Analytics",analyticsDescription:"Monitor client companies and coach performance at a glance",trendsTitle:"Multi-Company Wellbeing Trends"},s=[{id:"chat",label:"Chat",icon:o.q9p,onClick:()=>e("chat"),variant:"primary"},{id:"companies",label:"Companies",icon:o.URI,onClick:()=>{}},{id:"users",label:"Users",icon:o.gdJ,onClick:()=>{}},{id:"forms",label:"Forms",icon:o.vZS,onClick:()=>{}},{id:"exercises",label:"Exercises",icon:o.VwO,onClick:()=>{}},{id:"library",label:"Library",icon:o.LBj,onClick:()=>{}},{id:"settings",label:"Settings",icon:o.dB,onClick:()=>{}}],i=[{id:"chat",title:"".concat(t.businessTypeLabel," Discussion"),icon:o.q9p,theme:"dark"},{id:"companies",title:"Client Companies",icon:o.URI},{id:"coaches",title:"Agency Coaches",icon:o.t9i}
1,{id:"users",title:"All Users",icon:o.gdJ},{id:"forms",title:"Form Builder",icon:o.vZS},{id:"exercises",title:"Exercise Builder",icon:o.VwO},{id:"library",title:"Training Library",icon:o.LBj},{id:"settings",title:"Settings",icon:o.dB}];return{dashboardConfig:t,headerMenuItems:s,metricCards:[{id:"engagement",component:x,props:{}},{id:"attention",component:h,props:{}},{id:"health",component:g,props:{}},{id:"stalemate",component:u,props:{}}],actionStripSections:[],chartConfig:{title:"Multi-Company Wellbeing Trends",lines:[{dataKey:"emotionalWellbeingScore",name:"Emotional Wellbeing"},{dataKey:"workSatisfaction",name:"Work Satisfaction"},{dataKey:"workLifeBalance",name:"Work-Life Balance"},{dataKey:"stressLevel",name:"Stress Level"},{dataKey:"overallHealth",name:"Overall Health"}],height:320},slideoutConfigs:i,renderSlideoutContent:(e,s,i)=>{switch(e){case"chat":return(0,a.jsx)(d.r,{mode:t.chatMode});case"companies":return(0,a.jsx)(N,{agencyId:s.id,agencySlug:s.slug,companies:i.companies.filter(e=>"company"===e.type)});case"coaches":return(0,a.jsx)(w,{agencyId:s.id,coaches:i.coaches});case"users":return(0,a.jsx)(y,{agencySlug:s.slug});case"forms":return(0,a.jsx)(U.A,{organizationSlug:s.slug,organizationType:"agency",sequenceType:"forms"});case"exercises":return(0,a.jsx)(U.A,{organizationSlug:s.slug,organizationType:"agency",sequenceType:"exercises"});case"library":return(0,a.jsx)(A,{businessId:s.id,businessSlug:s.slug});case"settings":return(0,a.jsx)(E.A,{organization:s});default:return null}},createActionStripSections:t=>{var s,a;return[{id:"wins",title:"Big Wins & Momentum",icon:"\uD83D\uDE80",items:((null==(s=t.insights)?void 0:s.wins)||[]).map((t,s)=>({id:"win-".concat(s),text:t.message,metric:t.metric,timestamp:t.companyName,change:"+".concat(t.improvement.toFixed(0),"%"),actionLabel:"View company details",onClick:()=>e("chat")})),emptyState:{icon:"\uD83C\uDF31",title:"Building Success Across Companies",description:"Company wins and improvements will appear here as client organizations make progress."},onItemClick:e=>{var t;return null==(t=e.onClick)?void 0:t.call(e)}},{id:"risks",title:"Risks & Immediate Actions",icon:"⚠️",items:((null==(a=t.insights)?void 0:a.risks)||[]).map((t,s)=>({id:"risk-".concat(s),text:t.message,metric:t.metric,timestamp:t.companyName,change:"".concat(t.userCount," users"),severity:t.severity,actionLabel:"Review interventions",onClick:()=>e("chat")})),emptyState:{icon:"✅",title:"All companies stable",description:"Risk alerts across client companies will appear here when intervention is needed."},onItemClick:e=>{var t;return null==(t=e.onClick)?void 0:t.call(e)}}]}}})(e);return{...t,getActionStripSections:e=>t.createActionStripSections(e)}},pageTitle:"".concat(e?"".concat(e," - "):"","Agency Dashboard")})},I=()=>(0,a.jsx)(r.T,{children:(0,a.jsx)(n.A,{className:"bg-aidx-mesh-gradient-light",children:(0,a.jsx)(R,{})})})}},e=>{e.O(0,[7725,8805,4587,5849,4882,8204,2834,126,6303,8811,2793,8992,8573,5951,3532,363,3681,6036,4172,1801,636,6593,8792],()=>e(e.s=59872)),_N_E=e.O()}]);

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.