PageSourceSearch

https://protein-os.lovable.app/assets/Dashboard-CJWKRRdj.js

js protein-os.lovable.app collected 2026-10-03 03:41:42 UTC 34,267 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-markdown-C-I3nZWo.js";import{r as u}from"./vendor-charts-DphG3eWF.js";import{T as pt,a9 as Ne,aa as we,a5 as _e,ab as Ce,s as _,j as K,C as Ae,b as Le,aH as ht,B as S,a3 as F,K as Ee,ah as ft,M as Re,Q as De,S as Fe,U as Ie,t as M,aI as Te,X as gt,aJ as bt,aK as jt,aL as yt,aM as vt,aN as Nt,aO as wt,aP as _t,aQ as Ct,aR as kt,aS as qt,aT as St,aU as Pt,aV as Mt,Y as ee,Z as te,_ as se,$ as ae,a0 as C,aj as re,aA as At}from"./index-DFoQxP2Z.js";import{C as Lt}from"./CulturalShell-CRmgK6jo.js";import{D as H,S as Et,K as O,M as Rt,a as Dt,b as Ft,c as It}from"./primitives-DwkiOsSy.js";import{R as U,a as Tt}from"./RecordDialog-CajPKuxO.js";import{bG as $t,bH as Qt,H as Vt,aN as zt,v as ne,i as Ot}from"./vendor-icons-DptrxPFP.js";import{logFeedback as Ut}from"./logFeedback-7BbUMWaP.js";import{P as Bt}from"./ProteinIndexBadge-DUGhjyzc.js";import{P as Ht}from"./ProteinIndexMethodPanel-CQGkhxau.js";import{B as $e}from"./badge-DvZAazPQ.js";import{u as le}from"./useIsAdmin-Cz3smzBt.js";import{a as P,u as ie,b as oe}from"./vendor-query-Csct0vqx.js";import{P as Kt,a as Gt}from"./PiQuadrant-BYbMmmSz.js";import{T as Yt,a as ke}from"./toggle-group-BYjfrCFG.js";import"./vendor-office-CYA1a3lH.js";import"./vendor-radix-DiGlQgnh.js";import"./vendor-supabase-C6T5JIOu.js";import"./vendor-analytics-4JMxWFgu.js";import"./vendor-forms-Crpao7PO.js";import"./alert-dialog-Co-1sklm.js";import"./textarea-DyjusVvx.js";import"./progress-C4dqlrQs.js";import"./piQueries-Bc_UDOzN.js";import"./vendor-date-DwvsUr7l.js";function B({vote:s,onVote:a,disabled:r}){const n=i=>{i.preventDefault(),i.stopPropagation()};return e.jsx(pt,{delayDuration:150,children:e.jsxs("div",{className:"flex gap-0.5 shrink-0",onClick:n,children:[e.jsxs(Ne,{children:[e.jsx(we,{asChild:!0,children:e.jsx("button",{type:"button",disabled:r,onClick:i=>{n(i),a(1)},"aria-pressed":s===1,"aria-label":"Mark as relevant",className:_e("inline-flex items-center justify-center rounded border transition-colors h-[18px] w-[18px] disabled:opacity-50",s===1?"border-foreground bg-foreground text-background":"border-border text-muted-foreground hover:text-foreground hover:border-foreground
1/40"),children:e.jsx($t,{className:"h-2.5 w-2.5"})})}),e.jsx(Ce,{className:"max-w-xs text-xs leading-snug",children:"Relevant — tells the radar this is on-territory. Your votes feed back into future scoring."})]}),e.jsxs(Ne,{children:[e.jsx(we,{asChild:!0,children:e.jsx("button",{type:"button",disabled:r,onClick:i=>{n(i),a(-1)},"aria-pressed":s===-1,"aria-label":"Mark as not relevant",className:_e("inline-flex items-center justify-center rounded border transition-colors h-[18px] w-[18px] disabled:opacity-50",s===-1?"border-destructive bg-destructive text-destructive-foreground":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/40"),children:e.jsx(Qt,{className:"h-2.5 w-2.5"})})}),e.jsx(Ce,{className:"max-w-xs text-xs leading-snug",children:"Not relevant — tells the radar to down-weight this and things like it."})]})]})})}const qe=[{name:"name",label:"Name",type:"text",required:!0,placeholder:"e.g. Soft brutalism"},{name:"brief",label:"Brief",type:"textarea",rows:3,placeholder:"One paragraph describing the root"},{name:"category",label:"Category",type:"text",placeholder:"Design, music, etc."},{name:"source",label:"Source",type:"text",placeholder:"Where you spotted it"},{name:"url",label:"URL",type:"url",placeholder:"https://…"},{name:"tier",label:"Tier",type:"select",options:[{value:"edge",label:"Edge"},{value:"early",label:"Early"},{value:"mainstream",label:"Mainstream"}]},{name:"maturity",label:"Maturity",type:"select",required:!0,options:[{value:"emerging",label:"Emerging"},{value:"growing",label:"Growing"},{value:"peak",label:"Peak"},{value:"declining",label:"Declining"}]},{name:"status",label:"Status",type:"select",options:[{value:"active",label:"Active"},{value:"archived",label:"Archived"}]},{name:"momentum",label:"Velocity (0–100)",type:"number",min:0,max:100},{name:"delta",label:"Δ %",type:"number",step:.1},{name:"relevance",label:"Relevance (0–100)",type:"number",min:0,max:100},{name:"reach",label:"Reach",type:"text",placeholder:"e.g. 1.2M"},{name:"tags",label:"Tags",type:"tags"}],Wt=["instagram","youtube","tiktok","substack","twitter","linkedin","threads","twitch","pinterest","podcast"],Zt=[{name:"name",label:"Name",type:"text",required:!0},{name:"handle",label:"Handle",type:"text",placeholder:"@username"},{name:"niche",label:"Niche",type:"text"},{name:"platforms",label:"Platforms",type:"tags",placeholder:"TikTok, Instagram, Substack"},{name:"audience_size",label:"Audience size",type:"text",placeholder:"1.2M"},{name:"growth",label:"Growth %",type:"number",step:.1},{name:"fit_score",label:"Fit score (0–100)",type:"number",min:0,max:100},{name:"relevance_score",label:"Relevance score (0–100)",type:"number",min:0,max:100},{name:"tags",label:"Tags",type:"tags"},{name:"avatar_url",label:"Avatar URL",type:"text",placeholder:"https://…"},{name:"profile_url",label:"Primary profile URL",type:"text",placeholder:"https://…"},...Wt.map(s=>({name:`platform_url_${s}`,label:`${s.charAt(0).toUpperCase()+s.slice(1)} URL`,type:"text",placeholder:"https://…"})),{name:"notes",label:"Notes",type:"textarea",rows:3}],Jt=[{name:"name",label:"Name",type:"text",required:!0},{name:"last_move",label:"Last move",type:"textarea",rows:2,placeholder:"What did they ship / say / file?"},{name:"url",label:"URL",type:"url",placeholder:"https://…"},{name:"move_type",label:"Move type",type:"text",placeholder:"Launch, Campaign, Partnership…"},{name:"threat_level",label:"Threat level",type:"select",options:[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}]}];function Xt(s){return[{name:"headline",label:"Headline",type:"text",required:!0},{name:"detail",label:"Detail",type:"textarea",rows:3},{name:"source",label:"Source",type:"text",required:!0,placeholder:"TikTok, Reddit, NYT…"},{name:"url",label:"URL",type:"url"},{name:"type",label:"Type",type:"select",required:!0,options:[{value:"spike",label:"Spike"},{value:"shift",label:"Shift"},{value:"weak",label:"Weak signal"},{value:"alert",label:"Risk"}]},{name:"forecast_id",label:"Link to roots",type:"select",options:[{value:"",label:"— none —"},...s.map(a=>({value:a.id,label:a.name}))]},{name:"weight",label:"Weight",type:"number",min:0,max:100,step:1},{name:"delta",label:"Δ %",type:"number",step:.1}]}const I={snapshots:s=>["pi:quarterly",s??"none"],competitors:s=>["pi:competitors",s??"none"]};function es(s=new Date){return`${s.getUTCFullYear()}-Q${Math.floor(s.getUTCMonth()/3)+1}`}function q(s){const[a,r]=s.split("-Q");return`Q${r} ${a}`}function Se(s){return typeof s=="number"?Math.round((s-100)*10)/10:null}function ts(s){return s==="category"?"Category = 100":"Your baseline = 100"}function Qe(s){return P({queryKey:I.snapshots(s),enabled:!!s,queryFn:async()=>{const{data:a,error:r}=await _.from("pi_quarterly_snapshots").select("*").eq("org_id",s).order("quarter",{ascending:!0}).order("created_at",{ascending:!0});if(r)throw r;return a??[]}})}function Ve(s){const a=new Map;for(const r of s)a.set(`${r.entity_type}:${r.entity_name.toLowerCase()}:${r.quarter}`,r);return Array.from(a.values())}function ze(s){return P({queryKey:I.competitors(s),enabled:!!s,queryFn:async()=>{const{data:a,error:r}=await _.from("pi_competitors").select("id, org_id, name, domains, handles, notes").eq("org_id",s).order("name",{ascending:!0});if(r)throw r;return a??[]}})}function ss(){const s=ie();return oe({mutationFn:async a=>{const r={org_id:a.orgId,name:a.name,domains:a.domains,handles:a.handles},{error:n}=a.id?await _.from("pi_competitors").update(r).eq("id",a.id):await _.from("pi_competitors").insert(r);if(n)throw n},onSuccess:(a,r)=>
1s.invalidateQueries({queryKey:I.competitors(r.orgId)})})}function as(){const s=ie();return oe({mutationFn:async a=>{const{error:r}=await _.from("pi_competitors").delete().eq("id",a.id);if(r)throw r},onSuccess:(a,r)=>s.invalidateQueries({queryKey:I.competitors(r.orgId)})})}function rs(){const s=ie();return oe({mutationFn:async a=>{const{data:r,error:n}=await _.functions.invoke("pi-quarterly-index",{body:{org_id:a.orgId,quarter:a.quarter,dry_run:a.dryRun??!1,correction:a.correction??!1,notes:a.notes}});if(n)throw n;const i=r;if((i==null?void 0:i.ok)===!1)throw new Error(i.error??"Could not compute the quarterly index");return r},onSuccess:(a,r)=>{s.invalidateQueries({queryKey:I.snapshots(r.orgId)})}})}function ns({className:s}){const{org:a}=K(),r=le(),{data:n=[],isLoading:i}=Qe(a==null?void 0:a.id),m=rs(),[h,x]=u.useState(null),f=u.useMemo(()=>Ve(n).filter(j=>j.entity_type==="brand").sort((j,y)=>j.quarter.localeCompare(y.quarter)),[n]),l=f.at(-1)??null,p=f.at(-2)??null,c=es(),b=(l==null?void 0:l.quarter)===c,A=async j=>{var y;if(a!=null&&a.id)try{const N=await m.mutateAsync({orgId:a.id,dryRun:j});if(j){const v=(y=N.rows)==null?void 0:y.find(G=>G.entity_type==="brand");x({quarter:N.quarter,value:(v==null?void 0:v.indexed_value)??null,basis:N.basis}),F.success(`Preview ready for ${q(N.quarter)} — nothing published yet`)}else x(null),F.success(`${q(N.quarter)} published`)}catch(N){F.error(N.message)}};return e.jsx(Ae,{className:s,children:e.jsxs(Le,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"The Quarterly Index"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1 max-w-xl",children:"Every scored root in this workspace, rolled into one number for the quarter and rebased so the comparison sits at 100. It answers one question: is our cultural position strengthening or weakening?"})]}),e.jsxs($e,{variant:"outline",className:"text-[10px] font-normal shrink-0",children:["v",ht]})]}),i?e.jsx("p",{className:"text-sm text-muted-foreground mt-4",children:"Loading…"}):l?e.jsxs("div",{className:"mt-4 flex flex-wrap items-end gap-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-medium tabular-nums leading-none",children:l.indexed_value??"—"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:[q(l.quarter)," · ",ts(l.basis)]})]}),(p==null?void 0:p.indexed_value)!=null&&l.indexed_value!=null&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-1",children:["vs ",q(p.quarter)]}),e.jsx(H,{value:Math.round((l.indexed_value-p.indexed_value)*10)/10,suffix:" pts"})]}),Se(l.indexed_value)!==null&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-1",children:["vs ",l.basis==="category"?"category":"baseline"]}),e.jsx(H,{value:Se(l.indexed_value),suffix:" pts"})]}),f.length>1&&e.jsxs("div",{className:"ml-auto",children:[e.jsx(Et,{values:f.map(j=>Number(j.indexed_value??0)),height:34}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/70 mt-1 text-right",children:[f.length," quarters"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground mt-4",children:"No quarter published yet. The first published quarter becomes this workspace's baseline at 100, and every quarter after it is read against the category."}),l&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-4 border-t border-border pt-3",children:["Basket: ",l.basket_size," root",l.basket_size===1?"":"s",l.insufficient_evidence&&" — thin evidence this quarter, read with care",l.is_correction&&" · restated",l.basis_note?` · ${l.basis_note}`:""]}),r&&e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>A(!0),disabled:m.isPending,children:["Preview ",q(c)]}),e.jsx(S,{size:"sm",onClick:()=>A(!1),disabled:m.isPending,children:b?"Publish correction":`Publish ${q(c)}`}),h&&e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["Preview: ",h.value??"—"," (",h.basis," basis) — not published"]})]})]})})}function Pe(s){return s.split(/[,\s]+/).map(a=>
1a.trim().replace(/^@/,"").replace(/^www\./,"")).filter(Boolean)}function ls(){const{org:s}=K(),{data:a=[]}=ze(s==null?void 0:s.id),r=ss(),n=as(),[i,m]=u.useState(""),[h,x]=u.useState(""),[f,l]=u.useState(""),p=async()=>{if(!(!(s!=null&&s.id)||!i.trim()))try{await r.mutateAsync({orgId:s.id,name:i.trim(),domains:Pe(h),handles:Pe(f)}),m(""),x(""),l(""),F.success("Competitor added — it will be scored on the next quarterly run")}catch(c){F.error(c.message)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{value:i,onChange:c=>m(c.target.value),placeholder:"Competitor name",className:"text-sm"}),e.jsx(M,{value:h,onChange:c=>x(c.target.value),placeholder:"Domains (comma separated) — e.g. nike.com, nikesb.com",className:"text-sm"}),e.jsx(M,{value:f,onChange:c=>l(c.target.value),placeholder:"Handles (comma separated) — e.g. @nike, nikerunning",className:"text-sm"}),e.jsx(S,{size:"sm",onClick:p,disabled:!i.trim()||r.isPending,children:"Add competitor"})]}),a.length>0&&e.jsx("ul",{className:"divide-y divide-border rounded-md border border-border",children:a.map(c=>e.jsxs("li",{className:"flex items-start justify-between gap-3 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium",children:c.name}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5 truncate",children:[...c.domains??[],...(c.handles??[]).map(b=>`@${b}`)].join(", ")||"No domains or handles yet"})]}),e.jsx(S,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>(s==null?void 0:s.id)&&n.mutate({id:c.id,orgId:s.id}),"aria-label":`Remove ${c.name}`,children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]},c.id))})]})}function is({className:s}){const{org:a}=K(),r=le(),{data:n=[],isLoading:i}=Qe(a==null?void 0:a.id),{data:m=[]}=ze(a==null?void 0:a.id),{quarter:h,standings:x}=u.useMemo(()=>{const l=Ve(n),p=l.map(b=>b.quarter).sort().at(-1)??null,c=l.filter(b=>b.quarter===p).sort((b,A)=>Number(A.indexed_value??-1)-Number(b.indexed_value??-1));return{quarter:p,standings:c}},[n]),f=Math.max(100,...x.map(l=>Number(l.indexed_value??0)));return e.jsx(Ae,{className:s,children:e.jsxs(Le,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Territory Position"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1 max-w-xl",children:"Your competitive set scored on the same five inputs, inside your territories, using only evidence already on your radar. The category mean is 100."})]}),r&&e.jsxs(Ee,{children:[e.jsx(ft,{asChild:!0,children:e.jsxs(S,{size:"sm",variant:"outline",className:"shrink-0",children:["Competitive set (",m.length,")"]})}),e.jsxs(Re,{children:[e.jsxs(De,{children:[e.jsx(Fe,{children:"Competitive set"}),e.jsx(Ie,{children:"Domains and handles are how we attribute radar evidence to a competitor. The more precise these are, the more defensible the position."})]}),e.jsx(ls,{})]})]})]}),i?e.jsx("p",{className:"text-sm text-muted-foreground mt-4",children:"Loading…"}):x.length?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[11px] text-muted-foreground mt-4 mb-2",children:h?q(h):""}),e.jsx("ul",{className:"space-y-2",children:x.map(l=>{const p=Number(l.indexed_value??0),c=l.entity_type==="brand";return e.jsxs("li",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:`text-xs w-36 shrink-0 truncate ${c?"font-medium text-foreground":"text-muted-foreground"}`,children:[l.entity_name,c&&e.jsx("span",{className:"ml-1 text-[10px] text-muted-foreground",children:"you"})]}),e.jsx("span",{className:"relative h-2 flex-1 rounded-full bg-muted overflow-hidden",children:e.jsx("span",{className:`absolute inset-y-0 left-0 rounded-full ${c?"bg-primary":"bg-muted-foreground/40"}`,style:{width:`${Math.max(2,p/f*100)}%`}})}),e.jsx("span",{className:"text-xs tabular-nums w-10 text-right",children:l.indexed_value??"—"}),l.insufficient_evidence&&e.jsx($e,{variant:"outline",className:"text-[10px] font-normal shrink-0",children:"thin"})]},`${l.entity_type}-${l.entity_name}`)})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-4 border-t border-border pt-3",children:'"Thin" means fewer than three territories carried enough attributable evidence that quarter — the number is published, but treat it as directional.'})]}):e.jsx("p",{className:"text-sm text-muted-foreground mt-4",children:"No standings yet. Add your competitive set, then publish a quarter to see where you sit against it."})]})})}function os({radar:s}={}){const a=le(),{activeRadar:r}=Te(),n=s??r,i=gt();return!a||!n?null:e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground","aria-label":"Workspace settings",onClick:()=>i("/workspace/settings"),children:e.jsx(zt,{className:"h-4 w-4"})})}function D({title:s,hint:a,right:r}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[" ",e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("h2",{className:"text-sm font-medium text-foreground",children:s}),a&&e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:a})]}),r]})}function ds({text:s,title:a}){const r=u.useRef(null),[n,i]=u.useState(!1),[m,h]=u.useState(!1);return u.useLayoutEffect(()=>{const x=r.current;if(!x)return;const f=()=>i(x.scrollHeight-x.clientHeight>1);f();const l=new ResizeObserver(f);
1return l.observe(x),()=>l.disconnect()},[s]),e.jsxs("div",{className:"mt-3 max-w-2xl",children:[e.jsx("p",{ref:r,className:"text-sm text-muted-foreground line-clamp-3",children:s}),n&&e.jsx("button",{type:"button",onClick:()=>h(!0),className:"mt-1 text-xs font-medium text-foreground/80 hover:text-foreground underline underline-offset-2",children:"Read more …"}),e.jsx(Ee,{open:m,onOpenChange:h,children:e.jsxs(Re,{className:"max-w-2xl",children:[e.jsxs(De,{children:[e.jsx(Fe,{className:"font-redaction italic text-2xl",children:a}),e.jsx(Ie,{className:"text-[10px] uppercase tracking-[0.18em]",children:"RADAR"})]}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap leading-relaxed",children:s})]})})]})}function Oe(s){var r;if(typeof s.pi_score=="number"&&isFinite(s.pi_score))return Math.round(s.pi_score);const a=(r=s.raw_meta)==null?void 0:r.relevance;return typeof a=="number"&&isFinite(a)?Math.round(a*100):null}const Me=s=>Oe(s)??-1;function Ds(){var ye;const{org:s,role:a,isPlatformAdmin:r}=K(),n=s==null?void 0:s.id,{activeRadar:i}=Te(),m=a==="admin"||r,h=m||a==="owner",[x,f]=u.useState("list"),{data:l=[]}=bt(n),{data:p=[]}=jt(n),{data:c=[]}=yt(n),b=(i==null?void 0:i.id)??null,j=n==="b6c87b2f-4818-4310-8fa3-810920678158"?.62:.4,{data:y}=P({queryKey:["radar-seeds",n,b,j],enabled:!!n,queryFn:async()=>{const{data:t,error:o}=await _.functions.invoke("radar-seeds",{body:{org_id:n,radar_id:b,limit:24,min_semantic:j}});if(o)throw o;return t},staleTime:5*6e4}),N=((ye=y==null?void 0:y.items)==null?void 0:ye.length)??0,{data:v=[]}=vt(n),{data:G=[]}=Nt(n),{data:de=[]}=P({queryKey:re.projects(n??null),queryFn:()=>At(n),enabled:!!n}),{data:ce=[]}=P({queryKey:re.sidebarQuestions(n??null),enabled:!!n,queryFn:async()=>{const{data:t}=await _.from("question_credits").select("id, slug, question_number, question_text, processing_status").eq("org_id",n).in("processing_status",["idle","ready"]).order("question_number",{ascending:!0}).limit(50);return t??[]}}),{data:ue=[]}=P({queryKey:re.sidebarDebriefs(n??null),enabled:!!n,queryFn:async()=>{const{data:t}=await _.from("debriefs").select("id, slug, title, status, updated_at, created_at").eq("org_id",n).neq("status","cancelled").order("created_at",{ascending:!1}).limit(50);return t??[]}}),T=l,L=p,E=c,me=(y==null?void 0:y.items)??[];v.slice(0,4),G.slice(0,3),de.slice(0,5),ce.slice(0,5),ue.slice(0,5);const[Y,Ue]=u.useState(""),[$,Be]=u.useState("all"),He=u.useMemo(()=>Array.from(new Set(L.map(t=>t.source).filter(Boolean))).sort(),[L]),xe=u.useMemo(()=>{const t=Y.trim().toLowerCase();return L.filter(o=>$!=="all"&&o.source!==$?!1:t?(o.headline??"").toLowerCase().includes(t)||(o.source??"").toLowerCase().includes(t):!0).sort((o,g)=>Me(g)-Me(o))},[L,Y,$]),[W,Ke]=u.useState(""),[Q,Ge]=u.useState("all"),Ye=u.useMemo(()=>Array.from(new Set(E.map(t=>{var o;return(o=t.niche)==null?void 0:o.trim()}).filter(Boolean))).sort(),[E]),pe=u.useMemo(()=>{const t=W.trim().toLowerCase();return E.filter(o=>Q!=="all"&&(o.niche??"")!==Q?!1:t?(o.name??"").toLowerCase().includes(t)||(o.handle??"").toLowerCase().includes(t)||(o.niche??"").toLowerCase().includes(t):!0)},[E,W,Q]),[Z,We]=u.useState(""),[V,Ze]=u.useState("all"),he=u.useMemo(()=>{const t=Z.trim().toLowerCase();return v.filter(o=>V!=="all"&&(o.threat_level??"")!==V?!1:t?(o.name??"").toLowerCase().includes(t)||(o.last_move??"").toLowerCase().includes(t)||(o.move_type??"").toLowerCase().includes(t):!0)},[v,Z,V]),Je=wt(),Xe=_t(),et=Ct(),tt=kt(),st=qt(),at=St(),rt=Pt(),nt=Mt(),[d,J]=u.useState(null),lt=d!==null,R=(t,o)=>J({kind:t,row:o}),[fe,it]=u.useState({}),[ge,ot]=u.useState({}),[be,dt]=u.useState({}),[je,ct]=u.useState({});function z(t,o,g,k,w,X){const ve=k===X;g(xt=>({...xt,[w.id]:ve?void 0:X})),Ut({surface:t,vote:ve?0:X,entity_type:o,entity_id:w.id,entity_label:w.label??null,entity_url:w.url??null,radar_id:(i==null?void 0:i.id)??null,radar_name:(i==null?void 0:i.name)??null})}const ut=u.useMemo(()=>Xt(l.map(t=>({id:t.id,name:t.name}))),[l]),mt=l.length||p.length||c.length||v.length;return de.length||ce.length||ue.length,e.jsxs(Lt,{children:[i&&e.jsxs("section",{className:"relative mb-8 md:mb-10 rounded-2xl border border-border bg-gradient-to-br from-muted/40 via-card to-card p-5 sm:p-6 md:p-8",children:[m&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3",children:e.jsx(os,{})}),e.jsx("p",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground mb-2",children:"RADAR"}),e.jsx("h2",{className:`font-redaction italic text-2xl sm:text-3xl md:text-4xl text-foreground leading-tight ${m?"pr-10 sm:pr-12":""}`,children:i.name}),i.theme_prompt&&e.jsx(ds,{text:i.theme_prompt,title:i.name})]}),e.jsxs("div",{id:"dashboard",className:"grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4 gap-3 mb-8 md:mb-10",children:[e.jsx(O,{label:"Seeds",value:N,delta:"ranked above threshold",href:"#seeds"}),e.jsx(O,{label:"Signals",value:p.length,delta:"across all sources",href:"#signals"}),e.jsx(O,{label:"Creators",value:c.length,delta:`${c.filter(t=>(t.fit_score??0)>=90).length} ≥90 PI`,href:"#creators"}),e.jsx(O,{label:"Competitors",value:v.length,delta:`${v.filter(t=>t.threat_level==="high").length} high threat`,href:"#competitors"})]}),mt?e.jsxs("section",{className:"mb-12 space-y-10 min-w-0",children:[e.jsxs("div",{id:"roots",className:"scroll-mt-24 min-w-0",children:[e.jsx(D,{title:"Roots"}),e.jsx("div",{className:"mb-3",children:e.jsxs(Yt,{type:"single",value:x,onValueChange:t=>t&&f(t),variant:"outline",size:"sm",children:[e.jsx(ke,{value:"list",className:"text-xs px-3",children:"List"}),e.jsxs(ke,{value:"quadrant",className:"text-xs px-3 leading-tight text-center",children:["Quadrant",e.jsx("br",{})," [still in beta]"]})]})}),x==="quadrant"?e.jsx(Kt,{items:T,onSelect:m?t=>{const o=T.find(g=>g.id===t.id);o&&R("forecast",o)}:void 0}):e.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[T.map(t=>{const o=Math.max(0,Math.min(100,Number(t.momentum)||0));return e.jsxs("article",{className:"rounded-lg border border-border bg-card p-4 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2 flex-wrap",children:[e.jsx("p",{className:"font-medium text-foreground truncate flex-1 min-w-0",title:t.name,children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[e.jsx(Bt,{row:t}),e.jsx(Gt,{score:t.pi_score,maturity:t.maturity}),e.jsx(Rt,{value:t.maturity}),e.jsx(B,{vote:fe[t.id],onVote:g=>z("forecast","forecast",it,fe[t.id],{id:t.id,label:t.name,url:t.url},g)}),m&&e.jsx(U,{canEdit:!0,size:"sm",label:t.name,onEdit:()=>R("forecast",t),onDelete:()=>Xe.mutateAsync({orgId:n,id:t.id})})]})]}),t.brief&&e.jsx("p",{className:"text-xs text-muted-foreground mb-3 sm:w-3/4",children:t.brief}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1.5",children:[e.jsxs("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:[e.jsx(Dt,{metric:"momentum",children:"Velocity"})," ",o]}),e.jsx(H,{value:Number(t.delta)})]}),e.jsx(Ft,{value:o})]},t.id)}),T.length===0&&e.jsx("p",{className:"p-6 text-sm text-muted-foreground rounded-lg border border-border",children:"No roots yet."})]})]}),me.length>
10&&e.jsxs("div",{id:"seeds",className:"scroll-mt-24 min-w-0 w-full overflow-hidden",children:[e.jsx(D,{title:"Seeds"}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 snap-x snap-mandatory scrollbar-none",children:me.map(t=>e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"snap-start shrink-0 w-72 rounded-lg border border-border bg-card hover:border-foreground/30 transition-colors overflow-hidden flex flex-col",children:[t.feature_image?e.jsx("div",{className:"aspect-[16/9] bg-muted overflow-hidden",children:e.jsx("img",{src:t.feature_image,alt:"",className:"w-full h-full object-cover",loading:"lazy"})}):e.jsx("div",{className:"aspect-[16/9] bg-muted"}),e.jsxs("div",{className:"p-3 flex-1 flex flex-col gap-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground line-clamp-2 leading-snug",children:t.title}),t.excerpt&&e.jsx("p",{className:"text-[11px] text-muted-foreground line-clamp-2",children:t.excerpt})]})]},t.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8 min-w-0",children:[e.jsxs("div",{id:"signals",className:"scroll-mt-24 min-w-0",children:[e.jsx(D,{title:"Signals"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[160px]",children:[e.jsx(ne,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(M,{placeholder:"Search signals…",value:Y,onChange:t=>Ue(t.target.value),className:"h-9 pl-8 text-xs"})]}),e.jsxs(ee,{value:$,onValueChange:Be,children:[e.jsx(te,{className:"h-9 w-[150px] text-xs",children:e.jsx(se,{placeholder:"Source"})}),e.jsxs(ae,{children:[e.jsx(C,{value:"all",children:"All sources"}),He.map(t=>e.jsx(C,{value:t,children:t},t))]})]})]}),e.jsxs("div",{className:"rounded-lg border border-border divide-y divide-border overflow-y-auto",style:{maxHeight:"calc(10 * 4.5rem)"},children:[xe.map(t=>{const o=Oe(t),g=t.url??void 0;return e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(It,{value:t.type}),e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground truncate",children:t.source})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[o!=null&&e.jsx("span",{title:"PI",className:"inline-flex items-center justify-center h-6 w-6 rounded-full border border-border bg-muted/40 text-[10px] tabular-nums text-foreground",children:o}),t.delta!=null&&e.jsx(H,{value:Number(t.delta)}),e.jsx(B,{vote:ge[t.id],onVote:k=>z("signals","signal",ot,ge[t.id],{id:t.id,label:t.headline,url:t.url},k)}),m&&e.jsx(U,{canEdit:!0,size:"sm",label:t.headline,onEdit:()=>R("signal",t),onDelete:()=>tt.mutateAsync({orgId:n,id:t.id})})]})]}),g?e.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-foreground leading-snug hover:underline underline-offset-2",children:t.headline}):e.jsx("p",{className:"text-sm text-foreground leading-snug",children:t.headline})]},t.id)}),xe.length===0&&e.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:L.length===0?"No signals yet.":"No signals match your filters."})]})]}),e.jsxs("div",{id:"creators",className:"scroll-mt-24 min-w-0",children:[e.jsx(D,{title:"Creators"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[160px]",children:[e.jsx(ne,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(M,{placeholder:"Search creators…",value:W,onChange:t=>Ke(t.target.value),className:"h-9 pl-8 text-xs"})]}),e.jsxs(ee,{value:Q,onValueChange:Ge,children:[e.jsx(te,{className:"h-9 w-[150px] text-xs",children:e.jsx(se,{placeholder:"Niche"})}),e.jsxs(ae,{children:[e.jsx(C,{value:"all",children:"All niches"}),Ye.map(t=>e.jsx(C,{value:t,children:t},t))]})]})]}),e.jsxs("div",{className:"rounded-lg border border-border divide-y divide-border overflow-y-auto",style:{maxHeight:"calc(10 * 4.5rem)"},children:[pe.map(t=>{const o=t.platform_urls&&typeof t.platform_urls=="object"&&!Array.isArray(t.platform_urls)?t.platform_urls:{},g=Object.values(o).find(w=>typeof w=="string"&&w.length>
10),k=t.profile_url??g??void 0;return e.jsxs("div",{className:"p-3 flex items-center justify-between gap-3",children:[" ",e.jsxs("div",{className:"min-w-0",children:[k?e.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-foreground truncate hover:underline underline-offset-2 block",children:t.name}):e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.name}),e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:[t.handle??"—",t.niche?` · ${t.niche}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 shrink-0 flex-wrap justify-end",children:[t.audience_size&&e.jsx("span",{className:"text-[11px] tabular-nums text-muted-foreground",title:"Followers",children:t.audience_size}),t.fit_score!=null&&e.jsx("span",{title:"PI",className:"inline-flex items-center justify-center h-6 w-6 rounded-full border border-border bg-muted/40 text-[10px] tabular-nums text-foreground",children:t.fit_score}),e.jsx(B,{vote:be[t.id],onVote:w=>z("creators","creator",dt,be[t.id],{id:t.id,label:t.name,url:k??null},w)}),m&&e.jsx(U,{canEdit:!0,size:"sm",label:t.name,onEdit:()=>R("creator",t),onDelete:()=>at.mutateAsync({orgId:n,id:t.id})})]})]},t.id)}),pe.length===0&&e.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:E.length===0?"No creators yet.":"No creators match your filters."})]})]})]}),e.jsxs("div",{id:"competitors",className:"scroll-mt-24 min-w-0",children:[e.jsx(D,{title:"Competitors",right:h?e.jsxs(S,{size:"sm",variant:"outline",className:"h-8 gap-1.5 text-xs",onClick:()=>J({kind:"competitor",row:null}),children:[e.jsx(Ot,{className:"h-3.5 w-3.5"})," Log move"]}):void 0}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[160px]",children:[e.jsx(ne,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(M,{placeholder:"Search competitors…",value:Z,onChange:t=>We(t.target.value),className:"h-9 pl-8 text-xs"})]}),e.jsxs(ee,{value:V,onValueChange:Ze,children:[e.jsx(te,{className:"h-9 w-[150px] text-xs",children:e.jsx(se,{placeholder:"Threat"})}),e.jsxs(ae,{children:[e.jsx(C,{value:"all",children:"All threats"}),e.jsx(C,{value:"high",children:"High"}),e.jsx(C,{value:"medium",children:"Medium"}),e.jsx(C,{value:"low",children:"Low"})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-border divide-y divide-border overflow-y-auto",style:{maxHeight:"calc(5 * 4.5rem)"},children:[he.map(t=>{const o=t.url??void 0;return e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o?e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-foreground truncate hover:underline underline-offset-2",children:t.name}):e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.name}),t.move_type&&e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:t.move_type})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[t.threat_level&&e.jsx("span",{className:`text-[10px] tracking-wide capitalize px-1.5 py-0.5 rounded ${t.threat_level==="high"?"text-rose-700 dark:text-rose-300 bg-rose-500/10":t.threat_level==="medium"?"text-amber-700 dark:text-amber-300 bg-amber-500/10":"text-sky-700 dark:text-sky-300 bg-sky-500/10"}`,children:t.threat_level}),e.jsx(B,{vote:je[t.id],onVote:g=>z("competitors","competitor",ct,je[t.id],{id:t.id,label:t.name,url:t.url},g)}),h&&e.jsx(U,{canEdit:!0,size:"sm",label:t.name,onEdit:()=>R("competitor",t),onDelete:()=>nt.mutateAsync({orgId:n,id:t.id})})]})]}),t.last_move&&e.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:t.last_move})]},t.id)}),he.length===0&&e.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:v.length===0?"No competitors yet.":"No competitors match your filters."})]})]}),e.jsx(Ht,{}),e.jsxs("div",{id:"quarterly-index",className:"scroll-mt-24 min-w-0 grid gap-4 lg:grid-cols-2",children:[e.jsx(ns,{}),e.jsx(is,{})]})]}):null,(m||(d==null?void 0:d.kind)==="competitor")&&e.jsx(Tt,{open:lt,onOpenChange:t=>{t||J(null)},title:(d==null?void 0:d.kind)==="forecast"?"Edit root":(d==null?void 0:d.kind)==="signal"?"Edit signal":(d==null?void 0:d.kind)==="creator"?"Edit creator":(d==null?void 0:d.kind)==="competitor"?"Edit move":"Edit",fields:(d==null?void 0:d.kind)==="forecast"?qe:(d==null?void 0:d.kind)==="signal"?ut:(d==null?void 0:d.kind)==="creator"?Zt:(d==null?void 0:d.kind)==="competitor"?Jt:qe,
1initial:(d==null?void 0:d.row)??null,onSubmit:async t=>{if(!(!n||!d))switch(d.kind){case"forecast":await Je.mutateAsync({orgId:n,values:t});break;case"signal":await et.mutateAsync({orgId:n,values:t});break;case"creator":await st.mutateAsync({orgId:n,values:t});break;case"competitor":await rt.mutateAsync({orgId:n,values:t});break}}})]})}export{Ds as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.