1import{o as e}from"./chunk-C_JJxWoe.js";import{c as s,s as t}from"./chunk-rFqg_5aG.js";import{h as a}from"./chunk-BujAe8FO.js";import{i as n}from"./chunk-BA8PhJfb.js";import{s as r}from"./chunk-BGvE84R2.js";import{i as l}from"./chunk-DfDiApbE.js";import{a as i,i as c,n as d}from"./chunk-BdmRp9-u.js";import{n as o,t as m}from"./chunk-BApK0bRp.js";import{a as x,c as h,f as u,h as p,m as j,o as f}from"./chunk-BVoOQtad.js";import{r as g}from"./chunk-oEarIxkK.js";import{r as N}from"./chunk-CcfmLqZl.js";import{r as y}from"./chunk-C7t3w7G5.js";import{Bt as v,En as b,Gt as w,Lr as k,Ut as E,Wt as T,Xn as S,Zn as P,er as C,jr as A,mr as L,pr as O,zt as _}from"../index-D56I12Dv.js";import{n as $}from"./chunk-QqNSRoPr2.js";import{t as z}from"./chunk-D0zXT10r2.js";import{n as D,r as M,t as U}from"./chunk-BEIlD_Q-.js";import{a as q,c as I,i as W,n as F,s as H}from"./chunk-SsMeMIBl.js";import{a as B,s as G}from"./chunk-oUiPicNn.js";import{t as R}from"./chunk-C-xgxJgr.js";import{i as K,r as Z,t as V}from"./chunk-tRoDmPI0.js";import{t as X}from"./chunk-BV9bCqdA.js";var J=e(k(),1);function Q(e,s){if(!s)return!1;const t=G(e,s);return!H(e,t)}var Y=A();function ee({snapshotTotal:e,eventTotal:t,unmappedStages:a}){const n=[{name:"Mapping Coverage",status:0===a.length?"pass":"fail",message:0===a.length?"All stages explicitly mapped":`${a.length} unmapped stage(s) detected`,icon:j},{name:"Snapshot Lens",status:e>0?"pass":"warn",message:e>0?`${e} entities in current state`:"No entities found (empty or RLS issue)",icon:c},{name:"Event Log",status:t>0?"pass":"warn",message:t>0?`${t} events recorded`:"No events (backfill needed or no transitions)",icon:s},{name:"Dual Lens Consistency",status:se(e,t),message:te(e,t),icon:C}],r=n.filter(e=>"pass"===e.status).length,l=n.filter(e=>"fail"===e.status).length;return(0,Y.jsxs)(_,{children:[(0,Y.jsx)(E,{className:"pb-3",children:(0,Y.jsxs)(T,{className:"text-lg flex items-center justify-between",children:[(0,Y.jsx)("span",{children:"Topology Health"}),(0,Y.jsxs)(z,{variant:l>0?"destructive":r===n.length?"default":"secondary",className:"ml-2",children:[r,"/",n.length," passing"]})]})}),(0,Y.jsxs)(v,{className:"space-y-3",children:[n.map(e=>{const s=e.icon,t="pass"===e.status?o:"warn"===e.status?x:m;return(0,Y.jsxs)("div",{className:S("flex items-center justify-between p-2 rounded-lg","pass"===e.status&&"bg-emerald-500/10","warn"===e.status&&"bg-amber-500/10","fail"===e.status&&"bg-destructive/10"),children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Y.jsx)(s,{className:"w-4 h-4 text-muted-foreground"}),(0,Y.jsx)("span",{className:"text-sm font-medium",children:e.name})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Y.jsx)("span",{className:"text-xs text-muted-foreground",children:e.message}),(0,Y.jsx)(t,{className:S("w-4 h-4","pass"===e.status&&"text-emerald-500","warn"===e.status&&"text-amber-500","fail"===e.status&&"text-destructive")}
1)]})]},e.name)}),a.length>0&&(0,Y.jsxs)("div",{className:"mt-4 p-3 rounded-lg bg-destructive/10 border border-destructive/20",children:[(0,Y.jsx)("div",{className:"text-sm font-medium text-destructive mb-2",children:"Unmapped Stages (Stop-Ship)"}),(0,Y.jsx)("div",{className:"space-y-1",children:a.map((e,s)=>(0,Y.jsxs)("div",{className:"text-xs flex justify-between",children:[(0,Y.jsxs)("span",{className:"text-muted-foreground",children:[e.entityType,".",(0,Y.jsx)("code",{className:"bg-muted px-1 rounded",children:e.stage})]}),(0,Y.jsxs)("span",{className:"text-destructive",children:[e.count," record(s)"]})]},s))})]})]})]})}function se(e,s){return 0===e&&0===s||e>0&&0===s?"warn":0===e&&s>0?"fail":"pass"}function te(e,s){return 0===e&&0===s?"Both lenses empty (new install or RLS issue)":e>0&&0===s?"Snapshot has data, events empty (backfill needed)":0===e&&s>0?"Events exist but snapshot empty (data deleted?)":"Both lenses operational"}var ae={perception:y,understanding:l,consideration:n,decision:t,action:P,outcome:a,wisdom:N},ne={stakeholder:d,content:p,episode:u,outreach:h,research:l};function re(){const{data:e,isLoading:t}=B(),{data:a,isLoading:n}=b({queryKey:["flywheel-current-state"],queryFn:async()=>{const e=Object.fromEntries(q.map(e=>[e,{total:0,byEntityType:{stakeholder:0,content:0,episode:0,outreach:0}}])),s={stakeholder:0,content:0,episode:0,outreach:0,all:0},t=new Map,[a,n,r,l]=await Promise.all([$.from("stakeholders").select("pipeline_stage").limit(5e3),$.from("content_assets").select("lifecycle_stage").limit(5e3),$.from("episode_workflows").select("current_stage").limit(5e3),$.from("outreach_drafting_sessions").select("status").limit(5e3)]),i=e=>{if(e.error)throw e.error;return e.data??[]};for(const c of i(a)){const a=c.pipeline_stage??null,n=G("stakeholder",a),r=I("stakeholder",n);if(e[r].total+=1,e[r].byEntityType.stakeholder+=1,s.stakeholder+=1,Q("stakeholder",a)){const e=`stakeholder:${a}`,s=t.get(e);s?s.count++:t.set(e,{entityType:"stakeholder",stage:a||"null",count:1})}}for(const c of i(n)){const a=c.lifecycle_stage??null,n=G("content",a),r=I("content",n);if(e[r].total+=1,e[r].byEntityType.content+=1,s.content+=1,Q("content",a)){const e=`content:${a}`,s=t.get(e);s?s.count++:t.set(e,{entityType:"content",stage:a||"null",count:1})}}for(const c of i(r)){const a=c.current_stage??null,n=G("episode",a),r=I("episode",n);if(e[r].total+=1,e[r].byEntityType.episode+=1,s.episode+=1,Q("episode",a)){const e=`episode:${a}`,s=t.get(e);s?s.count++:t.set(e,{entityType:"episode",stage:a||"null",count:1})}}for(const c of i(l)){const a=c.status??null,n=G("outreach",a),r=I("outreach",n);if(e[r].total+=1,e[r].byEntityType.outreach+=1,s.outreach+=1,Q("outreach",a)){const e=`outreach:${a}`,s=t.get(e);s?s.count++:t.set(e,{entityType:"outreach",stage:a||"null",count:1})}}return s.all=s.stakeholder+s.content+s.episode+s.outreach,{byPhase:e,totals:s,unmappedStages:Array.from(t.values())}},staleTime:3e4}),{data:l}=X(),[o,m]=(0,J.useState)(!1),[h,u]=(0,J.useState)("snapshot");if(t||n||!e&&!a)return(0,Y.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,Y.jsx)("div",{className:"animate-pulse text-muted-foreground",children:"Loading flywheel data..."})});const p=a,j=e,N="snapshot"===h?p?.byPhase:j?.byPhase,y=N?q.reduce((e,s)=>e+(N[s]?.total||0),0):0;return(0,Y.jsxs)("div",{className:"space-y-6",children:[(0,Y.jsx)("div",{className:"flex items-center justify-between",children:(0,Y.jsxs)("div",{className:"flex items-center gap-4",children:[(0,Y.jsx)("h2",{className:"text-xl font-semibold",children:"Universal Flywheel"}),(0,Y.jsx)(V,{value:h,onValueChange:e=>u(e),children:(0,Y.jsxs)(Z,{className:"h-8",children:[(0,Y.jsxs)(K,{value:"snapshot",className:"text-xs gap-1.5",children:[(0,Y.jsx)(c,{className:"w-3.5 h-3.5"}),"Current State"]}),(0,Y.jsxs)(K,{value:"events",className:"text-xs gap-1.5",children:[(0,Y.jsx)(s,{className:"w-3.5 h-3.5"}),"Event History"]})]})})]})}),(0,Y.jsx)(_,{className:"border-2 border-primary/20 bg-primary/5",children:(0,Y.jsx)(v,{className:"pt-4",children:(0,Y.jsxs)("div",{className:"flex items-start gap-3",children:[(0,Y.jsx)("div",{className:"p-2 rounded-full bg-primary/10",children:(0,Y.jsx)(r,{className:"w-5 h-5 text-primary"})}),(0,Y.jsxs)("div",{className:"space-y-2",children:[(0,Y.jsx)("h3",{className:"font-semibold text-sm",children:"ð ORGANIZATIONAL SCOPE LAW"}),(0,Y.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Phases describe the ",(0,Y.jsx)("strong",{children:"organization"})," â not the people working inside it."]}),(0,Y.jsxs)("ul",{className:"text-xs text-muted-foreground space-y-1 list-disc ml-4",children:[(0,Y.jsxs)("li",{children:["Internal prep/review/escalation = ",(0,Y.jsx)("strong",{children:"Consideration"})]}),(0,Y.jsxs)("li",{children:["Org authorization to affect the outside world = ",(0,Y.jsx)("strong",{children:"Decision"})]}),(0,Y.jsxs)("li",{children:["Dissemination = ",(0,Y.jsx)("strong",{children:"Action"})]}),(0,Y.jsxs)("li",{children:["Measurement = ",(0,Y.jsx)("strong",{children:"Outcome"})]}),(0,Y.jsxs)("li",{children:["Interpretation = ",(0,Y.jsx)("strong",{children:"Wisdom"})]})]}),(0,Y.jsx)("p",{className:"text-xs italic text-muted-foreground border-t pt-2 mt-2",children:"If the outside world has not been affected yet, the organization has not acted."})]})]})})}),(0,Y.jsxs)(U,{open:o,onOpenChange:m,children:[(0,Y.jsx)(M,{asChild:!0,children:(0,Y.jsxs)(w,{variant:"ghost",size:"sm",className:"gap-1.5 mb-2",children:[(0,Y.jsx)(O,{className:"w-4 h-4"}),"Mapping Details",(0,Y.jsx)(L,{className:S("w-4 h-4 transition-transform",o&&"rotate-180")}
1)]})}),(0,Y.jsx)(D,{children:(0,Y.jsx)(_,{className:"bg-muted/30 border-dashed",children:(0,Y.jsxs)(v,{className:"pt-4 text-sm space-y-3",children:[(0,Y.jsxs)("div",{children:[(0,Y.jsx)("strong",{children:"Dual Lens Model:"}),(0,Y.jsxs)("ul",{className:"list-disc ml-4 mt-1 space-y-1 text-muted-foreground",children:[(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Current State"})," (snapshot): What's true now â queries entity tables directly"]}),(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Event History"}),": What happened over time â queries transformation_events log"]})]})]}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("strong",{children:"Entity Entry Points:"}),(0,Y.jsxs)("ul",{className:"list-disc ml-4 mt-1 space-y-1 text-muted-foreground",children:[(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Stakeholders"}),": Enter at Perception (we notice them)"]}),(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Content"}),": Enters at Understanding (sense-making, off-beat)"]}),(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Outreach"}),": Enters at Consideration (preparing to commit)"]}),(0,Y.jsxs)("li",{children:[(0,Y.jsx)("strong",{children:"Episodes"}),": Enter at Action (production in motion)"]})]})]}),(0,Y.jsxs)("div",{className:"text-xs text-muted-foreground italic",children:["Key rule: ",(0,Y.jsx)("code",{children:"measuring"})," is Outcome (observing), not Action (doing)."]})]})})})]}),(0,Y.jsx)(_,{className:"border-amber-500/30 bg-amber-500/5",children:(0,Y.jsx)(v,{className:"py-3",children:(0,Y.jsxs)("div",{className:"flex items-center justify-between",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Y.jsx)(g,{className:"w-4 h-4 text-amber-500"}),(0,Y.jsx)("span",{className:"text-sm font-medium",children:"Annotation Gate"})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Y.jsxs)("span",{className:"text-sm",children:[(0,Y.jsx)("span",{className:"font-bold text-emerald-500",children:l?.explainedEvents??0})," / ",(0,Y.jsx)("span",{className:"font-bold",children:l?.totalEvents??0})," events explained"]}),(0,Y.jsxs)(z,{variant:(l?.explainedPct??0)<10?"destructive":(l?.explainedPct??0)<50?"secondary":"default",children:[(l?.explainedPct??0).toFixed(1),"%"]})]})]})})}),(0,Y.jsx)(ee,{snapshotTotal:p?.totals.all||0,eventTotal:l?.totalEvents??0,unmappedStages:p?.unmappedStages||[]}),(0,Y.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,Y.jsx)(_,{children:(0,Y.jsx)(v,{className:"pt-4",children:(0,Y.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Y.jsx)("div",{className:"p-2 rounded-full bg-primary/10",children:(0,Y.jsx)(f,{className:"w-5 h-5 text-primary"})}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("div",{className:"text-2xl font-bold",children:j?.velocity.daily??0}),(0,Y.jsx)("p",{className:"text-xs text-muted-foreground",children:"Transitions today"})]})]})})}),(0,Y.jsx)(_,{children:(0,Y.jsx)(v,{className:"pt-4",children:(0,Y.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Y.jsx)("div",{className:"p-2 rounded-full bg-chart-2/10",children:(0,Y.jsx)(f,{className:"w-5 h-5 text-chart-2"})}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("div",{className:"text-2xl font-bold",children:j?.velocity.weekly??0}),(0,Y.jsx)("p",{className:"text-xs text-muted-foreground",children:"Transitions this week"})]})]})})}),(0,Y.jsx)(_,{children:(0,Y.jsx)(v,{className:"pt-4",children:(0,Y.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Y.jsx)("div",{className:"p-2 rounded-full bg-amber-500/10",children:(0,Y.jsx)(i,{className:"w-5 h-5 text-amber-500"})}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("div",{className:"text-2xl font-bold",children:j?.stalledEntities.length??0}),(0,Y.jsx)("p",{className:"text-xs text-muted-foreground",children:"Stalled entities"})]})]})})})]}),(0,Y.jsxs)(_,{children:[(0,Y.jsx)(E,{className:"pb-2",children:(0,Y.jsxs)(T,{className:"text-lg flex items-center justify-between",children:[(0,Y.jsx)("span",{children:"Universal Transformation Phases"}),(0,Y.jsx)(z,{variant:"outline",className:"font-normal",children:"snapshot"===h?"Current State":"Event History"})]})}),(0,Y.jsx)(v,{children:(0,Y.jsx)("div",{className:"grid grid-cols-7 gap-2",children:q.map(e=>{const s=W[e],t=ae[e],a=N?.[e]||{total:0,byEntityType:{},stalledCount:0},n=y>0?a.total/y*100:0,r="events"===h&&j?.byPhase[e]?.stalledCount||0;return(0,Y.jsxs)("div",{className:S("p-3 rounded-lg border text-center transition-colors",r>0&&"border-amber-500/50 bg-amber-500/5"),children:[(0,Y.jsx)("div",{className:"w-10 h-10 mx-auto rounded-full flex items-center justify-center mb-2",style:{backgroundColor:`${s.color}20`},children:(0,Y.jsx)(t,{className:"w-5 h-5",style:{color:s.color}})}),(0,Y.jsx)("div",{className:"text-lg font-bold",children:a.total}),(0,Y.jsx)("div",{className:"text-xs font-medium",children:s.label}),(0,Y.jsx)(R,{value:n,className:"mt-2 h-1"}),r>0&&(0,Y.jsxs)(z,{variant:"outline",className:"mt-2 text-xs text-amber-500 border-amber-500/50",children:[r," stalled"]})]},e)})})})]}),(0,Y.jsxs)(_,{children:[(0,Y.jsx)(E,{children:(0,Y.jsx)(T,{className:"text-lg",children:"Entity Distribution by Phase"})}),(0,Y.jsx)(v,{children:(0,Y.jsx)("div",{className:"overflow-x-auto",children:(0,Y.jsxs)("table",{className:"w-full text-sm",children:[(0,Y.jsx)("thead",{children:(0,Y.jsxs)("tr",{className:"border-b",children:[(0,Y.jsx)("th",{className:"text-left py-2 px-2",children:"Phase"}),Object.keys(F).map(e=>{const s=ne[e];return(0,Y.jsx)("th",{className:"text-center py-2 px-2",children:(0,Y.jsxs)("div",{className:"flex items-center justify-center gap-1",children:[(0,Y.jsx)(s,{className:"w-4 h-4"}),(0,Y.jsx)("span",{className:"hidden md:inline",children:F[e].label})]})},e)}),(0,Y.jsx)("th",{className:"text-center py-2 px-2",children:"Total"})]})}),(0,Y.jsx)("tbody",{children:q.map(e=>{const s=N?.[e]||{total:0,byEntityType:{}};return(0,Y.jsxs)("tr",{className:"border-b last:border-0",children:[(0,Y.jsx)("td",{className:"py-2 px-2 font-medium",children:W[e].label}),Object.keys(F).map(e=>(0,Y.jsx)("td",{className:"text-center py-2 px-2",children:s.byEntityType[e]||0},e)),(0,Y.jsx)("td",{className:"text-center py-2 px-2 font-bold",children:s.total})]},e)})})]})})})]}),j&&j.stalledEntities.length>0&&(0,Y.jsxs)(_,{children:[(0,Y.jsx)(E,{children:(0,Y.jsxs)(T,{className:"text-lg flex items-center gap-2",children:[(0,Y.jsx)(x,{className:"w-5 h-5 text-amber-500"}
1),"Stalled Entities"]})}),(0,Y.jsx)(v,{children:(0,Y.jsx)("div",{className:"space-y-2",children:j.stalledEntities.slice(0,10).map((e,s)=>{const t=ne[e.entityType]||d;return(0,Y.jsxs)("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Y.jsx)(t,{className:"w-4 h-4 text-muted-foreground"}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("span",{className:"text-sm font-medium capitalize",children:e.entityType}),(0,Y.jsxs)("span",{className:"text-xs text-muted-foreground ml-2",children:["in ",W[e.phase].label]})]})]}),(0,Y.jsxs)(z,{variant:"outline",className:"text-amber-500",children:[e.daysSinceTransition,"d since activity"]})]},s)})})})]}),j&&j.driftAlerts.length>0&&(0,Y.jsxs)(_,{children:[(0,Y.jsx)(E,{children:(0,Y.jsxs)(T,{className:"text-lg flex items-center gap-2",children:[(0,Y.jsx)(x,{className:"w-5 h-5 text-destructive"}),"Drift Alerts"]})}),(0,Y.jsx)(v,{children:(0,Y.jsx)("div",{className:"space-y-2",children:j.driftAlerts.map((e,s)=>(0,Y.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg bg-destructive/10",children:[(0,Y.jsxs)("div",{children:[(0,Y.jsx)("span",{className:"font-medium capitalize",children:e.platform}),(0,Y.jsx)("span",{className:"text-sm text-muted-foreground ml-2",children:e.metric})]}),(0,Y.jsxs)("div",{className:"text-right",children:[(0,Y.jsxs)("div",{className:"text-sm",children:["Assumed: ",e.assumed,"h â Measured: ",e.measured,"h"]}),(0,Y.jsxs)(z,{variant:"destructive",children:[e.driftPercent?.toFixed(1),"% drift"]})]})]},s))})})]})]})}export{re as UniversalFlywheelTab};
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.