nexus-shell 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/components/graph/GraphEdge.d.ts +2 -0
- package/dist/components/properties/FieldShell.d.ts +65 -0
- package/dist/components/properties/PropertyPanel.d.ts +132 -0
- package/dist/components/properties/fields.d.ts +101 -0
- package/dist/components/properties/index.d.ts +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/lib/properties.d.ts +67 -0
- package/dist/nexus-shell.es.js +2316 -1684
- package/dist/nexus-shell.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/nexus-shell.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("flexlayout-react"),require("flexlayout-react/style/light.css"),require("lucide-react"),require("clsx"),require("tailwind-merge"),require("zustand"),require("react-virtuoso")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","flexlayout-react","flexlayout-react/style/light.css","lucide-react","clsx","tailwind-merge","zustand","react-virtuoso"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.NexusShell={},m.jsxRuntime,m.React,m.FlexLayout,null,m.lucideReact,m.clsx,m.tailwindMerge,m.zustand,m.reactVirtuoso))})(this,function(m,r,g,F,br,P,xt,yt,X,Ee){"use strict";var pr=Object.defineProperty;var mr=(m,r,g)=>r in m?pr(m,r,{enumerable:!0,configurable:!0,writable:!0,value:g}):m[r]=g;var R=(m,r,g)=>mr(m,typeof r!="symbol"?r+"":r,g);function A(...t){return yt.twMerge(xt.clsx(t))}const vt=[{id:"settings",label:"Settings",icon:P.Settings}],Se=({items:t=[],bottomItems:e=vt,activeId:n=null,onSelect:s,className:a,"aria-label":o="Activity Bar"})=>{const i=({id:d,label:c,icon:l})=>r.jsx("button",{type:"button",onClick:()=>s==null?void 0:s(d),"aria-label":c,title:c,"aria-pressed":n===d,className:A("p-2 cursor-pointer rounded text-muted-foreground hover:text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",n===d&&"text-foreground border-l-2 border-primary rounded-none"),children:r.jsx(l,{size:20})},d);return r.jsxs("aside",{role:"navigation","aria-label":o,className:A("w-12 h-full bg-muted border-r flex flex-col items-center py-2 select-none",a),children:[r.jsx("div",{className:"flex-1 flex flex-col space-y-4",children:t.map(i)}),e.length>0&&r.jsx("div",{className:"flex flex-col space-y-4",children:e.map(i)})]})},re="nexus-shell-sidebar",W=X.create(t=>{const e=localStorage.getItem(re);return{activeSidebar:e!==null?e:null,panels:[],setActiveSidebar:s=>{s===null?localStorage.removeItem(re):localStorage.setItem(re,s),t({activeSidebar:s})},toggleSidebar:s=>t(a=>{const o=a.activeSidebar===s?null:s;return o===null?localStorage.removeItem(re):localStorage.setItem(re,o),{activeSidebar:o}}),setPanels:s=>t({panels:s})}}),Te=t=>{const e=W(o=>o.panels),n=W(o=>o.activeSidebar),s=W(o=>o.toggleSidebar),a=g.useMemo(()=>e.map(({id:o,label:i,icon:d})=>({id:o,label:i,icon:d})),[e]);return r.jsx(Se,{...t,items:a,activeId:n,onSelect:s})},wt=r.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center px-6 text-muted-foreground",children:[r.jsx(P.MessageCircle,{size:28,className:"mb-3 opacity-40"}),r.jsx("p",{className:"text-xs",children:"No messages yet."}),r.jsxs("p",{className:"text-[11px] mt-1 opacity-70",children:["Type a message, or ",r.jsx("span",{className:"font-mono",children:"/"})," for commands."]})]}),Ce=({messages:t=[],onSend:e,slashCommands:n=[],onSlashCommand:s,onClose:a,title:o="Chat",placeholder:i="Send a message…",emptyState:d=wt,className:c})=>{const[l,x]=g.useState(""),[p,u]=g.useState(0),N=g.useRef(null),k=g.useRef(null),v=l.startsWith("/")?n.filter(f=>`/${f.command}`.startsWith(l.toLowerCase().split(" ")[0])):[],b=v.length>0;g.useEffect(()=>{k.current&&(k.current.scrollTop=k.current.scrollHeight)},[t]),g.useEffect(()=>{u(0)},[l]);const w=()=>{const f=l.trim();f&&(e==null||e(f),x(""))},E=f=>{var M;s==null||s(f),x(`/${f.command} `),(M=N.current)==null||M.focus()},y=f=>{if(b){if(f.key==="ArrowDown"){f.preventDefault(),u(M=>(M+1)%v.length);return}if(f.key==="ArrowUp"){f.preventDefault(),u(M=>(M-1+v.length)%v.length);return}if(f.key==="Tab"||f.key==="Enter"&&!f.shiftKey){f.preventDefault(),E(v[p]);return}}f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),w())};return r.jsxs("aside",{role:"complementary","aria-label":o,className:A("w-[320px] h-full bg-muted border-l border-border flex flex-col select-none shrink-0",c),children:[r.jsxs("div",{className:"h-10 flex items-center justify-between px-4 shrink-0",children:[r.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[r.jsx(P.MessageCircle,{size:13}),r.jsx("span",{className:"text-[11px] font-bold uppercase tracking-widest",children:o})]}),a&&r.jsx("button",{type:"button",onClick:a,"aria-label":"Close Chat",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(P.X,{size:14})})]}),r.jsx("div",{ref:k,role:"log","aria-label":`${o} transcript`,className:"flex-1 overflow-y-auto border-t border-border/50 bg-background/50 px-3 py-3 space-y-3",children:t.length===0?d:t.map(f=>{const M=f.role==="user";return r.jsxs("div",{className:A("flex flex-col",M?"items-end":"items-start"),children:[r.jsxs("div",{className:"flex items-center space-x-1 mb-1 text-[10px] uppercase tracking-wider text-muted-foreground font-bold",children:[M?r.jsx(P.User,{size:10}):r.jsx(P.Terminal,{size:10}),r.jsx("span",{children:f.author??(M?"You":"Assistant")})]}),r.jsx("div",{className:A("max-w-[85%] rounded-lg px-3 py-2 text-xs whitespace-pre-wrap break-words",M?"bg-primary text-primary-foreground":"bg-card border border-border text-foreground"),children:f.text})]},f.id)})}),r.jsxs("div",{className:"relative border-t border-border/50 p-2 shrink-0",children:[b&&r.jsx("div",{role:"listbox","aria-label":"Slash commands",className:"absolute bottom-full left-2 right-2 mb-1 bg-popover border border-border rounded-md shadow-lg overflow-hidden z-20",children:v.map((f,M)=>r.jsxs("div",{role:"option","aria-selected":M===p,onMouseEnter:()=>u(M),onClick:()=>E(f),className:A("px-3 py-1.5 text-xs cursor-pointer flex items-baseline justify-between gap-3",M===p?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[r.jsxs("span",{className:"font-mono",children:["/",f.command]}),r.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:f.description})]},f.command))}),r.jsxs("div",{className:"flex items-end space-x-2",children:[r.jsx("textarea",{ref:N,rows:1,value:l,"aria-label":`${o} message`,placeholder:i,onChange:f=>x(f.target.value),onKeyDown:y,className:"flex-1 resize-none bg-background border border-border rounded-md px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/50 max-h-32"}),r.jsx("button",{type:"button",onClick:w,disabled:!l.trim(),"aria-label":"Send message",className:"p-2 rounded-md bg-primary text-primary-foreground disabled:opacity-40 disabled:cursor-not-allowed hover:bg-primary/90 transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(P.Send,{size:14})})]})]})]})};let Nt=0;const kt=()=>`msg-${Date.now()}-${Nt+=1}`,ee=X.create(t=>({messages:[],slashCommands:[],setMessages:e=>t({messages:e}),addMessage:e=>t(n=>({messages:[...n.messages,{...e,id:e.id??kt()}]})),clearMessages:()=>t({messages:[]}),setSlashCommands:e=>t({slashCommands:e}),registerSlashCommand:e=>t(n=>({slashCommands:[...n.slashCommands,e]}))})),ge="nexus-shell-right-sidebar",oe=X.create(t=>({isChatOpen:localStorage.getItem(ge)==="true",setChatOpen:s=>{localStorage.setItem(ge,String(s)),t({isChatOpen:s})},toggleChat:()=>t(s=>{const a=!s.isChatOpen;return localStorage.setItem(ge,String(a)),{isChatOpen:a}})})),Me=({onSend:t,...e})=>{const n=oe(c=>c.isChatOpen),s=oe(c=>c.setChatOpen),a=ee(c=>c.messages),o=ee(c=>c.slashCommands),i=ee(c=>c.addMessage);if(!n)return null;const d=c=>{if(i({role:"user",text:c}),c.startsWith("/")){const[l,...x]=c.slice(1).split(/\s+/),p=o.find(u=>u.command===l);if(p){p.execute(x);return}i({role:"assistant",text:`Unknown command: /${l}`});return}t==null||t(c)};return r.jsx(Ce,{...e,messages:a,slashCommands:o,onSend:d,onClose:()=>s(!1)})},De=({menus:t={},onSelect:e,title:n,center:s,right:a,className:o})=>{const i=c=>c.keybinding?r.jsx("span",{className:"text-[10px] text-muted-foreground opacity-60 ml-4",children:c.keybinding}):null,d=c=>r.jsx("div",{role:"menu",className:"absolute left-0 top-full hidden group-hover:block z-50 min-w-[180px] bg-popover text-popover-foreground border shadow-md rounded-md py-1",children:c.map(l=>r.jsxs("div",{className:"relative group/sub",children:[r.jsxs("div",{role:"menuitem",tabIndex:0,onClick:()=>!l.submenu&&(e==null?void 0:e(l)),onKeyDown:x=>{!l.submenu&&(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),e==null||e(l))},className:"px-3 py-1.5 hover:bg-accent hover:text-accent-foreground cursor-pointer text-xs flex justify-between items-center focus:outline-none focus:bg-accent",children:[r.jsx("span",{children:l.label}),r.jsxs("div",{className:"flex items-center space-x-2",children:[i(l),l.submenu&&r.jsx(P.ChevronRight,{size:10})]})]}),l.submenu&&r.jsx("div",{role:"menu",className:"absolute left-full top-0 hidden group-hover/sub:block z-[60] min-w-[180px] bg-popover text-popover-foreground border shadow-md rounded-md py-1 ml-[-2px]",children:l.submenu.map(x=>r.jsxs("div",{role:"menuitem",tabIndex:0,onClick:()=>e==null?void 0:e(x),onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),e==null||e(x))},className:"px-3 py-1.5 hover:bg-accent hover:text-accent-foreground cursor-pointer text-xs flex justify-between items-center focus:outline-none focus:bg-accent",children:[r.jsx("span",{children:x.label}),i(x)]},x.id))})]},l.id))});return r.jsxs("header",{role:"banner","aria-label":"Application Header",className:A("bg-muted border-b flex items-center justify-between px-4 select-none shrink-0 transition-all z-50 relative",n!==void 0?"h-12 bg-card/65 backdrop-blur-sm":"h-8",o),children:[r.jsxs("div",{className:"flex items-center flex-1 min-w-0",children:[n!==void 0?r.jsx("div",{className:"mr-12 flex items-center shrink-0",children:n}):r.jsx("div",{className:"font-semibold mr-6 text-sm shrink-0",children:"Nexus Shell"}),r.jsx("nav",{role:"navigation","aria-label":"Main Menu",className:"flex space-x-1 text-sm shrink-0",children:Object.entries(t).map(([c,l])=>r.jsxs("div",{className:"relative group",children:[r.jsx("div",{role:"button",tabIndex:0,"aria-haspopup":"menu",className:"cursor-pointer hover:bg-accent hover:text-accent-foreground px-3 py-1 rounded text-xs focus:outline-none focus:ring-2 focus:ring-ring",children:c}),l.length>0&&d(l)]},c))}),s&&r.jsx("div",{className:"ml-8 w-60 md:w-72 relative hidden sm:block",children:s})]}),a&&r.jsx("div",{className:"flex items-center ml-4 shrink-0",children:a})]})};class Le{constructor(){R(this,"menus",new Map)}registerMenu(e,n){var s;this.menus.has(e)||this.menus.set(e,[]),(s=this.menus.get(e))==null||s.push(n)}setMenus(e){this.menus=new Map(Object.entries(e))}getMenu(e){return this.menus.get(e)||[]}getAllMenus(){const e={};return this.menus.forEach((n,s)=>{e[s]=n}),e}}const ae=new Le;class Ie{constructor(){R(this,"commands",new Map)}registerCommand(e){if(this.commands.has(e.id)){console.warn(`Command ${e.id} is already registered.`);return}this.commands.set(e.id,e)}executeCommand(e,...n){const s=this.commands.get(e);s?s.execute(...n):console.warn(`Command ${e} not found.`)}getCommand(e){return this.commands.get(e)}getCommands(){return Array.from(this.commands.values())}}const q=new Ie,Ae=t=>t.map(e=>{var n;return{...e,keybinding:e.keybinding??(e.commandId?(n=q.getCommand(e.commandId))==null?void 0:n.keybinding:void 0),submenu:e.submenu?Ae(e.submenu):void 0}}),Oe=(t,e)=>{for(const n of t){if(n.id===e)return n;const s=n.submenu&&Oe(n.submenu,e);if(s)return s}},Pe=t=>{const e=ae.getAllMenus(),n=Object.fromEntries(Object.entries(e).map(([a,o])=>[a,Ae(o)])),s=a=>{for(const o of Object.values(e)){const i=Oe(o,a.id);if(i!=null&&i.commandId){q.executeCommand(i.commandId);return}}};return r.jsx(De,{...t,menus:n,onSelect:s})},le=({title:t,children:e,onClose:n,width:s="300px",className:a})=>r.jsxs("aside",{role:"tabpanel","aria-label":`${t} Panel`,style:{width:s},className:A("h-full bg-muted border-r flex flex-col select-none shrink-0",a),children:[r.jsxs("div",{className:"h-10 flex items-center justify-between px-4 text-[11px] font-bold text-muted-foreground uppercase tracking-widest",children:[r.jsx("span",{className:"truncate",children:t}),n&&r.jsx("button",{type:"button",onClick:n,"aria-label":"Close Panel",className:"p-1 hover:bg-accent hover:text-foreground rounded transition-colors focus:outline-none focus:ring-2 focus:ring-ring shrink-0",children:r.jsx(P.X,{size:14})})]}),r.jsx("div",{className:"flex-1 overflow-auto border-t border-border/50 bg-background/50",children:e})]}),te=[{id:"light",label:"Light",shortLabel:"Light",description:"Neutral light theme. The default."},{id:"dark",label:"Dark",shortLabel:"Dark",description:"Low-glare dark theme on a soft grey base."},{id:"gt",label:"Georgia Tech",shortLabel:"GT",description:"Buzz Gold (#EAAA00) on Tech Tower White."},{id:"tamu",label:"Texas A&M",shortLabel:"TAMU",description:"Aggie Maroon (#500000) on white."}],$e=te.map(t=>`theme-${t.id}`),_e=t=>`theme-${t}`,Et={light:P.Sun,dark:P.Moon,gt:P.GraduationCap,tamu:P.GraduationCap},ze=te.map(t=>({id:t.id,label:t.label,icon:Et[t.id]??P.Palette})),Ue=({theme:t,onThemeChange:e,themes:n=ze,className:s})=>r.jsx("div",{className:A("p-4 space-y-6",s),children:r.jsxs("section",{children:[r.jsx("h3",{className:"text-[11px] font-bold text-muted-foreground uppercase mb-3",children:"Theme"}),r.jsx("div",{role:"radiogroup","aria-label":"Theme",className:"grid grid-cols-1 gap-2",children:n.map(({id:a,label:o,icon:i})=>r.jsxs("button",{type:"button",role:"radio","aria-checked":t===a,onClick:()=>e(a),className:A("flex items-center space-x-3 px-3 py-2 rounded-md border text-sm transition-all focus:outline-none focus:ring-2 focus:ring-ring",t===a?"bg-primary text-primary-foreground border-primary":"bg-background hover:bg-accent border-border"),children:[r.jsx(i,{size:16}),r.jsx("span",{children:o})]},a))})]})}),Fe="nexus-shell-theme",Ke=t=>{const e=window.document.documentElement,n=[...$e,...Array.from(e.classList).filter(s=>s.startsWith("theme-"))];e.classList.remove(...n),e.classList.add(_e(t))},Q=X.create(t=>{const n=localStorage.getItem(Fe)||"light";return Ke(n),{theme:n,setTheme:s=>{localStorage.setItem(Fe,s),Ke(s),t({theme:s})}}}),Be=t=>{const e=W(l=>l.activeSidebar),n=W(l=>l.panels),s=W(l=>l.setActiveSidebar),a=Q(l=>l.theme),o=Q(l=>l.setTheme);if(!e)return null;const i=()=>s(null);if(e==="settings")return r.jsx(le,{...t,title:"Settings",onClose:i,children:r.jsx(Ue,{theme:a,onThemeChange:l=>o(l)})});const d=n.find(l=>l.id===e);if(!d)return r.jsx(le,{...t,title:e,onClose:i,children:r.jsx("div",{className:"p-4 text-sm italic text-muted-foreground",children:"Panel content not found."})});const c=typeof d.component=="function"?d.component:null;return r.jsx(le,{...t,title:d.label,onClose:i,children:c?r.jsx(c,{}):d.component})},pe=(t,e)=>(e.priority??0)-(t.priority??0),je=({widgets:t=[],className:e,"aria-label":n="Status Bar"})=>{const s={left:t.filter(o=>o.alignment==="left").sort(pe),center:t.filter(o=>o.alignment==="center").sort(pe),right:t.filter(o=>o.alignment==="right").sort(pe)},a=o=>{const i=o.icon,d=!!o.onClick;return r.jsxs("div",{onClick:o.onClick,onKeyDown:d?c=>{var l;(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),(l=o.onClick)==null||l.call(o))}:void 0,role:d?"button":void 0,tabIndex:d?0:void 0,className:A("flex items-center space-x-1.5 px-2 py-0.5 rounded transition-colors h-full focus:outline-none",d?"cursor-pointer hover:bg-white/10 focus:ring-1 focus:ring-white":"cursor-default",o.className),children:[i&&r.jsx(i,{size:12}),o.label&&r.jsx("span",{children:o.label})]},o.id)};return r.jsxs("footer",{role:"status","aria-label":n,className:A("h-6 bg-primary text-primary-foreground text-[11px] flex items-center justify-between px-1 select-none shrink-0 border-t border-white/5",e),children:[r.jsx("div",{className:"flex items-center space-x-1 h-full",children:s.left.map(a)}),r.jsx("div",{className:"flex items-center space-x-1 h-full",children:s.center.map(a)}),r.jsx("div",{className:"flex items-center space-x-1 h-full",children:s.right.map(a)})]})},ie=X.create(t=>({widgets:[],setWidgets:e=>t({widgets:e}),addWidget:e=>t(n=>({widgets:[...n.widgets,e].sort((s,a)=>(a.priority||0)-(s.priority||0))})),removeWidget:e=>t(n=>({widgets:n.widgets.filter(s=>s.id!==e)})),updateWidget:(e,n)=>t(s=>({widgets:s.widgets.map(a=>a.id===e?{...a,...n}:a)}))})),Ge=t=>{const e=ie(s=>s.widgets),n=g.useMemo(()=>e.map(({commandId:s,...a})=>({...a,onClick:a.onClick??(s?()=>q.executeCommand(s):void 0)})),[e]);return r.jsx(je,{...t,widgets:n})},He=({history:t=[],onCommand:e,onClose:n,height:s="250px",prompt:a="$",title:o="Terminal",className:i})=>{const[d,c]=g.useState(""),l=g.useRef(null),x=g.useRef(null);g.useEffect(()=>{l.current&&(l.current.scrollTop=l.current.scrollHeight)},[t]);const p=u=>{if(u.key!=="Enter")return;const N=d.trim();N&&(e==null||e(N),c(""))};return r.jsxs("div",{style:{height:s},className:A("bg-card border-t border-border flex flex-col shrink-0 font-mono text-xs",i),children:[r.jsxs("div",{className:"h-8 flex items-center justify-between px-3 border-b border-border/50 shrink-0",children:[r.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[r.jsx(P.Terminal,{size:13}),r.jsx("span",{className:"text-[11px] font-bold uppercase tracking-widest",children:o})]}),n&&r.jsxs("div",{className:"flex items-center space-x-1",children:[r.jsx("button",{type:"button",onClick:n,"aria-label":"Collapse Terminal",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(P.ChevronUp,{size:14})}),r.jsx("button",{type:"button",onClick:n,"aria-label":"Close Terminal",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(P.X,{size:14})})]})]}),r.jsx("div",{ref:l,role:"log","aria-label":`${o} output`,className:"flex-1 overflow-y-auto px-3 py-2 space-y-0.5",onClick:()=>{var u;return(u=x.current)==null?void 0:u.focus()},children:t.map((u,N)=>r.jsx("div",{className:"whitespace-pre-wrap break-all text-foreground/90",children:u},N))}),r.jsxs("div",{className:"flex items-center px-3 py-2 border-t border-border/50 shrink-0",children:[r.jsx("span",{className:"text-primary mr-2 select-none",children:a}),r.jsx("input",{ref:x,type:"text","aria-label":`${o} input`,value:d,onChange:u=>c(u.target.value),onKeyDown:p,spellCheck:!1,autoComplete:"off",className:"flex-1 bg-transparent outline-none text-foreground placeholder:text-muted-foreground"})]})]})},Z=X.create(t=>({isOpen:!1,history:["Welcome to Nexus Shell Terminal v0.1.0",'Type "help" for a list of commands.'],setOpen:e=>t({isOpen:e}),toggle:()=>t(e=>({isOpen:!e.isOpen})),addHistory:e=>t(n=>({history:[...n.history,e]})),clearHistory:()=>t({history:[]})})),St=["Available commands:"," help — show this message"," clear — clear the terminal"],We=({onCommand:t,...e})=>{const n=Z(c=>c.isOpen),s=Z(c=>c.history),a=Z(c=>c.setOpen),o=Z(c=>c.addHistory),i=Z(c=>c.clearHistory);if(!n)return null;const d=c=>{o(`$ ${c}`);const l=c.toLowerCase();if(l==="clear"){i();return}if(l==="help"){St.forEach(o);return}(t==null?void 0:t(c))!==!0&&o(`command not found: ${c.split(" ")[0]}`)};return r.jsx(He,{...e,history:s,onCommand:d,onClose:()=>a(!1)})};class Tt{constructor(){R(this,"components",new Map)}register(e,n){this.components.has(e)&&console.warn(`Component with ID "${e}" is already registered.`),this.components.set(e,n)}get(e){return this.components.get(e)}getRegisteredIds(){return Array.from(this.components.keys())}}const Ye=new Tt,J={global:{tabEnableClose:!0,tabSetEnableMaximize:!1,tabSetEnableDivide:!0},borders:[{type:"border",location:"left",children:[]}],layout:{type:"row",weight:100,children:[{type:"tabset",weight:50,children:[{type:"tab",name:"Welcome",component:"welcome"}]}]}},Xe="nexus-shell-layout",qe=X.create((t,e)=>{let n;if(typeof window<"u")try{const s=localStorage.getItem(Xe);if(s){const a=JSON.parse(s);n=F.Model.fromJson(a);const o=new Set(["dialogue-library","argument-inspector"]),i=[];n.visitNodes(d=>{if(d.getType()==="tab"){const c=d;o.has(c.getComponent())&&i.push(c.getId())}}),i.forEach(d=>{n.doAction(F.Actions.deleteTab(d))})}else n=F.Model.fromJson(J)}catch(s){console.warn("Failed to load layout from storage, using default",s),n=F.Model.fromJson(J)}else n=F.Model.fromJson(J);return{model:n,dirtyTabs:new Set,storageKey:Xe,disableLocalStorage:!1,initLayout:(s,a)=>{let o;if(s&&Object.keys(s).length>0)try{o=F.Model.fromJson(s)}catch(i){console.warn("Failed to parse init layout json, using default",i),o=F.Model.fromJson(J)}else o=F.Model.fromJson(J);t({model:o,disableLocalStorage:a||!1})},setModel:s=>{t({model:s});const a=e().storageKey;if(typeof window<"u"&&!e().disableLocalStorage)try{localStorage.setItem(a,JSON.stringify(s.toJson()))}catch(o){console.error("Failed to save layout to storage",o)}},setStorageKey:(s,a)=>{let o;if(typeof window<"u")try{const i=localStorage.getItem(s);i?o=F.Model.fromJson(JSON.parse(i)):o=F.Model.fromJson(a||J)}catch(i){console.warn("Failed to load layout from storage for key",s,i),o=F.Model.fromJson(a||J)}else o=F.Model.fromJson(a||J);t({storageKey:s,model:o})},setTabDirty:(s,a)=>{t(o=>{const i=new Set(o.dirtyTabs);return a?i.add(s):i.delete(s),{dirtyTabs:i}})},isTabDirty:s=>e().dirtyTabs.has(s),addTab:(s,a,o)=>{const i=e().model,d=i.getActiveTabset();let c=d==null?void 0:d.getId();if(!c)try{const p=i.getFirstTabSet();c=p==null?void 0:p.getId()}catch(p){console.warn("Failed to get first tabset fallback",p)}const x={...{},...o};if(["nexus-dashboard","nexus-docs"].includes(s)){let p=null;if(i.visitNodes(u=>{if(u.getType()==="tab"){const N=u;N.getComponent()===s&&(p=N.getId())}}),p){i.doAction(F.Actions.selectTab(p));return}}if(x.mapId){let p=null;if(i.visitNodes(u=>{var N;if(u.getType()==="tab"){const k=u;((N=k.getConfig())==null?void 0:N.mapId)===x.mapId&&(p=k.getId())}}),p){i.doAction(F.Actions.selectTab(p));return}}if(x.projectId){let p=null;if(i.visitNodes(u=>{var N;if(u.getType()==="tab"){const k=u;((N=k.getConfig())==null?void 0:N.projectId)===x.projectId&&(p=k.getId())}}),p){i.doAction(F.Actions.selectTab(p));return}}c&&i.doAction(F.Actions.addNode({type:"tab",component:s,name:a||s,config:x},c,F.DockLocation.CENTER,-1))}}}),me=X.create((t,e)=>({isOpen:!1,type:"alert",title:"",message:"",defaultValue:"",resolve:null,openAlert:(n,s="Alert")=>new Promise(a=>{t({isOpen:!0,type:"alert",title:s,message:n,defaultValue:"",resolve:a})}),openConfirm:(n,s="Confirm")=>new Promise(a=>{t({isOpen:!0,type:"confirm",title:s,message:n,defaultValue:"",resolve:a})}),openPrompt:(n,s="",a="Prompt")=>new Promise(o=>{t({isOpen:!0,type:"prompt",title:a,message:n,defaultValue:s,resolve:o})}),close:(n=null)=>{const{resolve:s}=e();s&&s(n),t({isOpen:!1,resolve:null})}})),Je=({panels:t,slashCommands:e,menuConfig:n,statusBarConfig:s,title:a,rightMenuBarContent:o,centerMenuBarContent:i,layoutModel:d,initialLayoutJson:c,disableLocalStorage:l=!1,onLayoutChange:x})=>{const{model:p,setModel:u,initLayout:N,isTabDirty:k,setTabDirty:v}=qe(),b=Q(I=>I.theme),w=W(I=>I.setPanels),E=ee(I=>I.setSlashCommands),y=ie(I=>I.setWidgets);g.useEffect(()=>{t&&w(t)},[t,w]),g.useEffect(()=>{e&&E(e)},[e,E]),g.useEffect(()=>{n&&ae.setMenus(n)},[n]),g.useEffect(()=>{s&&y(s)},[s,y]),g.useEffect(()=>{d||!c&&!l||N(c,l)},[]);const f=I=>{try{const O=I.getComponent(),C=I.getConfig()||{},D=O?Ye.get(O):void 0;return D?r.jsx(D,{node:I,...C}):r.jsxs("div",{className:"p-4 text-sm",children:["Unknown Component: ",O]})}catch(O){return console.error("Error in component factory:",O),r.jsxs("div",{className:"p-8 text-destructive bg-destructive/10 border border-destructive/20 h-full flex items-center justify-center",children:["Error rendering component: ",O instanceof Error?O.message:"Unknown error"]})}},M=I=>{if(I.type!==F.Actions.DELETE_TAB)return I;const O=p.getNodeById(I.data.node);if(!O||!k(O.getId()))return I;me.getState().openConfirm(`Tab "${O.getName()}" has unsaved changes. Are you sure you want to close it?`).then(C=>{C&&(v(O.getId(),!1),p.doAction(I))})};return r.jsxs("div",{className:`flex flex-col h-screen w-screen bg-background text-foreground overflow-hidden theme-${b}`,children:[r.jsx(Pe,{title:a,center:i,right:o}),r.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[r.jsx(Te,{}),r.jsx(Be,{}),r.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-card",children:[r.jsx("div",{className:"flex-1 relative h-full w-full",children:r.jsx(F.Layout,{model:d||p,factory:f,onModelChange:I=>{d||u(I),x==null||x(I.toJson())},onAction:M})}),r.jsx(We,{})]}),r.jsx(Me,{})]}),r.jsx(Ge,{})]})},Ve=te.map(t=>({id:`theme.${t.id}`,label:`Preferences: ${t.label} Theme`,execute:()=>Q.getState().setTheme(t.id)})),Ct=["view.toggleTerminal","view.toggleChat","view.toggleSidebar",...Ve.map(t=>t.id)],Mt=[{id:"view.toggleTerminal",label:"View: Toggle Terminal",keybinding:"Control+`",execute:()=>Z.getState().toggle()},{id:"view.toggleChat",label:"View: Toggle Chat",execute:()=>oe.getState().toggleChat()},{id:"view.toggleSidebar",label:"View: Toggle Sidebar",keybinding:"Control+b",execute:()=>{var s;const{activeSidebar:t,panels:e,setActiveSidebar:n}=W.getState();n(t?null:((s=e[0])==null?void 0:s.id)??null)}},...Ve],Dt={View:[{id:"view.terminal",label:"Toggle Terminal",commandId:"view.toggleTerminal"},{id:"view.chat",label:"Toggle Chat",commandId:"view.toggleChat"},{id:"view.sidebar",label:"Toggle Sidebar",commandId:"view.toggleSidebar"},{id:"view.theme",label:"Theme",submenu:te.map(t=>({id:`view.theme.${t.id}`,label:t.label,commandId:`theme.${t.id}`}))}]},Lt=(t={})=>{const{panels:e,menus:n,commands:s,statusBar:a,slashCommands:o,defaultCommands:i=!0,defaultMenus:d=!0}=t;i&&Mt.forEach(l=>q.registerCommand(l)),s==null||s.forEach(l=>q.registerCommand(l));const c={...i&&d?Dt:{},...n??{}};Object.keys(c).length>0&&ae.setMenus(c),e&&W.getState().setPanels(e),a&&ie.getState().setWidgets(a),o&&ee.getState().setSlashCommands(o)};class It{constructor(){R(this,"plugins",new Map);R(this,"loaders",new Map);R(this,"statuses",new Map)}registerPlugin(e){if(this.plugins.has(e.id)){console.warn(`Plugin ${e.id} is already registered.`);return}this.plugins.set(e.id,e),this.statuses.set(e.id,"registered"),console.log(`Plugin ${e.name} (${e.id}) registered.`)}registerLazyPlugin(e,n){if(this.loaders.has(e)||this.plugins.has(e)){console.warn(`Plugin ${e} is already registered or has a loader.`);return}this.loaders.set(e,n),this.statuses.set(e,"inactive"),console.log(`Lazy plugin loader for ${e} registered.`)}async activatePlugin(e){let n=this.plugins.get(e);if(!n&&this.loaders.has(e))try{n=await this.loaders.get(e)(),this.plugins.set(e,n),this.statuses.set(e,"registered"),console.log(`Lazy plugin ${e} loaded.`)}catch(s){console.error(`Failed to load lazy plugin ${e}`,s),this.statuses.set(e,"failed");return}if(n)try{this.statuses.set(e,"activating"),n.activate(),this.statuses.set(e,"active"),console.log(`Plugin ${n.name} activated.`)}catch(s){console.error(`Failed to activate plugin ${e}`,s),this.statuses.set(e,"failed")}else console.warn(`Plugin ${e} not found for activation.`),this.statuses.set(e,"failed")}async deactivatePlugin(e){const n=this.plugins.get(e);if(n)try{n.deactivate(),this.statuses.set(e,"deactivated"),console.log(`Plugin ${n.name} deactivated.`)}catch(s){console.error(`Failed to deactivate plugin ${e}`,s),this.statuses.set(e,"failed")}}getPluginStatus(e){return this.statuses.get(e)}getPluginStatuses(){const e={};return this.statuses.forEach((n,s)=>{e[s]=n}),e}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.values())}}const At=new It,Qe="nexus-shell-user-profile",Ze={name:"David Tech",role:"Shell Architect",email:"david@techmuch.io",avatarUrl:"",customAvatar:""},V=X.create(t=>{let e={...Ze};if(typeof window<"u")try{const s=localStorage.getItem(Qe);s&&(e={...Ze,...JSON.parse(s)})}catch(s){console.error("Failed to parse saved user profile:",s)}const n=s=>{if(typeof window<"u")try{localStorage.setItem(Qe,JSON.stringify({name:s.name,role:s.role,email:s.email,avatarUrl:s.avatarUrl,customAvatar:s.customAvatar}))}catch(a){console.error("Failed to save user profile:",a)}};return{...e,updateProfile:s=>t(a=>{const o={...a,...s};return n(o),s}),setCustomAvatar:s=>t(a=>{const o={...a,customAvatar:s};return n(o),{customAvatar:s}}),clearCustomAvatar:()=>t(s=>{const a={...s,customAvatar:""};return n(a),{customAvatar:""}})}}),Ot=()=>{g.useEffect(()=>{const t=e=>{const n=q.getCommands();for(const s of n)if(s.keybinding&&Pt(e,s.keybinding)){e.preventDefault(),s.execute();break}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[])};function Pt(t,e){var u;const n=e.split("+"),s=(u=n.pop())==null?void 0:u.toLowerCase(),a=n.includes("Control")||n.includes("Ctrl"),o=n.includes("Shift"),i=n.includes("Alt"),d=n.includes("Meta")||n.includes("Cmd"),c=t.ctrlKey,l=t.shiftKey,x=t.altKey,p=t.metaKey;return t.key.toLowerCase()===s&&c===a&&l===o&&x===i&&p===d}const $t=(t,e)=>{const n=e.toLowerCase();return t.label.toLowerCase().includes(n)||t.id.toLowerCase().includes(n)},Re=({open:t,commands:e,onSelect:n,onClose:s,inline:a=!1,placeholder:o="Type a command to run…",filter:i=$t,className:d})=>{const[c,l]=g.useState(""),[x,p]=g.useState(0),u=g.useRef(null),N=g.useMemo(()=>e.filter(v=>i(v,c)),[e,c,i]);if(g.useEffect(()=>{var v;t&&(l(""),p(0),(v=u.current)==null||v.focus())},[t]),g.useEffect(()=>{p(0)},[c]),!t)return null;const k=v=>{v.key==="ArrowDown"?(v.preventDefault(),p(b=>N.length?(b+1)%N.length:0)):v.key==="ArrowUp"?(v.preventDefault(),p(b=>N.length?(b-1+N.length)%N.length:0)):v.key==="Enter"?(v.preventDefault(),N[x]&&n(N[x])):v.key==="Escape"&&(v.preventDefault(),s==null||s())};return r.jsx("div",{onClick:a?void 0:s,className:A("z-[100] flex items-start justify-center",a?"relative w-full max-w-xl":"fixed inset-0 pt-[10vh] bg-black/50 backdrop-blur-sm"),children:r.jsxs("div",{role:"dialog","aria-modal":!a,"aria-label":"Command Palette",onClick:v=>v.stopPropagation(),className:A("w-full max-w-xl bg-popover text-popover-foreground border shadow-2xl rounded-xl overflow-hidden animate-in fade-in zoom-in duration-200",d),children:[r.jsxs("div",{className:"flex items-center px-4 border-b",children:[r.jsx(P.Search,{size:18,className:"text-muted-foreground mr-3"}),r.jsx("input",{ref:u,type:"text",role:"combobox","aria-expanded":!0,"aria-controls":"command-palette-list","aria-label":"Command",placeholder:o,value:c,onChange:v=>l(v.target.value),onKeyDown:k,className:"flex-1 h-14 bg-transparent outline-none text-base text-foreground placeholder:text-muted-foreground"})]}),r.jsx("div",{id:"command-palette-list",role:"listbox",className:"max-h-[300px] overflow-y-auto py-2",children:N.length===0?r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:c?`No commands found matching "${c}"`:"No commands available."}):N.map((v,b)=>r.jsxs("div",{role:"option","aria-selected":b===x,onClick:()=>n(v),onMouseEnter:()=>p(b),className:A("px-4 py-2 cursor-pointer flex justify-between items-center text-sm",b===x?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[r.jsx("span",{children:v.label}),v.keybinding&&r.jsx("span",{className:"text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded border border-border/50",children:v.keybinding})]},v.id))}),r.jsxs("div",{className:"px-4 py-2 border-t bg-muted/30 flex justify-between items-center text-[10px] text-muted-foreground",children:[r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"↑↓"})," to navigate"]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"Enter"})," to select"]})]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"Esc"})," to close"]})]})]})})},_t=({shortcutKey:t="p",...e})=>{const[n,s]=g.useState(!1);return g.useEffect(()=>{if(t===null)return;const a=o=>{(o.metaKey||o.ctrlKey)&&o.shiftKey&&o.key.toLowerCase()===t&&(o.preventDefault(),s(i=>!i))};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[t]),r.jsx(Re,{...e,open:n,commands:q.getCommands(),onSelect:a=>{a.execute(),s(!1)},onClose:()=>s(!1)})},zt={alert:P.AlertCircle,confirm:P.HelpCircle,prompt:P.Info},Ut={alert:"text-destructive",confirm:"text-amber-500",prompt:"text-blue-500"},et=({open:t,type:e="alert",title:n,message:s,defaultValue:a="",onConfirm:o,onCancel:i,confirmLabel:d,cancelLabel:c="Cancel",placeholder:l="Enter value…",className:x})=>{const[p,u]=g.useState(a),N=g.useRef(null);if(g.useEffect(()=>{if(!t||(u(a),e!=="prompt"))return;const w=window.setTimeout(()=>{var E,y;(E=N.current)==null||E.focus(),(y=N.current)==null||y.select()},50);return()=>window.clearTimeout(w)},[t,e,a]),g.useEffect(()=>{if(!t)return;const w=E=>{E.key==="Escape"&&(E.preventDefault(),i==null||i())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[t,i]),!t)return null;const k=()=>o==null?void 0:o(e==="prompt"?p:void 0),v=w=>{w.key==="Enter"&&(w.preventDefault(),k())},b=zt[e];return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-background/80 backdrop-blur-sm transition-all duration-300",onClick:i,children:r.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":n,onClick:w=>w.stopPropagation(),onKeyDown:v,className:A("relative flex flex-col w-full max-w-md p-6 bg-card border border-border shadow-2xl rounded-2xl animate-in fade-in zoom-in-95 ring-1 ring-white/10",x),children:[r.jsx("button",{type:"button",onClick:i,"aria-label":"Close",className:"absolute top-4 right-4 p-1 rounded-full text-muted-foreground hover:bg-muted hover:text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(P.X,{size:18})}),r.jsxs("div",{className:"flex items-start space-x-4 mb-4",children:[r.jsx("div",{className:A("p-2 bg-muted rounded-full shrink-0",Ut[e]),children:r.jsx(b,{size:24})}),r.jsxs("div",{className:"flex-1 mt-1",children:[r.jsx("h2",{className:"text-lg font-semibold tracking-tight pr-6",children:n}),s&&r.jsx("p",{className:"text-sm text-muted-foreground mt-1 whitespace-pre-wrap",children:s})]})]}),e==="prompt"&&r.jsx("div",{className:"mt-2 mb-4",children:r.jsx("input",{ref:N,type:"text","aria-label":n,value:p,placeholder:l,onChange:w=>u(w.target.value),className:"w-full bg-background border border-border rounded-lg px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-all placeholder:text-muted-foreground/50"})}),r.jsxs("div",{className:"flex items-center justify-end space-x-3 mt-4",children:[e!=="alert"&&r.jsx("button",{type:"button",onClick:i,className:"px-4 py-2 text-sm font-medium rounded-lg border border-border hover:bg-muted transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:c}),r.jsx("button",{type:"button",onClick:k,autoFocus:e!=="prompt",className:"px-4 py-2 text-sm font-medium rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:d??(e==="alert"?"OK":"Confirm")})]})]})})},Ft=t=>{const{isOpen:e,type:n,title:s,message:a,defaultValue:o,close:i}=me(),d=l=>{n==="prompt"?i(l??""):n==="confirm"?i(!0):i()},c=()=>{n==="prompt"?i(null):n==="confirm"?i(!1):i()};return r.jsx(et,{...t,open:e,type:n,title:s,message:a,defaultValue:o,onConfirm:d,onCancel:c})},tt=te.map(t=>({id:t.id,label:t.shortLabel})),rt=({value:t,onChange:e,options:n=tt,className:s,"aria-label":a="Theme"})=>r.jsx("div",{role:"radiogroup","aria-label":a,className:A("flex items-center border border-border rounded-lg p-0.5 bg-secondary/80 select-none",s),children:n.map(o=>r.jsx("button",{role:"radio","aria-checked":t===o.id,onClick:()=>e(o.id),className:A("px-2.5 py-1 text-[9px] font-extrabold uppercase rounded-md transition-all font-mono cursor-pointer outline-none focus-visible:ring-1 focus-visible:ring-ring",t===o.id?"bg-primary text-primary-foreground shadow":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:o.label},o.id))}),Kt=t=>{const e=Q(s=>s.theme),n=Q(s=>s.setTheme);return r.jsx(rt,{...t,value:e,onChange:n})},st=({profile:t,actions:e=[],onProfileChange:n,onAvatarChange:s,onClick:a,showName:o=!0,className:i})=>{const{name:d,role:c,email:l,avatarUrl:x}=t,[p,u]=g.useState(!1),[N,k]=g.useState(!1),[v,b]=g.useState(d),[w,E]=g.useState(c??""),y=g.useRef(null),f=g.useRef(null);g.useEffect(()=>{p&&(b(d),E(c??""),k(!1))},[p,d,c]),g.useEffect(()=>{if(!p)return;const C=D=>{y.current&&!y.current.contains(D.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[p]);const M=C=>{C.preventDefault(),n==null||n({name:v,role:w}),k(!1)},I=C=>{var h;const D=(h=C.target.files)==null?void 0:h[0];D&&(s==null||s(D)),C.target.value=""},O=C=>x?r.jsx("img",{src:x,alt:d,className:"w-full h-full object-cover"}):r.jsx(P.User,{size:C,className:"text-muted-foreground"});return r.jsxs("div",{ref:y,className:"relative inline-block text-left",children:[r.jsxs("button",{type:"button",onClick:()=>a?a():u(C=>!C),"aria-haspopup":a?void 0:"menu","aria-expanded":a?void 0:p,"aria-label":"User Profile Menu",className:A("focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none transition-all duration-200 select-none",o?"flex items-center space-x-2 px-2 py-1 rounded-md hover:bg-accent/50 hover:text-accent-foreground text-left cursor-pointer border border-transparent hover:border-border/30":"w-7 h-7 rounded-full bg-secondary/80 border border-border flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-secondary cursor-pointer",p&&(o?"bg-accent/60 border-border/40":"border-primary/50 text-foreground ring-1 ring-primary/20"),i),children:[r.jsx("div",{className:A("rounded-full overflow-hidden border border-border/50 bg-muted flex items-center justify-center shrink-0 shadow-sm",o?"w-6 h-6":"w-full h-full"),children:O(o?13:12)}),o&&r.jsxs("div",{className:"flex flex-col min-w-0 leading-tight pr-1",children:[r.jsx("span",{className:"text-[11px] font-semibold truncate text-foreground",children:d}),c&&r.jsx("span",{className:"text-[9px] text-muted-foreground/80 truncate font-medium",children:c})]})]}),s&&r.jsx("input",{type:"file",ref:f,onChange:I,accept:"image/*","aria-label":"Upload avatar",className:"hidden"}),p&&r.jsx("div",{role:"menu",className:A("absolute z-50 w-64 rounded-lg border border-border/50 bg-card text-card-foreground shadow-lg backdrop-blur-md p-2 flex flex-col gap-1 mt-1.5 animate-in fade-in slide-in-from-top-2 duration-150 origin-top-right",o?"left-0":"right-0"),children:N?r.jsxs("form",{onSubmit:M,className:"p-2 flex flex-col gap-2",children:[r.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:"Edit Profile"}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("label",{htmlFor:"profile-name",className:"text-[9px] font-semibold text-muted-foreground",children:"Name"}),r.jsx("input",{id:"profile-name",type:"text",value:v,onChange:C=>b(C.target.value),required:!0,className:"w-full px-2 py-1 text-xs border rounded bg-background focus:ring-1 focus:ring-primary focus:outline-none"})]}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("label",{htmlFor:"profile-role",className:"text-[9px] font-semibold text-muted-foreground",children:"Role"}),r.jsx("input",{id:"profile-role",type:"text",value:w,onChange:C=>E(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background focus:ring-1 focus:ring-primary focus:outline-none"})]}),r.jsxs("div",{className:"flex gap-1.5 mt-1 justify-end",children:[r.jsxs("button",{type:"button",onClick:()=>k(!1),className:"px-2 py-1 text-[10px] rounded hover:bg-accent text-muted-foreground flex items-center gap-1 border border-border/30",children:[r.jsx(P.X,{size:10})," Cancel"]}),r.jsxs("button",{type:"submit",className:"px-2 py-1 text-[10px] rounded bg-primary text-primary-foreground hover:bg-primary/95 flex items-center gap-1 font-semibold",children:[r.jsx(P.Check,{size:10})," Save"]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"p-2 flex items-center gap-3 border-b border-border/40 pb-2.5 mb-1",children:[r.jsxs("div",{onClick:()=>{var C;return s&&((C=f.current)==null?void 0:C.click())},title:s?"Upload avatar image":void 0,className:A("group relative w-12 h-12 rounded-full overflow-hidden border border-border/80 bg-muted flex items-center justify-center shrink-0 shadow-inner",s&&"cursor-pointer"),children:[O(24),s&&r.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 flex items-center justify-center transition-opacity",children:r.jsx(P.Camera,{size:14,className:"text-white"})})]}),r.jsxs("div",{className:"flex flex-col min-w-0 leading-normal flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-xs font-bold truncate text-foreground",children:d}),n&&r.jsx("button",{type:"button",onClick:()=>k(!0),title:"Edit Profile","aria-label":"Edit Profile",className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent/40 rounded transition-colors",children:r.jsx(P.Edit2,{size:10})})]}),c&&r.jsx("span",{className:"text-[10px] text-muted-foreground/80 truncate font-semibold",children:c}),l&&r.jsx("span",{className:"text-[9px] text-muted-foreground/60 truncate font-mono mt-0.5",children:l})]})]}),e.map(C=>{const D=C.icon;return r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{C.onSelect(),u(!1)},className:A("w-full px-2 py-1.5 text-left rounded-md text-[11px] font-medium flex items-center gap-2 cursor-pointer transition-colors",C.destructive?"text-destructive hover:bg-destructive/10":"hover:bg-accent/60 hover:text-accent-foreground",C.divider&&"border-t border-border/20 pt-2 mt-1"),children:[D&&r.jsx(D,{size:12,className:"opacity-70"}),C.label]},C.id)})]})})]})},Bt=t=>{const e=V(l=>l.name),n=V(l=>l.role),s=V(l=>l.email),a=V(l=>l.avatarUrl),o=V(l=>l.customAvatar),i=V(l=>l.updateProfile),d=V(l=>l.setCustomAvatar),c=l=>{const x=new FileReader;x.onloadend=()=>{typeof x.result=="string"&&d(x.result)},x.readAsDataURL(l)};return r.jsx(st,{...t,profile:{name:e,role:n,email:s,avatarUrl:o||a},onProfileChange:i,onAvatarChange:c})},jt=({title:t,subtitle:e,icon:n,className:s})=>r.jsxs("div",{className:A("flex items-center space-x-3 select-none",s),children:[n&&r.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 border border-primary/30 flex items-center justify-center text-primary shadow-inner shrink-0",children:n}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h1",{className:"text-xs font-black uppercase tracking-wider text-foreground font-mono truncate",children:t}),e&&r.jsx("p",{className:"text-[9px] text-muted-foreground font-semibold truncate",children:e})]})]}),nt=({x:t,y:e,items:n,onClose:s,className:a})=>{const o=g.useRef(null);return g.useEffect(()=>{const i=c=>{o.current&&!o.current.contains(c.target)&&s()},d=c=>{c.key==="Escape"&&s()};return document.addEventListener("mousedown",i),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",d)}},[s]),r.jsx("div",{ref:o,role:"menu",style:{top:e,left:t},className:A("fixed z-[1000] min-w-[160px] bg-popover text-popover-foreground border shadow-md rounded-md py-1 animate-in fade-in zoom-in-95 duration-100",a),children:n.map((i,d)=>r.jsxs(g.Fragment,{children:[i.divider&&r.jsx("div",{className:"h-[1px] bg-border my-1"}),r.jsxs("div",{role:"menuitem",tabIndex:i.disabled?void 0:0,"aria-disabled":i.disabled,onClick:()=>{i.disabled||(i.onClick(),s())},onKeyDown:c=>{i.disabled||c.key!=="Enter"&&c.key!==" "||(c.preventDefault(),i.onClick(),s())},className:A("px-3 py-1.5 text-xs flex items-center focus:outline-none",i.disabled?"opacity-40 cursor-default":"cursor-pointer hover:bg-accent hover:text-accent-foreground focus:bg-accent"),children:[i.icon&&r.jsx("span",{className:"mr-2 opacity-70",children:i.icon}),r.jsx("span",{children:i.label})]})]},`${i.label}-${d}`))})},Gt=({columns:t,data:e,onRowClick:n,selectedRowId:s,rowKey:a="id",virtualized:o=!0,showFilter:i=!0,loading:d=!1,placeholder:c="No data available",className:l})=>{const[x,p]=g.useState(""),[u,N]=g.useState(null),[k,v]=g.useState(-1),b=g.useRef(null);g.useEffect(()=>{v(-1)},[x,u]);const w=g.useMemo(()=>{if(!x)return e;const h=x.toLowerCase();return e.filter(T=>Object.values(T).some(L=>L==null?!1:String(L).toLowerCase().includes(h)))},[e,x]),E=g.useMemo(()=>{if(!u)return w;const{key:h,direction:T}=u;return[...w].sort((L,$)=>{const K=L[h],U=$[h];if(K===U)return 0;if(K==null)return 1;if(U==null)return-1;const G=Number(K),S=Number(U);if(!isNaN(G)&&!isNaN(S))return T==="asc"?G-S:S-G;const z=String(K).toLowerCase(),_=String(U).toLowerCase();return T==="asc"?z.localeCompare(_):_.localeCompare(z)})},[w,u]),y=(h,T)=>{T!==!1&&N(L=>!L||L.key!==h?{key:h,direction:"asc"}:L.direction==="asc"?{key:h,direction:"desc"}:null)},f=h=>{if(!(E.length===0||d)){if(h.key==="ArrowDown")h.preventDefault(),v(T=>{const L=T+1;return L>=E.length?0:L});else if(h.key==="ArrowUp")h.preventDefault(),v(T=>{const L=T-1;return L<0?E.length-1:L});else if((h.key==="Enter"||h.key===" ")&&(h.preventDefault(),k>=0&&k<E.length)){const T=E[k];n&&n(T)}}},M=h=>h.sortable===!1?null:(u==null?void 0:u.key)!==h.key?r.jsx(P.ChevronsUpDown,{size:14,className:"text-muted-foreground/60 ml-1.5 opacity-0 group-hover:opacity-100 transition-opacity"}):u.direction==="asc"?r.jsx(P.ChevronUp,{size:14,className:"text-primary ml-1.5"}):r.jsx(P.ChevronDown,{size:14,className:"text-primary ml-1.5"}),I=()=>r.jsx("tr",{role:"row",className:"border-b border-border bg-muted/30 select-none",children:t.map(h=>r.jsx("th",{role:"columnheader","aria-sort":(u==null?void 0:u.key)===h.key?u.direction==="asc"?"ascending":"descending":"none",className:A("p-3 text-xs font-semibold text-muted-foreground uppercase tracking-wider text-left transition-colors",h.sortable!==!1&&"cursor-pointer hover:bg-accent/30 hover:text-foreground group"),style:{width:h.width},onClick:()=>y(h.key,h.sortable),children:r.jsxs("div",{className:"flex items-center",children:[r.jsx("span",{children:h.header}),M(h)]})},h.key))}),O=(h,T)=>{const L=s!==void 0&&h[a]===s,$=k===T;return r.jsx("tr",{role:"row","aria-selected":L,onClick:()=>n&&n(h),className:A("border-b border-border/40 hover:bg-accent/40 transition-colors cursor-pointer text-sm outline-none",L&&"bg-primary/10 text-primary hover:bg-primary/15 font-medium border-l-2 border-l-primary",$&&"bg-accent/60 ring-1 ring-inset ring-ring"),children:t.map(K=>{const U=h[K.key];return r.jsx("td",{role:"gridcell",className:"p-3 align-middle truncate max-w-xs",children:K.render?K.render(U,h):U!=null?String(U):""},K.key)})},String(h[a]||T))},C=g.useMemo(()=>({Table:h=>r.jsx("table",{...h,role:"grid",className:"w-full border-collapse text-left bg-background text-foreground"}),TableHead:g.forwardRef((h,T)=>r.jsx("thead",{ref:T,...h,className:"sticky top-0 bg-background z-10 shadow-[0_1px_0_0_rgba(0,0,0,0.1)] dark:shadow-[0_1px_0_0_rgba(255,255,255,0.05)]"})),TableBody:g.forwardRef((h,T)=>r.jsx("tbody",{ref:T,...h})),TableRow:({item:h,context:T,...L})=>{if(!T||!h)return r.jsx("tr",{...L});const $=T.selectedRowId!==void 0&&h[T.rowKey]===T.selectedRowId,K=T.focusedIndex===L["data-index"];return r.jsx("tr",{...L,onClick:()=>{var U;return(U=T.onRowClick)==null?void 0:U.call(T,h)},className:A("border-b border-border/40 hover:bg-accent/40 transition-colors cursor-pointer text-sm outline-none",$&&"bg-primary/10 text-primary hover:bg-primary/15 font-medium border-l-2 border-l-primary",K&&"bg-accent/60 ring-1 ring-inset ring-ring")})}}),[]),D=()=>d?r.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-3",children:[r.jsx(P.Loader2,{className:"animate-spin text-primary",size:24}),r.jsx("span",{className:"text-xs text-muted-foreground",children:"Loading dataset..."})]}):E.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-48 text-center px-4",children:[r.jsx("span",{className:"text-sm font-medium text-foreground",children:c}),r.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"No items matched your search query."})]}):o?r.jsx("div",{className:"flex-1 min-h-[300px] h-full relative",children:r.jsx(Ee.TableVirtuoso,{data:E,context:{selectedRowId:s,focusedIndex:k,rowKey:a,onRowClick:n},components:C,fixedHeaderContent:I,itemContent:(h,T)=>r.jsx(r.Fragment,{children:t.map(L=>{const $=T[L.key];return r.jsx("td",{role:"gridcell",className:"p-3 align-middle truncate max-w-xs",children:L.render?L.render($,T):$!=null?String($):""},L.key)})})})}):r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("table",{role:"grid",className:"w-full border-collapse text-left bg-background text-foreground",children:[r.jsx("thead",{children:I()}),r.jsx("tbody",{children:E.map((h,T)=>O(h,T))})]})});return r.jsxs("div",{ref:b,role:"region","aria-label":"Data Grid",tabIndex:0,onKeyDown:f,className:A("flex flex-col h-full bg-background border border-border rounded-lg shadow-sm overflow-hidden focus:outline-none focus:ring-1 focus:ring-ring focus:border-transparent",l),children:[i&&r.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border bg-muted/20",children:[r.jsxs("div",{className:"relative flex-1 max-w-sm",children:[r.jsx(P.Search,{size:14,className:"absolute left-2.5 top-2.5 text-muted-foreground"}),r.jsx("input",{type:"text",placeholder:"Filter table rows...",className:"w-full bg-secondary/40 border border-border rounded-md pl-8 pr-7 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary focus:border-transparent transition-all",value:x,onChange:h=>p(h.target.value)}),x&&r.jsx("button",{onClick:()=>p(""),className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground","aria-label":"Clear filter",children:r.jsx(P.X,{size:12})})]}),r.jsxs("div",{className:"text-[11px] text-muted-foreground font-medium ml-4",children:[E.length," of ",e.length," records"]})]}),D()]})},Ht=({results:t,onQueryChange:e,onSelect:n,categories:s,placeholder:a="Search…",debounceMs:o=200,className:i})=>{const[d,c]=g.useState(""),[l,x]=g.useState(!1),[p,u]=g.useState(0),N=g.useRef(null),k=g.useRef(null),v=g.useMemo(()=>s||[...new Set(t.map(y=>y.category))],[s,t]),b=g.useMemo(()=>v.flatMap(y=>t.filter(f=>f.category===y)),[v,t]);g.useEffect(()=>{const y=f=>{N.current&&!N.current.contains(f.target)&&x(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]),g.useEffect(()=>{if(!e)return;const y=window.setTimeout(()=>e(d),o);return()=>window.clearTimeout(y)},[d,o,e]),g.useEffect(()=>{u(0)},[t]);const w=y=>{n(y),x(!1),c("")},E=y=>{var f;if(!l){(y.key==="ArrowDown"||y.key==="Enter")&&x(!0);return}y.key==="ArrowDown"?(y.preventDefault(),u(M=>b.length?(M+1)%b.length:0)):y.key==="ArrowUp"?(y.preventDefault(),u(M=>b.length?(M-1+b.length)%b.length:0)):y.key==="Enter"?(y.preventDefault(),b[p]&&w(b[p])):y.key==="Escape"&&(y.preventDefault(),x(!1),(f=k.current)==null||f.blur())};return r.jsxs("div",{ref:N,className:A("relative w-full",i),children:[r.jsxs("div",{className:"relative flex items-center",children:[r.jsx(P.Search,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),r.jsx("input",{ref:k,type:"text",role:"combobox","aria-expanded":l,"aria-label":a,value:d,placeholder:a,onChange:y=>{c(y.target.value),x(!0)},onFocus:()=>x(!0),onKeyDown:E,className:"w-full h-7 pl-8 pr-7 bg-secondary/35 border border-border/40 rounded-md text-xs text-foreground placeholder:text-muted-foreground/75 focus:outline-none focus:ring-1 focus:ring-primary/40 focus:bg-background/95 focus:border-primary/50 transition-all font-sans"}),d&&r.jsx("button",{type:"button",onClick:()=>{var y;c(""),(y=k.current)==null||y.focus()},"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:r.jsx(P.X,{size:11})})]}),l&&d.trim()&&r.jsxs("div",{role:"listbox",className:"absolute right-0 md:left-0 mt-1.5 w-80 max-h-[380px] bg-popover text-popover-foreground border border-border shadow-lg rounded-lg overflow-hidden flex flex-col z-[100] animate-in fade-in-50 slide-in-from-top-1 duration-100",children:[r.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:b.length===0?r.jsxs("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground italic",children:['No results found matching "',d,'"']}):v.map(y=>{const f=t.filter(M=>M.category===y);return f.length===0?null:r.jsxs("div",{className:"flex flex-col",children:[r.jsx("div",{className:"px-3 py-1 text-[9px] font-bold uppercase tracking-wider text-muted-foreground/80 bg-muted/40 border-y border-border/20 first:border-t-0",children:y}),f.map(M=>{const I=M.icon,O=b.indexOf(M),C=O===p;return r.jsxs("div",{role:"option","aria-selected":C,onClick:()=>w(M),onMouseEnter:()=>u(O),className:A("px-3 py-2 cursor-pointer flex items-start space-x-2.5 transition-colors border-l-2",C?"bg-accent text-accent-foreground border-primary":"border-transparent hover:bg-accent/40"),children:[I&&r.jsx("div",{className:A("mt-0.5 p-1 rounded bg-muted/50",C&&"bg-background text-primary"),children:r.jsx(I,{size:12})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs font-medium truncate",children:M.title}),M.description&&r.jsx("div",{className:"text-[10px] text-muted-foreground truncate mt-0.5",children:M.description})]})]},`${M.category}-${M.id}`)})]},y)})}),b.length>0&&r.jsxs("div",{className:"px-3 py-1.5 border-t border-border bg-muted/20 flex items-center justify-between text-[9px] text-muted-foreground select-none shrink-0 font-mono",children:[r.jsxs("div",{className:"flex space-x-2",children:[r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border border-border/60",children:"↑↓"})," ","navigate"]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border border-border/60",children:"↵"})," ","select"]})]}),r.jsx("span",{children:"ESC to close"})]})]})]})},Wt=({placeholder:t="Search...",onSearch:e,results:n,onSelect:s,suggestions:a=[],loading:o=!1,className:i})=>{const[d,c]=g.useState(""),[l,x]=g.useState(!1),[p,u]=g.useState(-1),N=g.useRef(null);g.useEffect(()=>{const b=setTimeout(()=>{e(d)},300);return()=>clearTimeout(b)},[d,e]);const k=a.filter(b=>b.toLowerCase().includes(d.toLowerCase())&&b.toLowerCase()!==d.toLowerCase()),v=b=>{l&&k.length>0&&(b.key==="ArrowDown"?(b.preventDefault(),u(w=>(w+1)%k.length)):b.key==="ArrowUp"?(b.preventDefault(),u(w=>(w-1+k.length)%k.length)):b.key==="Enter"&&p>=0&&(b.preventDefault(),c(k[p]),x(!1)))};return r.jsxs("div",{ref:N,className:A("flex flex-col h-full bg-background",i),children:[r.jsxs("div",{className:"p-3 border-b border-border/50",children:[r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-2.5 top-2.5 text-muted-foreground",children:o?r.jsx(P.Loader2,{size:14,className:"animate-spin"}):r.jsx(P.Search,{size:14})}),r.jsx("input",{type:"text",className:"w-full bg-secondary/50 border border-border rounded-md pl-9 pr-8 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all",placeholder:t,value:d,onChange:b=>{c(b.target.value),x(!0),u(-1)},onKeyDown:v,onFocus:()=>x(!0)}),d&&r.jsx("button",{onClick:()=>{c(""),e("")},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:r.jsx(P.X,{size:14})})]}),l&&k.length>0&&r.jsx("div",{className:"absolute left-3 right-3 mt-1 bg-popover border shadow-lg rounded-md z-50 py-1 overflow-hidden",children:k.map((b,w)=>r.jsxs("div",{className:A("px-3 py-1.5 text-xs cursor-pointer flex items-center space-x-2",w===p?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>{c(b),x(!1)},children:[r.jsx(P.Clock,{size:12,className:"text-muted-foreground"}),r.jsx("span",{children:b})]},b))})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?r.jsx("div",{className:"p-8 text-center text-xs text-muted-foreground italic",children:d?`No results found for "${d}"`:"Type to start searching..."}):r.jsx("div",{className:"py-2",children:n.map(b=>{const w=b.icon;return r.jsx("div",{onClick:()=>s(b),className:"px-4 py-2 hover:bg-accent/50 cursor-pointer group transition-colors border-l-2 border-transparent hover:border-primary",children:r.jsxs("div",{className:"flex items-start space-x-3",children:[w&&r.jsx("div",{className:"mt-0.5 p-1 rounded bg-muted group-hover:bg-background transition-colors",children:r.jsx(w,{size:14,className:"text-muted-foreground group-hover:text-primary"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-medium truncate",children:b.title}),b.category&&r.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-bold px-1.5 py-0.5 bg-muted rounded",children:b.category})]}),b.description&&r.jsx("p",{className:"text-[11px] text-muted-foreground truncate mt-0.5",children:b.description})]})]})},b.id)})})})]})},ot=(t,e=0)=>t.reduce((n,s)=>(n.push({...s,level:e}),s.isOpen&&s.children&&n.push(...ot(s.children,e+1)),n),[]),Yt=t=>{if(!t)return["background"];const e=[t.isBranch?"branch":"leaf"];return t.kind&&e.push(t.kind),e},Xt=({data:t,onToggle:e,onActivate:n,onMoveNode:s,actions:a=[],indent:o=12,virtualized:i=!0,"aria-label":d="Tree",className:c})=>{const[l,x]=g.useState(null),[p,u]=g.useState(null),N=g.useMemo(()=>ot(t),[t]);g.useEffect(()=>{u(null)},[t]);const k=a.filter(w=>!w.showFor||l&&w.showFor.some(E=>l.scopes.includes(E))).map(w=>({label:w.label,icon:w.icon,divider:w.divider,onClick:()=>l&&w.onSelect(l.context)})),v=(w,E)=>{a.length!==0&&(w.preventDefault(),w.stopPropagation(),x({x:w.clientX,y:w.clientY,scopes:Yt(E),context:{nodeId:(E==null?void 0:E.id)??null,node:E}}))},b=w=>{const E=N[w],y=!!E.isBranch;return r.jsxs("div",{role:"treeitem","aria-expanded":y?!!E.isOpen:void 0,"aria-level":E.level+1,tabIndex:0,draggable:!0,onDragStart:f=>{f.dataTransfer.setData("text/plain",E.id),f.dataTransfer.effectAllowed="move"},onDragOver:f=>{y&&(f.preventDefault(),u(E.id))},onDragLeave:()=>u(null),onDrop:f=>{f.preventDefault(),u(null);const M=f.dataTransfer.getData("text/plain");M&&M!==E.id&&y&&(s==null||s(M,E.id))},onClick:()=>y&&(e==null?void 0:e(E)),onDoubleClick:()=>n==null?void 0:n(E),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),y?e==null||e(E):n==null||n(E))},onContextMenu:f=>v(f,E),style:{paddingLeft:`${E.level*o+8}px`},className:A("flex items-center py-1 px-2 cursor-pointer hover:bg-accent hover:text-accent-foreground select-none text-xs","transition-colors duration-150 relative focus:outline-none focus:ring-1 focus:ring-ring",p===E.id&&"bg-primary/20 ring-1 ring-primary/50 rounded-sm",E.className),children:[r.jsx("div",{className:"w-4 h-4 mr-1 flex items-center justify-center shrink-0",children:y&&(E.isOpen?r.jsx(P.ChevronDown,{size:14}):r.jsx(P.ChevronRight,{size:14}))}),E.icon&&r.jsx("div",{className:"mr-2 flex items-center shrink-0",children:E.icon}),r.jsx("span",{className:"truncate",children:E.label})]},E.id)};return r.jsxs("div",{role:"tree","aria-label":d,className:A("h-full w-full bg-muted/30",c),onContextMenu:w=>v(w,null),children:[i?r.jsx(Ee.Virtuoso,{style:{height:"100%"},totalCount:N.length,itemContent:b}):r.jsx("div",{className:"h-full overflow-auto",children:N.map((w,E)=>b(E))}),l&&k.length>0&&r.jsx(nt,{x:l.x,y:l.y,items:k,onClose:()=>x(null)})]})},se={width:180,height:72},be={x:0,y:0,scale:1},j=t=>{var e,n;return{x:t.position.x,y:t.position.y,width:((e=t.size)==null?void 0:e.width)??se.width,height:((n=t.size)==null?void 0:n.height)??se.height}},Y=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),ce=(t,e)=>({x:(t.x-e.x)/e.scale,y:(t.y-e.y)/e.scale}),qt=(t,e)=>({x:t.x*e.scale+e.x,y:t.y*e.scale+e.y}),xe=(t,e,n)=>{const s=ce(e,t);return{scale:n,x:e.x-s.x*n,y:e.y-s.y*n}},de=(t,e=.1,n=4)=>Math.min(n,Math.max(e,t)),ye=(t,e)=>{const n=Y(t);switch(e){case"top":return{x:n.x,y:t.y};case"bottom":return{x:n.x,y:t.y+t.height};case"left":return{x:t.x,y:n.y};case"right":return{x:t.x+t.width,y:n.y}}},at=(t,e)=>{const n=Y(t),s=Y(e),a=s.x-n.x,o=s.y-n.y;return Math.abs(a)>=Math.abs(o)?a>=0?{source:"right",target:"left"}:{source:"left",target:"right"}:o>=0?{source:"bottom",target:"top"}:{source:"top",target:"bottom"}},ve=t=>{if(t.length===0)return null;const e=t.map(j),n=Math.min(...e.map(i=>i.x)),s=Math.min(...e.map(i=>i.y)),a=Math.max(...e.map(i=>i.x+i.width)),o=Math.max(...e.map(i=>i.y+i.height));return{x:n,y:s,width:a-n,height:o-s}},lt=(t,e)=>({x:(0-t.x)/t.scale,y:(0-t.y)/t.scale,width:e.width/t.scale,height:e.height/t.scale}),we=(t,e,n)=>({scale:n,x:e.width/2-t.x*n,y:e.height/2-t.y*n}),it=(t,e)=>{const n=Math.min(t.x,e.x),s=Math.min(t.y,e.y);return{x:n,y:s,width:Math.max(t.x+t.width,e.x+e.width)-n,height:Math.max(t.y+t.height,e.y+e.height)-s}},ct=(t,e,n=48)=>{const s=ve(t);if(!s||e.width===0||e.height===0)return be;const a=de(Math.min((e.width-n*2)/Math.max(s.width,1),(e.height-n*2)/Math.max(s.height,1))),o=Y(s);return{scale:a,x:e.width/2-o.x*a,y:e.height/2-o.y*a}},dt={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}},ue=(t,e,n)=>{const s=t.find(d=>d.id===e);if(!s)return null;const a=Y(j(s)),o=dt[n];let i=null;for(const d of t){if(d.id===e)continue;const c=Y(j(d)),l=c.x-a.x,x=c.y-a.y,p=l*o.x+x*o.y;if(p<=0)continue;const u=Math.abs(l*o.y-x*o.x);if(u>p*2)continue;const N=p+u*2;(!i||N<i.score)&&(i={node:d,score:N})}return(i==null?void 0:i.node)??null},ut=(t,e,n,s=64)=>{const a=t.find(l=>l.id===e);if(!a)return{x:0,y:0};const o=j(a),i=dt[n],d={x:i.x*(o.width+s),y:i.y*(o.height+s)};let c={x:o.x+d.x,y:o.y+d.y};for(let l=0;l<24;l+=1){const x={...c,width:o.width,height:o.height};if(!t.some(u=>Jt(j(u),x)))break;c=i.x!==0?{x:c.x,y:c.y+o.height+s}:{x:c.x+o.width+s,y:c.y}}return c},Jt=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y,Vt=(t,e)=>t.filter(n=>n.source===e||n.target===e),Qt=(t,e,n)=>t.some(s=>s.source===e&&s.target===n||s.source===n&&s.target===e),Zt=(t,e,n)=>({nodes:t.filter(s=>s.id!==n),edges:e.filter(s=>s.source!==n&&s.target!==n)}),Rt=(t,e)=>{let n=e.length+1;const s=new Set(e.map(a=>a.id));for(;s.has(`${t}-${n}`);)n+=1;return`${t}-${n}`},ft=g.forwardRef(({children:t,overlay:e,viewport:n,defaultViewport:s=be,onViewportChange:a,onSizeChange:o,onCanvasClick:i,onCanvasDoubleClick:d,onCanvasContextMenu:c,onDrop:l,grid:x=!0,gridSize:p=24,minScale:u=.1,maxScale:N=4,pannable:k=!0,zoomable:v=!0,"aria-label":b="Graph canvas",className:w},E)=>{const y=g.useRef(null),[f,M]=g.useState(s),[I,O]=g.useState(!1),[C,D]=g.useState(!1),h=n??f,T=g.useRef(h);T.current=h;const L=g.useCallback(S=>{n||M(S),a==null||a(S)},[n,a]),$=g.useCallback(S=>{var _;const z=(_=y.current)==null?void 0:_.getBoundingClientRect();return z?{x:S.x-z.left,y:S.y-z.top}:S},[]);g.useEffect(()=>{const S=y.current;if(!S||!o)return;const z=()=>{const B=S.getBoundingClientRect();o({width:B.width,height:B.height})};z();const _=new ResizeObserver(z);return _.observe(S),()=>_.disconnect()},[o]),g.useEffect(()=>{const S=y.current;if(!S||!v)return;const z=_=>{_.preventDefault();const B=T.current,H=$({x:_.clientX,y:_.clientY}),fe=_.ctrlKey?.01:.002,he=de(B.scale*Math.exp(-_.deltaY*fe),u,N);L(xe(B,H,he))};return S.addEventListener("wheel",z,{passive:!1}),()=>S.removeEventListener("wheel",z)},[v,u,N,L,$]),g.useEffect(()=>{if(!k)return;const S=_=>{var H;if(_.code!=="Space")return;const B=_.target;B!=null&&B.closest('input, textarea, [contenteditable="true"]')||(H=y.current)!=null&&H.contains(document.activeElement)&&(_.preventDefault(),D(!0))},z=_=>{_.code==="Space"&&D(!1)};return window.addEventListener("keydown",S),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",S),window.removeEventListener("keyup",z)}},[k]);const K=S=>{if(!k)return;const z=S.target===S.currentTarget,_=S.button===1;if(!z&&!_&&!C||S.button!==0&&!_)return;S.preventDefault(),O(!0);const B={x:S.clientX,y:S.clientY},H={...T.current},fe=bt=>{L({...H,x:H.x+(bt.clientX-B.x),y:H.y+(bt.clientY-B.y)})},he=()=>{O(!1),window.removeEventListener("pointermove",fe),window.removeEventListener("pointerup",he)};window.addEventListener("pointermove",fe),window.addEventListener("pointerup",he)};g.useImperativeHandle(E,()=>({getViewport:()=>T.current,setViewport:L,fitTo:(S,z)=>{var B;const _=(B=y.current)==null?void 0:B.getBoundingClientRect();_&&L(ct(S,{width:_.width,height:_.height},z))},zoomBy:S=>{var H;const z=(H=y.current)==null?void 0:H.getBoundingClientRect();if(!z)return;const _={x:z.width/2,y:z.height/2},B=de(T.current.scale*S,u,N);L(xe(T.current,_,B))},clientToGraph:S=>ce($(S),T.current),getSize:()=>{var z;const S=(z=y.current)==null?void 0:z.getBoundingClientRect();return{width:(S==null?void 0:S.width)??0,height:(S==null?void 0:S.height)??0}},focus:()=>{var S;return(S=y.current)==null?void 0:S.focus()}}),[L,u,N,$]);const U=S=>ce($({x:S.clientX,y:S.clientY}),h),G=S=>S.target===S.currentTarget;return r.jsxs("div",{ref:y,role:"application","aria-label":b,tabIndex:0,onPointerDown:K,onClick:S=>G(S)&&(i==null?void 0:i(U(S),S)),onDoubleClick:S=>G(S)&&(d==null?void 0:d(U(S),S)),onContextMenu:S=>{!c||!G(S)||(S.preventDefault(),c(U(S),S))},onDragOver:S=>{l&&(S.preventDefault(),S.dataTransfer.dropEffect="copy")},onDrop:S=>{l&&(S.preventDefault(),l(U(S),S))},style:x?{backgroundImage:"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)",backgroundSize:`${p*h.scale}px ${p*h.scale}px`,backgroundPosition:`${h.x}px ${h.y}px`}:void 0,className:A("relative w-full h-full overflow-hidden bg-background outline-none","focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset",C||I?"cursor-grabbing":"cursor-grab",w),children:[r.jsx("div",{style:{transform:`translate(${h.x}px, ${h.y}px) scale(${h.scale})`,transformOrigin:"0 0",willChange:"transform"},className:"absolute inset-0 pointer-events-none [&>*]:pointer-events-auto",children:t}),e&&r.jsx("div",{className:"absolute inset-0 pointer-events-none [&>*]:pointer-events-auto",children:e})]})});ft.displayName="GraphCanvas";const er=["top","right","bottom","left"],tr={top:"left-1/2 -translate-x-1/2 -top-1.5",bottom:"left-1/2 -translate-x-1/2 -bottom-1.5",left:"top-1/2 -translate-y-1/2 -left-1.5",right:"top-1/2 -translate-y-1/2 -right-1.5"},rr=({node:t,children:e,onMove:n,onMoveEnd:s,onSelect:a,onActivate:o,onContextMenu:i,onConnectStart:d,onConnectEnd:c,selected:l=!1,focused:x=!1,ports:p=!0,draggable:u=!0,className:N})=>{var E,y;const k=g.useRef(!1),v=((E=t.size)==null?void 0:E.width)??se.width,b=((y=t.size)==null?void 0:y.height)??se.height,w=f=>{if(!u||!n||f.button!==0||f.nativeEvent.shiftKey)return;f.stopPropagation(),k.current=!1;const M={x:f.clientX,y:f.clientY},I={...t.position},O=sr(f.currentTarget);let C=I;const D=T=>{const L=(T.clientX-M.x)/O,$=(T.clientY-M.y)/O;(Math.abs(L)>1||Math.abs($)>1)&&(k.current=!0),C={x:I.x+L,y:I.y+$},n(t.id,C)},h=()=>{k.current&&(s==null||s(t.id,C)),window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",h)};return r.jsxs("div",{"data-graph-node":t.id,role:"button",tabIndex:-1,"aria-pressed":l,style:{position:"absolute",left:t.position.x,top:t.position.y,width:v,height:b},onPointerDown:w,onClick:f=>{f.stopPropagation(),k.current||a==null||a(t.id,f)},onDoubleClick:f=>{f.stopPropagation(),o==null||o(t.id)},onContextMenu:f=>{i&&(f.preventDefault(),f.stopPropagation(),i(t.id,{x:f.clientX,y:f.clientY},f))},onPointerUp:()=>c==null?void 0:c(t.id),className:A("group rounded-lg border bg-card text-card-foreground shadow-sm select-none","flex flex-col overflow-hidden transition-shadow",u&&n&&"cursor-grab active:cursor-grabbing",l?"border-primary shadow-md":"border-border",x&&"ring-2 ring-ring ring-offset-1 ring-offset-background",N),children:[e,p&&d&&er.map(f=>r.jsx("button",{type:"button",tabIndex:-1,"aria-label":`Connect from ${f}`,onPointerDown:M=>{M.stopPropagation(),d(t.id,f)},className:A("absolute w-3 h-3 rounded-full border-2 border-background bg-primary","opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity",x&&"opacity-100",tr[f])},f))]})},sr=t=>{let e=t.parentElement;for(;e;){const n=window.getComputedStyle(e).transform;if(n&&n!=="none"){const s=/matrix\(([^,]+),/.exec(n),a=s?parseFloat(s[1]):NaN;if(Number.isFinite(a)&&a!==0)return a}e=e.parentElement}return 1},ht=(t,e,n,s)=>{if(s==="straight")return`M ${t.x} ${t.y} L ${e.x} ${e.y}`;const a=n==="left"||n==="right";if(s==="smoothstep"){const l=a?(t.x+e.x)/2:(t.y+e.y)/2;return a?`M ${t.x} ${t.y} L ${l} ${t.y} L ${l} ${e.y} L ${e.x} ${e.y}`:`M ${t.x} ${t.y} L ${t.x} ${l} L ${e.x} ${l} L ${e.x} ${e.y}`}const o=Math.hypot(e.x-t.x,e.y-t.y),i=Math.min(Math.max(o/2,24),160),d=a?{x:t.x+(n==="right"?i:-i),y:t.y}:{x:t.x,y:t.y+(n==="bottom"?i:-i)},c=a?{x:e.x-(n==="right"?i:-i),y:e.y}:{x:e.x,y:e.y-(n==="bottom"?i:-i)};return`M ${t.x} ${t.y} C ${d.x} ${d.y}, ${c.x} ${c.y}, ${e.x} ${e.y}`},nr=({edge:t,source:e,target:n,routing:s="bezier",selected:a=!1,arrow:o=!0,onSelect:i,onContextMenu:d,className:c})=>{const l=j(e),x=j(n),p=at(l,x),u=ye(l,p.source),N=ye(x,p.target),k=ht(u,N,p.source,s),v={x:(u.x+N.x)/2,y:(u.y+N.y)/2},b=!!(i||d);return r.jsxs("g",{"data-graph-edge":t.id,className:A(b&&"cursor-pointer"),onClick:w=>{i&&(w.stopPropagation(),i(t.id,w))},onContextMenu:w=>{d&&(w.preventDefault(),w.stopPropagation(),d(t.id,{x:w.clientX,y:w.clientY},w))},children:[b&&r.jsx("path",{d:k,fill:"none",stroke:"transparent",strokeWidth:16}),r.jsx("path",{d:k,fill:"none",strokeWidth:a?2.5:1.5,markerEnd:o?"url(#nexus-graph-arrow)":void 0,className:A("transition-[stroke]",a?"stroke-primary":"stroke-border",c)}),t.label&&r.jsx("text",{x:v.x,y:v.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-muted-foreground text-[10px] font-medium select-none",style:{paintOrder:"stroke",stroke:"hsl(var(--background))",strokeWidth:4},children:t.label})]})},or=({children:t,className:e})=>r.jsxs("svg",{style:{position:"absolute",left:-5e4,top:-5e4,overflow:"visible"},width:1e5,height:1e5,viewBox:"-50000 -50000 100000 100000",className:A("pointer-events-none [&_g]:pointer-events-auto",e),children:[r.jsx("defs",{children:r.jsx("marker",{id:"nexus-graph-arrow",viewBox:"0 0 10 10",refX:9,refY:5,markerWidth:6,markerHeight:6,orient:"auto-start-reverse",children:r.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-border"})})}),t]}),ar={moveFocus:["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],createConnected:"Tab",edit:"Enter",cancel:"Escape",delete:["Delete","Backspace"],connect:"c",nudgeModifier:"shiftKey"},lr={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},ir=({nodes:t,edges:e,focusedId:n,defaultFocusedId:s=null,onFocusChange:a,targetRef:o,nudgeDistance:i=16,disabled:d=!1,onCreateNode:c,onConnect:l,onDeleteNode:x,onMoveNode:p,onEditNode:u})=>{const[N,k]=g.useState(s),[v,b]=g.useState(null),[w,E]=g.useState(null),y=n!==void 0?n:N,f=g.useCallback(C=>{n===void 0&&k(C),a==null||a(C)},[n,a]),M=g.useRef({nodes:t,edges:e,focusedId:y,editingId:v,connectingFrom:w});M.current={nodes:t,edges:e,focusedId:y,editingId:v,connectingFrom:w};const I=g.useCallback(C=>{const{nodes:D,focusedId:h}=M.current;if(D.length===0)return;if(!h){f(D[0].id);return}const T=ue(D,h,C);T&&f(T.id)},[f]),O=g.useCallback((C="right")=>{const{nodes:D,focusedId:h}=M.current;if(!c)return;const T=h?ut(D,h,C):{x:0,y:0},L=c(T,{from:h??void 0,direction:C});L&&(h&&(l==null||l(h,L)),f(L),b(L))},[c,l,f]);return g.useEffect(()=>{if(d)return;const C=o.current;if(!C)return;const D=h=>{const{focusedId:T,editingId:L,connectingFrom:$}=M.current;if(L){h.key==="Escape"&&(h.preventDefault(),b(null));return}const K=h.target;if(K!=null&&K.closest('input, textarea, select, [contenteditable="true"]'))return;const U=lr[h.key];if(U){h.preventDefault();const G=M.current.nodes.find(S=>S.id===T);if(h.shiftKey&&G&&p){const S={up:{x:0,y:-i},down:{x:0,y:i},left:{x:-i,y:0},right:{x:i,y:0}}[U];p(G.id,{x:G.position.x+S.x,y:G.position.y+S.y});return}I(U);return}switch(h.key){case"Tab":{if(!c)return;h.preventDefault(),O(h.shiftKey?"left":"right");return}case"Enter":{if(!T)return;if(h.preventDefault(),$&&$!==T){l==null||l($,T),E(null);return}u==null||u(T),b(T);return}case"Escape":{h.preventDefault(),$?E(null):f(null);return}case"Delete":case"Backspace":{if(!T||!x)return;h.preventDefault();const G=M.current.nodes.filter(z=>z.id!==T),S=ue(M.current.nodes,T,"left")??ue(M.current.nodes,T,"right")??G[0]??null;x(T),f((S==null?void 0:S.id)??null);return}case"c":case"C":{if(!T||!l||h.metaKey||h.ctrlKey)return;h.preventDefault(),E($===T?null:T);return}}};return C.addEventListener("keydown",D),()=>C.removeEventListener("keydown",D)},[d,o,I,O,i,l,c,x,u,p,f]),g.useEffect(()=>{y&&!t.some(C=>C.id===y)&&f(null),v&&!t.some(C=>C.id===v)&&b(null),w&&!t.some(C=>C.id===w)&&E(null)},[t,y,v,w,f]),g.useMemo(()=>({focusedId:y,setFocusedId:f,editingId:v,setEditingId:b,connectingFrom:w,setConnectingFrom:E,moveFocus:I,createConnected:O}),[y,f,v,w,I,O])},cr=({nodes:t,viewport:e,canvasSize:n,onViewportChange:s,width:a=180,height:o=120,nodeColor:i,highlightIds:d,padding:c=8,panDistance:l=80,"aria-label":x="Graph minimap",className:p})=>{const u=g.useRef(null),N=g.useMemo(()=>new Set(d??[]),[d]),k=lt(e,n),v=g.useMemo(()=>{const D=ve(t);return D?it(D,k):k},[t,k.x,k.y,k.width,k.height]),b=Math.min((a-c*2)/Math.max(v.width,1),(o-c*2)/Math.max(v.height,1)),w={x:(a-v.width*b)/2-v.x*b,y:(o-v.height*b)/2-v.y*b},E=D=>({x:D.x*b+w.x,y:D.y*b+w.y}),y=D=>({x:(D.x-w.x)/b,y:(D.y-w.y)/b}),f=g.useCallback(D=>{var L;if(!s)return;const h=(L=u.current)==null?void 0:L.getBoundingClientRect();if(!h)return;const T=y({x:D.x-h.left,y:D.y-h.top});s(we(T,n,e.scale))},[s,n,e.scale,b,w.x,w.y]),M=D=>{var L;if(!s||D.button!==0)return;D.preventDefault(),(L=u.current)==null||L.focus(),f({x:D.clientX,y:D.clientY});const h=$=>f({x:$.clientX,y:$.clientY}),T=()=>{window.removeEventListener("pointermove",h),window.removeEventListener("pointerup",T)};window.addEventListener("pointermove",h),window.addEventListener("pointerup",T)},I=D=>{if(!s)return;const h={ArrowUp:{x:0,y:-l},ArrowDown:{x:0,y:l},ArrowLeft:{x:-l,y:0},ArrowRight:{x:l,y:0}}[D.key];if(!h)return;D.preventDefault();const T=Y(k);s(we({x:T.x+h.x,y:T.y+h.y},n,e.scale))},O={x:E(k).x,y:E(k).y,width:k.width*b,height:k.height*b},C=!!s;return r.jsx("div",{ref:u,role:C?"slider":"img","aria-label":x,"aria-valuetext":t.length===0?"Empty graph":`${t.length} nodes, viewing around ${Math.round(Y(k).x)}, ${Math.round(Y(k).y)}`,tabIndex:C?0:void 0,onPointerDown:M,onKeyDown:I,style:{width:a,height:o},className:A("rounded-lg border border-border bg-card/90 backdrop-blur-sm shadow-sm overflow-hidden","focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",C&&"cursor-pointer",p),children:r.jsxs("svg",{width:a,height:o,className:"block",children:[t.map(D=>{const h=j(D),T=E(h),L=N.has(D.id);return r.jsx("rect",{x:T.x,y:T.y,width:Math.max(h.width*b,2),height:Math.max(h.height*b,2),rx:1,fill:L||i==null?void 0:i(D),className:A(!i&&!L&&"fill-muted-foreground/50",L&&"fill-primary")},D.id)}),n.width>0&&r.jsx("rect",{x:O.x,y:O.y,width:Math.max(O.width,4),height:Math.max(O.height,4),rx:2,className:"fill-primary/10 stroke-primary",strokeWidth:1.5})]})})},dr=(t,e)=>{const n=new Set(t.map(l=>l.id)),s=new Map,a=new Map;t.forEach(l=>{s.set(l.id,[]),a.set(l.id,0)}),e.forEach(l=>{!n.has(l.source)||!n.has(l.target)||(s.get(l.source).push(l.target),a.set(l.target,(a.get(l.target)??0)+1))});const o=new Map,i=[],d=l=>{o.set(l,0),i.push(l)};t.forEach(l=>{(a.get(l.id)??0)===0&&d(l.id)}),i.length===0&&t.length>0&&d(t[0].id);let c=t.length*t.length+t.length;for(;i.length>0&&c>0;){c-=1;const l=i.shift(),x=o.get(l)??0;for(const p of s.get(l)??[]){const u=o.get(p);(u===void 0||u<x+1)&&(o.set(p,x+1),i.push(p))}}return t.forEach(l=>{o.has(l.id)||d(l.id)}),o},Ne=({direction:t="down",nodeSpacing:e=48,layerSpacing:n=96,origin:s={x:0,y:0},align:a="center"}={})=>(o,i)=>{if(o.length===0)return o;const d=dr(o,i),c=t==="down"||t==="up",l=new Map;o.forEach(y=>{const f=d.get(y.id)??0,M=l.get(f)??[];M.push(y),l.set(f,M)});const x=[...l.keys()].sort((y,f)=>y-f),p=new Map;x.forEach(y=>{const f=l.get(y),M=Math.max(...f.map(I=>{const O=j(I);return c?O.height:O.width}));p.set(y,M)});const u=new Map;let N=0;x.forEach(y=>{u.set(y,N),N+=(p.get(y)??0)+n});const k=y=>{const f=l.get(y);return f.map(I=>{const O=j(I);return c?O.width:O.height}).reduce((I,O)=>I+O,0)+e*(f.length-1)},v=Math.max(...x.map(k)),b=t==="up"||t==="left",w=N-n,E=new Map;return x.forEach(y=>{const f=l.get(y),M=k(y);let I=a==="center"?(v-M)/2:0;const O=u.get(y)??0,C=b?w-O-(p.get(y)??0):O;f.forEach(D=>{const h=j(D),T=c?h.width:h.height,L=c?h.height:h.width,$=C+((p.get(y)??0)-L)/2;E.set(D.id,c?{x:s.x+I,y:s.y+$}:{x:s.x+$,y:s.y+I}),I+=T+e})}),o.map(y=>{const f=E.get(y.id);return f?{...y,position:f}:y})},gt=({columns:t,spacingX:e=48,spacingY:n=48,origin:s={x:0,y:0}}={})=>a=>{if(a.length===0)return a;const o=Math.max(1,t??Math.ceil(Math.sqrt(a.length))),i=Math.ceil(a.length/o),d=Array.from({length:o},(p,u)=>Math.max(...a.filter((N,k)=>k%o===u).map(N=>j(N).width))),c=Array.from({length:i},(p,u)=>Math.max(...a.filter((N,k)=>Math.floor(k/o)===u).map(N=>j(N).height))),l=[];d.reduce((p,u,N)=>(l[N]=p,p+u+e),0);const x=[];return c.reduce((p,u,N)=>(x[N]=p,p+u+n),0),a.map((p,u)=>({...p,position:{x:s.x+l[u%o],y:s.y+x[Math.floor(u/o)]}}))},pt={vertical:Ne({direction:"down"}),horizontal:Ne({direction:"right"}),grid:gt()},ne="freeform",ur=({nodes:t,edges:e,layouts:n=pt,mode:s,defaultMode:a=ne,onModeChange:o,onNodeMove:i,escapeOnDrag:d=!0})=>{const[c,l]=g.useState(a),x=s??c,p=g.useCallback(E=>{s===void 0&&l(E),o==null||o(E)},[s,o]),u=x===ne?void 0:n[x],N=!!u,k=g.useMemo(()=>u?u(t,e):t,[u,t,e]),v=g.useCallback((E,y)=>{N&&d&&p(ne),i==null||i(E,y)},[N,d,p,i]),b=g.useCallback(()=>k,[k]),w=g.useMemo(()=>Object.keys(n).filter(E=>E!==ne),[n]);return g.useMemo(()=>({nodes:k,mode:x,setMode:p,available:w,isAuto:N,onMove:v,bake:b}),[k,x,p,w,N,v,b])},ke="application/x-nexus-graph-node",fr=({items:t,onSelect:e,onDragStart:n,orientation:s="auto",onOrientationChange:a,iconOnly:o=!1,className:i,"aria-label":d="Node palette"})=>{const c=g.useRef(null),[l,x]=g.useState("horizontal"),p=s==="auto"?l:s,u=g.useRef(a);u.current=a;const N=g.useCallback(()=>{const v=c.current;if(!v)return;const b=[...v.querySelectorAll("[data-palette-item]")];if(b.length===0)return;const w=window.getComputedStyle(v),E=parseFloat(w.gap)||0,y=(parseFloat(w.paddingLeft)||0)+(parseFloat(w.paddingRight)||0),f=b.reduce((D,h)=>D+h.offsetWidth,0)+E*(b.length-1)+y,M=b.reduce((D,h)=>D+h.offsetHeight,0)+E*(b.length-1)+y,I=hr(v);if(!I)return;const O=4,C=f<=I.width+O?"horizontal":M<=I.height+O?"vertical":"horizontal";x(D=>{var h;return D===C?D:((h=u.current)==null||h.call(u,C),C)})},[]);g.useEffect(()=>{if(s!=="auto")return;const v=c.current;if(!v)return;N();const b=new ResizeObserver(N);b.observe(v);const w=mt(v);return w&&w!==v&&b.observe(w),()=>b.disconnect()},[s,N,t.length]);const k=p==="vertical";return r.jsx("div",{ref:c,role:"toolbar","aria-label":d,"aria-orientation":p,"data-orientation":p,className:A("flex gap-1.5 p-1.5 rounded-lg border border-border bg-card/90 backdrop-blur-sm shadow-sm",k?"flex-col items-stretch":"flex-wrap items-center",i),children:t.map(v=>r.jsxs("button",{type:"button","data-palette-item":!0,draggable:!0,title:v.description??(o?v.label:void 0),"aria-label":o?v.label:void 0,onDragStart:b=>{b.dataTransfer.setData(ke,v.kind),b.dataTransfer.setData("text/plain",v.label),b.dataTransfer.effectAllowed="copy",n==null||n(v)},onClick:()=>e==null?void 0:e(v),className:A("flex items-center gap-1.5 rounded-md text-xs font-medium","border border-border bg-background text-foreground","hover:bg-accent hover:text-accent-foreground transition-colors","cursor-grab active:cursor-grabbing","focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",o?"p-2 justify-center":"px-2.5 py-1.5",k&&!o&&"justify-start"),children:[v.icon,!o&&v.label]},v.kind))})},mt=t=>{let e=t.parentElement;for(let n=0;e&&n<6;n+=1){const s=e.getBoundingClientRect(),a=t.getBoundingClientRect();if(s.width>a.width+8)return e;e=e.parentElement}return null},hr=t=>{const e=mt(t);if(!e)return null;const n=window.getComputedStyle(e),s=e.getBoundingClientRect();return{width:s.width-(parseFloat(n.paddingLeft)||0)-(parseFloat(n.paddingRight)||0),height:s.height-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0)}},gr=t=>t.dataTransfer.getData(ke)||null;m.ActivityBar=Se,m.AppTitle=jt,m.BUILT_IN_LAYOUTS=pt,m.BUNDLED_THEMES=te,m.BUNDLED_THEME_CLASSES=$e,m.ChatPane=Ce,m.CommandPalette=Re,m.CommandRegistry=Ie,m.ConnectedActivityBar=Te,m.ConnectedChatPane=Me,m.ConnectedCommandPalette=_t,m.ConnectedMenuBar=Pe,m.ConnectedModal=Ft,m.ConnectedSidebarPane=Be,m.ConnectedStatusBar=Ge,m.ConnectedTerminalPane=We,m.ConnectedThemeSwitcher=Kt,m.ConnectedUserProfile=Bt,m.ContextMenu=nt,m.DEFAULT_COMMAND_IDS=Ct,m.DEFAULT_GRAPH_KEYS=ar,m.DEFAULT_NODE_SIZE=se,m.DEFAULT_SETTINGS_THEMES=ze,m.DEFAULT_THEME_OPTIONS=tt,m.DataGrid=Gt,m.FREEFORM=ne,m.GRAPH_NODE_MIME=ke,m.GraphCanvas=ft,m.GraphEdge=nr,m.GraphEdgeLayer=or,m.GraphMiniMap=cr,m.GraphNode=rr,m.IDENTITY_VIEWPORT=be,m.MenuBar=De,m.MenuRegistry=Le,m.Modal=et,m.NexusWorkspaceShell=Je,m.NodePalette=fr,m.QuickSearch=Ht,m.SearchWidget=Wt,m.SettingsPanel=Ue,m.ShellLayout=Je,m.SidebarPane=le,m.StatusBar=je,m.TerminalPane=He,m.ThemeSwitcher=rt,m.TreeWidget=Xt,m.UserProfile=st,m.centerOn=we,m.clampScale=de,m.cn=A,m.commandRegistry=q,m.componentRegistry=Ye,m.edgePath=ht,m.edgesOf=Vt,m.findNeighbour=ue,m.fitViewport=ct,m.graphBounds=ve,m.gridLayout=gt,m.initializeShell=Lt,m.isConnected=Qt,m.layeredLayout=Ne,m.menuRegistry=ae,m.nextId=Rt,m.nodeRect=j,m.placeRelativeTo=ut,m.pluginRegistry=At,m.portPoint=ye,m.readPaletteDrag=gr,m.rectCenter=Y,m.removeNode=Zt,m.resolvePorts=at,m.themeClass=_e,m.toGraphSpace=ce,m.toScreenSpace=qt,m.unionRect=it,m.useChatStore=ee,m.useGraphKeyboard=ir,m.useGraphLayout=ur,m.useKeyboardShortcuts=Ot,m.useLayoutStore=qe,m.useModalStore=me,m.useRightSidebarStore=oe,m.useSidebarStore=W,m.useStatusBarStore=ie,m.useTerminalStore=Z,m.useThemeStore=Q,m.useUserProfileStore=V,m.viewportRect=lt,m.zoomAt=xe,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("flexlayout-react"),require("flexlayout-react/style/light.css"),require("lucide-react"),require("clsx"),require("tailwind-merge"),require("zustand"),require("react-virtuoso")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","flexlayout-react","flexlayout-react/style/light.css","lucide-react","clsx","tailwind-merge","zustand","react-virtuoso"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p.NexusShell={},p.jsxRuntime,p.React,p.FlexLayout,null,p.lucideReact,p.clsx,p.tailwindMerge,p.zustand,p.reactVirtuoso))})(this,function(p,r,b,U,Kr,O,Ut,Kt,q,Ie){"use strict";var zr=Object.defineProperty;var Ur=(p,r,b)=>r in p?zr(p,r,{enumerable:!0,configurable:!0,writable:!0,value:b}):p[r]=b;var ne=(p,r,b)=>Ur(p,typeof r!="symbol"?r+"":r,b);function L(...e){return Kt.twMerge(Ut.clsx(e))}const Bt=[{id:"settings",label:"Settings",icon:O.Settings}],Ae=({items:e=[],bottomItems:t=Bt,activeId:s=null,onSelect:n,className:o,"aria-label":a="Activity Bar"})=>{const l=({id:d,label:c,icon:i})=>r.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(d),"aria-label":c,title:c,"aria-pressed":s===d,className:L("p-2 cursor-pointer rounded text-muted-foreground hover:text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",s===d&&"text-foreground border-l-2 border-primary rounded-none"),children:r.jsx(i,{size:20})},d);return r.jsxs("aside",{role:"navigation","aria-label":a,className:L("w-12 h-full bg-muted border-r flex flex-col items-center py-2 select-none",o),children:[r.jsx("div",{className:"flex-1 flex flex-col space-y-4",children:e.map(l)}),t.length>0&&r.jsx("div",{className:"flex flex-col space-y-4",children:t.map(l)})]})},le="nexus-shell-sidebar",W=q.create(e=>{const t=localStorage.getItem(le);return{activeSidebar:t!==null?t:null,panels:[],setActiveSidebar:n=>{n===null?localStorage.removeItem(le):localStorage.setItem(le,n),e({activeSidebar:n})},toggleSidebar:n=>e(o=>{const a=o.activeSidebar===n?null:n;return a===null?localStorage.removeItem(le):localStorage.setItem(le,a),{activeSidebar:a}}),setPanels:n=>e({panels:n})}}),Pe=e=>{const t=W(a=>a.panels),s=W(a=>a.activeSidebar),n=W(a=>a.toggleSidebar),o=b.useMemo(()=>t.map(({id:a,label:l,icon:d})=>({id:a,label:l,icon:d})),[t]);return r.jsx(Ae,{...e,items:o,activeId:s,onSelect:n})},Gt=r.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center px-6 text-muted-foreground",children:[r.jsx(O.MessageCircle,{size:28,className:"mb-3 opacity-40"}),r.jsx("p",{className:"text-xs",children:"No messages yet."}),r.jsxs("p",{className:"text-[11px] mt-1 opacity-70",children:["Type a message, or ",r.jsx("span",{className:"font-mono",children:"/"})," for commands."]})]}),Oe=({messages:e=[],onSend:t,slashCommands:s=[],onSlashCommand:n,onClose:o,title:a="Chat",placeholder:l="Send a message…",emptyState:d=Gt,className:c})=>{const[i,g]=b.useState(""),[f,u]=b.useState(0),N=b.useRef(null),v=b.useRef(null),h=i.startsWith("/")?s.filter(m=>`/${m.command}`.startsWith(i.toLowerCase().split(" ")[0])):[],y=h.length>0;b.useEffect(()=>{v.current&&(v.current.scrollTop=v.current.scrollHeight)},[e]),b.useEffect(()=>{u(0)},[i]);const k=()=>{const m=i.trim();m&&(t==null||t(m),g(""))},E=m=>{var D;n==null||n(m),g(`/${m.command} `),(D=N.current)==null||D.focus()},w=m=>{if(y){if(m.key==="ArrowDown"){m.preventDefault(),u(D=>(D+1)%h.length);return}if(m.key==="ArrowUp"){m.preventDefault(),u(D=>(D-1+h.length)%h.length);return}if(m.key==="Tab"||m.key==="Enter"&&!m.shiftKey){m.preventDefault(),E(h[f]);return}}m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),k())};return r.jsxs("aside",{role:"complementary","aria-label":a,className:L("w-[320px] h-full bg-muted border-l border-border flex flex-col select-none shrink-0",c),children:[r.jsxs("div",{className:"h-10 flex items-center justify-between px-4 shrink-0",children:[r.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[r.jsx(O.MessageCircle,{size:13}),r.jsx("span",{className:"text-[11px] font-bold uppercase tracking-widest",children:a})]}),o&&r.jsx("button",{type:"button",onClick:o,"aria-label":"Close Chat",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(O.X,{size:14})})]}),r.jsx("div",{ref:v,role:"log","aria-label":`${a} transcript`,className:"flex-1 overflow-y-auto border-t border-border/50 bg-background/50 px-3 py-3 space-y-3",children:e.length===0?d:e.map(m=>{const D=m.role==="user";return r.jsxs("div",{className:L("flex flex-col",D?"items-end":"items-start"),children:[r.jsxs("div",{className:"flex items-center space-x-1 mb-1 text-[10px] uppercase tracking-wider text-muted-foreground font-bold",children:[D?r.jsx(O.User,{size:10}):r.jsx(O.Terminal,{size:10}),r.jsx("span",{children:m.author??(D?"You":"Assistant")})]}),r.jsx("div",{className:L("max-w-[85%] rounded-lg px-3 py-2 text-xs whitespace-pre-wrap break-words",D?"bg-primary text-primary-foreground":"bg-card border border-border text-foreground"),children:m.text})]},m.id)})}),r.jsxs("div",{className:"relative border-t border-border/50 p-2 shrink-0",children:[y&&r.jsx("div",{role:"listbox","aria-label":"Slash commands",className:"absolute bottom-full left-2 right-2 mb-1 bg-popover border border-border rounded-md shadow-lg overflow-hidden z-20",children:h.map((m,D)=>r.jsxs("div",{role:"option","aria-selected":D===f,onMouseEnter:()=>u(D),onClick:()=>E(m),className:L("px-3 py-1.5 text-xs cursor-pointer flex items-baseline justify-between gap-3",D===f?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[r.jsxs("span",{className:"font-mono",children:["/",m.command]}),r.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:m.description})]},m.command))}),r.jsxs("div",{className:"flex items-end space-x-2",children:[r.jsx("textarea",{ref:N,rows:1,value:i,"aria-label":`${a} message`,placeholder:l,onChange:m=>g(m.target.value),onKeyDown:w,className:"flex-1 resize-none bg-background border border-border rounded-md px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/50 max-h-32"}),r.jsx("button",{type:"button",onClick:k,disabled:!i.trim(),"aria-label":"Send message",className:"p-2 rounded-md bg-primary text-primary-foreground disabled:opacity-40 disabled:cursor-not-allowed hover:bg-primary/90 transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(O.Send,{size:14})})]})]})]})};let jt=0;const Ht=()=>`msg-${Date.now()}-${jt+=1}`,oe=q.create(e=>({messages:[],slashCommands:[],setMessages:t=>e({messages:t}),addMessage:t=>e(s=>({messages:[...s.messages,{...t,id:t.id??Ht()}]})),clearMessages:()=>e({messages:[]}),setSlashCommands:t=>e({slashCommands:t}),registerSlashCommand:t=>e(s=>({slashCommands:[...s.slashCommands,t]}))})),ve="nexus-shell-right-sidebar",de=q.create(e=>({isChatOpen:localStorage.getItem(ve)==="true",setChatOpen:n=>{localStorage.setItem(ve,String(n)),e({isChatOpen:n})},toggleChat:()=>e(n=>{const o=!n.isChatOpen;return localStorage.setItem(ve,String(o)),{isChatOpen:o}})})),$e=({onSend:e,...t})=>{const s=de(c=>c.isChatOpen),n=de(c=>c.setChatOpen),o=oe(c=>c.messages),a=oe(c=>c.slashCommands),l=oe(c=>c.addMessage);if(!s)return null;const d=c=>{if(l({role:"user",text:c}),c.startsWith("/")){const[i,...g]=c.slice(1).split(/\s+/),f=a.find(u=>u.command===i);if(f){f.execute(g);return}l({role:"assistant",text:`Unknown command: /${i}`});return}e==null||e(c)};return r.jsx(Oe,{...t,messages:o,slashCommands:a,onSend:d,onClose:()=>n(!1)})},Fe=({menus:e={},onSelect:t,title:s,center:n,right:o,className:a})=>{const l=c=>c.keybinding?r.jsx("span",{className:"text-[10px] text-muted-foreground opacity-60 ml-4",children:c.keybinding}):null,d=c=>r.jsx("div",{role:"menu",className:"absolute left-0 top-full hidden group-hover:block z-50 min-w-[180px] bg-popover text-popover-foreground border shadow-md rounded-md py-1",children:c.map(i=>r.jsxs("div",{className:"relative group/sub",children:[r.jsxs("div",{role:"menuitem",tabIndex:0,onClick:()=>!i.submenu&&(t==null?void 0:t(i)),onKeyDown:g=>{!i.submenu&&(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),t==null||t(i))},className:"px-3 py-1.5 hover:bg-accent hover:text-accent-foreground cursor-pointer text-xs flex justify-between items-center focus:outline-none focus:bg-accent",children:[r.jsx("span",{children:i.label}),r.jsxs("div",{className:"flex items-center space-x-2",children:[l(i),i.submenu&&r.jsx(O.ChevronRight,{size:10})]})]}),i.submenu&&r.jsx("div",{role:"menu",className:"absolute left-full top-0 hidden group-hover/sub:block z-[60] min-w-[180px] bg-popover text-popover-foreground border shadow-md rounded-md py-1 ml-[-2px]",children:i.submenu.map(g=>r.jsxs("div",{role:"menuitem",tabIndex:0,onClick:()=>t==null?void 0:t(g),onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),t==null||t(g))},className:"px-3 py-1.5 hover:bg-accent hover:text-accent-foreground cursor-pointer text-xs flex justify-between items-center focus:outline-none focus:bg-accent",children:[r.jsx("span",{children:g.label}),l(g)]},g.id))})]},i.id))});return r.jsxs("header",{role:"banner","aria-label":"Application Header",className:L("bg-muted border-b flex items-center justify-between px-4 select-none shrink-0 transition-all z-50 relative",s!==void 0?"h-12 bg-card/65 backdrop-blur-sm":"h-8",a),children:[r.jsxs("div",{className:"flex items-center flex-1 min-w-0",children:[s!==void 0?r.jsx("div",{className:"mr-12 flex items-center shrink-0",children:s}):r.jsx("div",{className:"font-semibold mr-6 text-sm shrink-0",children:"Nexus Shell"}),r.jsx("nav",{role:"navigation","aria-label":"Main Menu",className:"flex space-x-1 text-sm shrink-0",children:Object.entries(e).map(([c,i])=>r.jsxs("div",{className:"relative group",children:[r.jsx("div",{role:"button",tabIndex:0,"aria-haspopup":"menu",className:"cursor-pointer hover:bg-accent hover:text-accent-foreground px-3 py-1 rounded text-xs focus:outline-none focus:ring-2 focus:ring-ring",children:c}),i.length>0&&d(i)]},c))}),n&&r.jsx("div",{className:"ml-8 w-60 md:w-72 relative hidden sm:block",children:n})]}),o&&r.jsx("div",{className:"flex items-center ml-4 shrink-0",children:o})]})};class _e{constructor(){ne(this,"menus",new Map)}registerMenu(t,s){var n;this.menus.has(t)||this.menus.set(t,[]),(n=this.menus.get(t))==null||n.push(s)}setMenus(t){this.menus=new Map(Object.entries(t))}getMenu(t){return this.menus.get(t)||[]}getAllMenus(){const t={};return this.menus.forEach((s,n)=>{t[n]=s}),t}}const ue=new _e;class ze{constructor(){ne(this,"commands",new Map)}registerCommand(t){if(this.commands.has(t.id)){console.warn(`Command ${t.id} is already registered.`);return}this.commands.set(t.id,t)}executeCommand(t,...s){const n=this.commands.get(t);n?n.execute(...s):console.warn(`Command ${t} not found.`)}getCommand(t){return this.commands.get(t)}getCommands(){return Array.from(this.commands.values())}}const V=new ze,Ue=e=>e.map(t=>{var s;return{...t,keybinding:t.keybinding??(t.commandId?(s=V.getCommand(t.commandId))==null?void 0:s.keybinding:void 0),submenu:t.submenu?Ue(t.submenu):void 0}}),Ke=(e,t)=>{for(const s of e){if(s.id===t)return s;const n=s.submenu&&Ke(s.submenu,t);if(n)return n}},Be=e=>{const t=ue.getAllMenus(),s=Object.fromEntries(Object.entries(t).map(([o,a])=>[o,Ue(a)])),n=o=>{for(const a of Object.values(t)){const l=Ke(a,o.id);if(l!=null&&l.commandId){V.executeCommand(l.commandId);return}}};return r.jsx(Fe,{...e,menus:s,onSelect:n})},fe=({title:e,children:t,onClose:s,width:n="300px",className:o})=>r.jsxs("aside",{role:"tabpanel","aria-label":`${e} Panel`,style:{width:n},className:L("h-full bg-muted border-r flex flex-col select-none shrink-0",o),children:[r.jsxs("div",{className:"h-10 flex items-center justify-between px-4 text-[11px] font-bold text-muted-foreground uppercase tracking-widest",children:[r.jsx("span",{className:"truncate",children:e}),s&&r.jsx("button",{type:"button",onClick:s,"aria-label":"Close Panel",className:"p-1 hover:bg-accent hover:text-foreground rounded transition-colors focus:outline-none focus:ring-2 focus:ring-ring shrink-0",children:r.jsx(O.X,{size:14})})]}),r.jsx("div",{className:"flex-1 overflow-auto border-t border-border/50 bg-background/50",children:t})]}),ae=[{id:"light",label:"Light",shortLabel:"Light",description:"Neutral light theme. The default."},{id:"dark",label:"Dark",shortLabel:"Dark",description:"Low-glare dark theme on a soft grey base."},{id:"gt",label:"Georgia Tech",shortLabel:"GT",description:"Buzz Gold (#EAAA00) on Tech Tower White."},{id:"tamu",label:"Texas A&M",shortLabel:"TAMU",description:"Aggie Maroon (#500000) on white."}],Ge=ae.map(e=>`theme-${e.id}`),je=e=>`theme-${e}`,Wt={light:O.Sun,dark:O.Moon,gt:O.GraduationCap,tamu:O.GraduationCap},He=ae.map(e=>({id:e.id,label:e.label,icon:Wt[e.id]??O.Palette})),We=({theme:e,onThemeChange:t,themes:s=He,className:n})=>r.jsx("div",{className:L("p-4 space-y-6",n),children:r.jsxs("section",{children:[r.jsx("h3",{className:"text-[11px] font-bold text-muted-foreground uppercase mb-3",children:"Theme"}),r.jsx("div",{role:"radiogroup","aria-label":"Theme",className:"grid grid-cols-1 gap-2",children:s.map(({id:o,label:a,icon:l})=>r.jsxs("button",{type:"button",role:"radio","aria-checked":e===o,onClick:()=>t(o),className:L("flex items-center space-x-3 px-3 py-2 rounded-md border text-sm transition-all focus:outline-none focus:ring-2 focus:ring-ring",e===o?"bg-primary text-primary-foreground border-primary":"bg-background hover:bg-accent border-border"),children:[r.jsx(l,{size:16}),r.jsx("span",{children:a})]},o))})]})}),Ye="nexus-shell-theme",Xe=e=>{const t=window.document.documentElement,s=[...Ge,...Array.from(t.classList).filter(n=>n.startsWith("theme-"))];t.classList.remove(...s),t.classList.add(je(e))},te=q.create(e=>{const s=localStorage.getItem(Ye)||"light";return Xe(s),{theme:s,setTheme:n=>{localStorage.setItem(Ye,n),Xe(n),e({theme:n})}}}),qe=e=>{const t=W(i=>i.activeSidebar),s=W(i=>i.panels),n=W(i=>i.setActiveSidebar),o=te(i=>i.theme),a=te(i=>i.setTheme);if(!t)return null;const l=()=>n(null);if(t==="settings")return r.jsx(fe,{...e,title:"Settings",onClose:l,children:r.jsx(We,{theme:o,onThemeChange:i=>a(i)})});const d=s.find(i=>i.id===t);if(!d)return r.jsx(fe,{...e,title:t,onClose:l,children:r.jsx("div",{className:"p-4 text-sm italic text-muted-foreground",children:"Panel content not found."})});const c=typeof d.component=="function"?d.component:null;return r.jsx(fe,{...e,title:d.label,onClose:l,children:c?r.jsx(c,{}):d.component})},we=(e,t)=>(t.priority??0)-(e.priority??0),Je=({widgets:e=[],className:t,"aria-label":s="Status Bar"})=>{const n={left:e.filter(a=>a.alignment==="left").sort(we),center:e.filter(a=>a.alignment==="center").sort(we),right:e.filter(a=>a.alignment==="right").sort(we)},o=a=>{const l=a.icon,d=!!a.onClick;return r.jsxs("div",{onClick:a.onClick,onKeyDown:d?c=>{var i;(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),(i=a.onClick)==null||i.call(a))}:void 0,role:d?"button":void 0,tabIndex:d?0:void 0,className:L("flex items-center space-x-1.5 px-2 py-0.5 rounded transition-colors h-full focus:outline-none",d?"cursor-pointer hover:bg-white/10 focus:ring-1 focus:ring-white":"cursor-default",a.className),children:[l&&r.jsx(l,{size:12}),a.label&&r.jsx("span",{children:a.label})]},a.id)};return r.jsxs("footer",{role:"status","aria-label":s,className:L("h-6 bg-primary text-primary-foreground text-[11px] flex items-center justify-between px-1 select-none shrink-0 border-t border-white/5",t),children:[r.jsx("div",{className:"flex items-center space-x-1 h-full",children:n.left.map(o)}),r.jsx("div",{className:"flex items-center space-x-1 h-full",children:n.center.map(o)}),r.jsx("div",{className:"flex items-center space-x-1 h-full",children:n.right.map(o)})]})},he=q.create(e=>({widgets:[],setWidgets:t=>e({widgets:t}),addWidget:t=>e(s=>({widgets:[...s.widgets,t].sort((n,o)=>(o.priority||0)-(n.priority||0))})),removeWidget:t=>e(s=>({widgets:s.widgets.filter(n=>n.id!==t)})),updateWidget:(t,s)=>e(n=>({widgets:n.widgets.map(o=>o.id===t?{...o,...s}:o)}))})),Ve=e=>{const t=he(n=>n.widgets),s=b.useMemo(()=>t.map(({commandId:n,...o})=>({...o,onClick:o.onClick??(n?()=>V.executeCommand(n):void 0)})),[t]);return r.jsx(Je,{...e,widgets:s})},Qe=({history:e=[],onCommand:t,onClose:s,height:n="250px",prompt:o="$",title:a="Terminal",className:l})=>{const[d,c]=b.useState(""),i=b.useRef(null),g=b.useRef(null);b.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e]);const f=u=>{if(u.key!=="Enter")return;const N=d.trim();N&&(t==null||t(N),c(""))};return r.jsxs("div",{style:{height:n},className:L("bg-card border-t border-border flex flex-col shrink-0 font-mono text-xs",l),children:[r.jsxs("div",{className:"h-8 flex items-center justify-between px-3 border-b border-border/50 shrink-0",children:[r.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[r.jsx(O.Terminal,{size:13}),r.jsx("span",{className:"text-[11px] font-bold uppercase tracking-widest",children:a})]}),s&&r.jsxs("div",{className:"flex items-center space-x-1",children:[r.jsx("button",{type:"button",onClick:s,"aria-label":"Collapse Terminal",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(O.ChevronUp,{size:14})}),r.jsx("button",{type:"button",onClick:s,"aria-label":"Close Terminal",className:"p-1 rounded hover:bg-accent hover:text-foreground text-muted-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(O.X,{size:14})})]})]}),r.jsx("div",{ref:i,role:"log","aria-label":`${a} output`,className:"flex-1 overflow-y-auto px-3 py-2 space-y-0.5",onClick:()=>{var u;return(u=g.current)==null?void 0:u.focus()},children:e.map((u,N)=>r.jsx("div",{className:"whitespace-pre-wrap break-all text-foreground/90",children:u},N))}),r.jsxs("div",{className:"flex items-center px-3 py-2 border-t border-border/50 shrink-0",children:[r.jsx("span",{className:"text-primary mr-2 select-none",children:o}),r.jsx("input",{ref:g,type:"text","aria-label":`${a} input`,value:d,onChange:u=>c(u.target.value),onKeyDown:f,spellCheck:!1,autoComplete:"off",className:"flex-1 bg-transparent outline-none text-foreground placeholder:text-muted-foreground"})]})]})},re=q.create(e=>({isOpen:!1,history:["Welcome to Nexus Shell Terminal v0.1.0",'Type "help" for a list of commands.'],setOpen:t=>e({isOpen:t}),toggle:()=>e(t=>({isOpen:!t.isOpen})),addHistory:t=>e(s=>({history:[...s.history,t]})),clearHistory:()=>e({history:[]})})),Yt=["Available commands:"," help — show this message"," clear — clear the terminal"],Ze=({onCommand:e,...t})=>{const s=re(c=>c.isOpen),n=re(c=>c.history),o=re(c=>c.setOpen),a=re(c=>c.addHistory),l=re(c=>c.clearHistory);if(!s)return null;const d=c=>{a(`$ ${c}`);const i=c.toLowerCase();if(i==="clear"){l();return}if(i==="help"){Yt.forEach(a);return}(e==null?void 0:e(c))!==!0&&a(`command not found: ${c.split(" ")[0]}`)};return r.jsx(Qe,{...t,history:n,onCommand:d,onClose:()=>o(!1)})};class Xt{constructor(){ne(this,"components",new Map)}register(t,s){this.components.has(t)&&console.warn(`Component with ID "${t}" is already registered.`),this.components.set(t,s)}get(t){return this.components.get(t)}getRegisteredIds(){return Array.from(this.components.keys())}}const Re=new Xt,Q={global:{tabEnableClose:!0,tabSetEnableMaximize:!1,tabSetEnableDivide:!0},borders:[{type:"border",location:"left",children:[]}],layout:{type:"row",weight:100,children:[{type:"tabset",weight:50,children:[{type:"tab",name:"Welcome",component:"welcome"}]}]}},et="nexus-shell-layout",tt=q.create((e,t)=>{let s;if(typeof window<"u")try{const n=localStorage.getItem(et);if(n){const o=JSON.parse(n);s=U.Model.fromJson(o);const a=new Set(["dialogue-library","argument-inspector"]),l=[];s.visitNodes(d=>{if(d.getType()==="tab"){const c=d;a.has(c.getComponent())&&l.push(c.getId())}}),l.forEach(d=>{s.doAction(U.Actions.deleteTab(d))})}else s=U.Model.fromJson(Q)}catch(n){console.warn("Failed to load layout from storage, using default",n),s=U.Model.fromJson(Q)}else s=U.Model.fromJson(Q);return{model:s,dirtyTabs:new Set,storageKey:et,disableLocalStorage:!1,initLayout:(n,o)=>{let a;if(n&&Object.keys(n).length>0)try{a=U.Model.fromJson(n)}catch(l){console.warn("Failed to parse init layout json, using default",l),a=U.Model.fromJson(Q)}else a=U.Model.fromJson(Q);e({model:a,disableLocalStorage:o||!1})},setModel:n=>{e({model:n});const o=t().storageKey;if(typeof window<"u"&&!t().disableLocalStorage)try{localStorage.setItem(o,JSON.stringify(n.toJson()))}catch(a){console.error("Failed to save layout to storage",a)}},setStorageKey:(n,o)=>{let a;if(typeof window<"u")try{const l=localStorage.getItem(n);l?a=U.Model.fromJson(JSON.parse(l)):a=U.Model.fromJson(o||Q)}catch(l){console.warn("Failed to load layout from storage for key",n,l),a=U.Model.fromJson(o||Q)}else a=U.Model.fromJson(o||Q);e({storageKey:n,model:a})},setTabDirty:(n,o)=>{e(a=>{const l=new Set(a.dirtyTabs);return o?l.add(n):l.delete(n),{dirtyTabs:l}})},isTabDirty:n=>t().dirtyTabs.has(n),addTab:(n,o,a)=>{const l=t().model,d=l.getActiveTabset();let c=d==null?void 0:d.getId();if(!c)try{const f=l.getFirstTabSet();c=f==null?void 0:f.getId()}catch(f){console.warn("Failed to get first tabset fallback",f)}const g={...{},...a};if(["nexus-dashboard","nexus-docs"].includes(n)){let f=null;if(l.visitNodes(u=>{if(u.getType()==="tab"){const N=u;N.getComponent()===n&&(f=N.getId())}}),f){l.doAction(U.Actions.selectTab(f));return}}if(g.mapId){let f=null;if(l.visitNodes(u=>{var N;if(u.getType()==="tab"){const v=u;((N=v.getConfig())==null?void 0:N.mapId)===g.mapId&&(f=v.getId())}}),f){l.doAction(U.Actions.selectTab(f));return}}if(g.projectId){let f=null;if(l.visitNodes(u=>{var N;if(u.getType()==="tab"){const v=u;((N=v.getConfig())==null?void 0:N.projectId)===g.projectId&&(f=v.getId())}}),f){l.doAction(U.Actions.selectTab(f));return}}c&&l.doAction(U.Actions.addNode({type:"tab",component:n,name:o||n,config:g},c,U.DockLocation.CENTER,-1))}}}),Ne=q.create((e,t)=>({isOpen:!1,type:"alert",title:"",message:"",defaultValue:"",resolve:null,openAlert:(s,n="Alert")=>new Promise(o=>{e({isOpen:!0,type:"alert",title:n,message:s,defaultValue:"",resolve:o})}),openConfirm:(s,n="Confirm")=>new Promise(o=>{e({isOpen:!0,type:"confirm",title:n,message:s,defaultValue:"",resolve:o})}),openPrompt:(s,n="",o="Prompt")=>new Promise(a=>{e({isOpen:!0,type:"prompt",title:o,message:s,defaultValue:n,resolve:a})}),close:(s=null)=>{const{resolve:n}=t();n&&n(s),e({isOpen:!1,resolve:null})}})),rt=({panels:e,slashCommands:t,menuConfig:s,statusBarConfig:n,title:o,rightMenuBarContent:a,centerMenuBarContent:l,layoutModel:d,initialLayoutJson:c,disableLocalStorage:i=!1,onLayoutChange:g})=>{const{model:f,setModel:u,initLayout:N,isTabDirty:v,setTabDirty:h}=tt(),y=te(A=>A.theme),k=W(A=>A.setPanels),E=oe(A=>A.setSlashCommands),w=he(A=>A.setWidgets);b.useEffect(()=>{e&&k(e)},[e,k]),b.useEffect(()=>{t&&E(t)},[t,E]),b.useEffect(()=>{s&&ue.setMenus(s)},[s]),b.useEffect(()=>{n&&w(n)},[n,w]),b.useEffect(()=>{d||!c&&!i||N(c,i)},[]);const m=A=>{try{const P=A.getComponent(),M=A.getConfig()||{},C=P?Re.get(P):void 0;return C?r.jsx(C,{node:A,...M}):r.jsxs("div",{className:"p-4 text-sm",children:["Unknown Component: ",P]})}catch(P){return console.error("Error in component factory:",P),r.jsxs("div",{className:"p-8 text-destructive bg-destructive/10 border border-destructive/20 h-full flex items-center justify-center",children:["Error rendering component: ",P instanceof Error?P.message:"Unknown error"]})}},D=A=>{if(A.type!==U.Actions.DELETE_TAB)return A;const P=f.getNodeById(A.data.node);if(!P||!v(P.getId()))return A;Ne.getState().openConfirm(`Tab "${P.getName()}" has unsaved changes. Are you sure you want to close it?`).then(M=>{M&&(h(P.getId(),!1),f.doAction(A))})};return r.jsxs("div",{className:`flex flex-col h-screen w-screen bg-background text-foreground overflow-hidden theme-${y}`,children:[r.jsx(Be,{title:o,center:l,right:a}),r.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[r.jsx(Pe,{}),r.jsx(qe,{}),r.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-card",children:[r.jsx("div",{className:"flex-1 relative h-full w-full",children:r.jsx(U.Layout,{model:d||f,factory:m,onModelChange:A=>{d||u(A),g==null||g(A.toJson())},onAction:D})}),r.jsx(Ze,{})]}),r.jsx($e,{})]}),r.jsx(Ve,{})]})},st=ae.map(e=>({id:`theme.${e.id}`,label:`Preferences: ${e.label} Theme`,execute:()=>te.getState().setTheme(e.id)})),qt=["view.toggleTerminal","view.toggleChat","view.toggleSidebar",...st.map(e=>e.id)],Jt=[{id:"view.toggleTerminal",label:"View: Toggle Terminal",keybinding:"Control+`",execute:()=>re.getState().toggle()},{id:"view.toggleChat",label:"View: Toggle Chat",execute:()=>de.getState().toggleChat()},{id:"view.toggleSidebar",label:"View: Toggle Sidebar",keybinding:"Control+b",execute:()=>{var n;const{activeSidebar:e,panels:t,setActiveSidebar:s}=W.getState();s(e?null:((n=t[0])==null?void 0:n.id)??null)}},...st],Vt={View:[{id:"view.terminal",label:"Toggle Terminal",commandId:"view.toggleTerminal"},{id:"view.chat",label:"Toggle Chat",commandId:"view.toggleChat"},{id:"view.sidebar",label:"Toggle Sidebar",commandId:"view.toggleSidebar"},{id:"view.theme",label:"Theme",submenu:ae.map(e=>({id:`view.theme.${e.id}`,label:e.label,commandId:`theme.${e.id}`}))}]},Qt=(e={})=>{const{panels:t,menus:s,commands:n,statusBar:o,slashCommands:a,defaultCommands:l=!0,defaultMenus:d=!0}=e;l&&Jt.forEach(i=>V.registerCommand(i)),n==null||n.forEach(i=>V.registerCommand(i));const c={...l&&d?Vt:{},...s??{}};Object.keys(c).length>0&&ue.setMenus(c),t&&W.getState().setPanels(t),o&&he.getState().setWidgets(o),a&&oe.getState().setSlashCommands(a)};class Zt{constructor(){ne(this,"plugins",new Map);ne(this,"loaders",new Map);ne(this,"statuses",new Map)}registerPlugin(t){if(this.plugins.has(t.id)){console.warn(`Plugin ${t.id} is already registered.`);return}this.plugins.set(t.id,t),this.statuses.set(t.id,"registered"),console.log(`Plugin ${t.name} (${t.id}) registered.`)}registerLazyPlugin(t,s){if(this.loaders.has(t)||this.plugins.has(t)){console.warn(`Plugin ${t} is already registered or has a loader.`);return}this.loaders.set(t,s),this.statuses.set(t,"inactive"),console.log(`Lazy plugin loader for ${t} registered.`)}async activatePlugin(t){let s=this.plugins.get(t);if(!s&&this.loaders.has(t))try{s=await this.loaders.get(t)(),this.plugins.set(t,s),this.statuses.set(t,"registered"),console.log(`Lazy plugin ${t} loaded.`)}catch(n){console.error(`Failed to load lazy plugin ${t}`,n),this.statuses.set(t,"failed");return}if(s)try{this.statuses.set(t,"activating"),s.activate(),this.statuses.set(t,"active"),console.log(`Plugin ${s.name} activated.`)}catch(n){console.error(`Failed to activate plugin ${t}`,n),this.statuses.set(t,"failed")}else console.warn(`Plugin ${t} not found for activation.`),this.statuses.set(t,"failed")}async deactivatePlugin(t){const s=this.plugins.get(t);if(s)try{s.deactivate(),this.statuses.set(t,"deactivated"),console.log(`Plugin ${s.name} deactivated.`)}catch(n){console.error(`Failed to deactivate plugin ${t}`,n),this.statuses.set(t,"failed")}}getPluginStatus(t){return this.statuses.get(t)}getPluginStatuses(){const t={};return this.statuses.forEach((s,n)=>{t[n]=s}),t}getPlugin(t){return this.plugins.get(t)}getAllPlugins(){return Array.from(this.plugins.values())}}const Rt=new Zt,nt="nexus-shell-user-profile",ot={name:"David Tech",role:"Shell Architect",email:"david@techmuch.io",avatarUrl:"",customAvatar:""},Z=q.create(e=>{let t={...ot};if(typeof window<"u")try{const n=localStorage.getItem(nt);n&&(t={...ot,...JSON.parse(n)})}catch(n){console.error("Failed to parse saved user profile:",n)}const s=n=>{if(typeof window<"u")try{localStorage.setItem(nt,JSON.stringify({name:n.name,role:n.role,email:n.email,avatarUrl:n.avatarUrl,customAvatar:n.customAvatar}))}catch(o){console.error("Failed to save user profile:",o)}};return{...t,updateProfile:n=>e(o=>{const a={...o,...n};return s(a),n}),setCustomAvatar:n=>e(o=>{const a={...o,customAvatar:n};return s(a),{customAvatar:n}}),clearCustomAvatar:()=>e(n=>{const o={...n,customAvatar:""};return s(o),{customAvatar:""}})}}),er=()=>{b.useEffect(()=>{const e=t=>{const s=V.getCommands();for(const n of s)if(n.keybinding&&tr(t,n.keybinding)){t.preventDefault(),n.execute();break}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])};function tr(e,t){var u;const s=t.split("+"),n=(u=s.pop())==null?void 0:u.toLowerCase(),o=s.includes("Control")||s.includes("Ctrl"),a=s.includes("Shift"),l=s.includes("Alt"),d=s.includes("Meta")||s.includes("Cmd"),c=e.ctrlKey,i=e.shiftKey,g=e.altKey,f=e.metaKey;return e.key.toLowerCase()===n&&c===o&&i===a&&g===l&&f===d}const rr=(e,t)=>{const s=t.toLowerCase();return e.label.toLowerCase().includes(s)||e.id.toLowerCase().includes(s)},at=({open:e,commands:t,onSelect:s,onClose:n,inline:o=!1,placeholder:a="Type a command to run…",filter:l=rr,className:d})=>{const[c,i]=b.useState(""),[g,f]=b.useState(0),u=b.useRef(null),N=b.useMemo(()=>t.filter(h=>l(h,c)),[t,c,l]);if(b.useEffect(()=>{var h;e&&(i(""),f(0),(h=u.current)==null||h.focus())},[e]),b.useEffect(()=>{f(0)},[c]),!e)return null;const v=h=>{h.key==="ArrowDown"?(h.preventDefault(),f(y=>N.length?(y+1)%N.length:0)):h.key==="ArrowUp"?(h.preventDefault(),f(y=>N.length?(y-1+N.length)%N.length:0)):h.key==="Enter"?(h.preventDefault(),N[g]&&s(N[g])):h.key==="Escape"&&(h.preventDefault(),n==null||n())};return r.jsx("div",{onClick:o?void 0:n,className:L("z-[100] flex items-start justify-center",o?"relative w-full max-w-xl":"fixed inset-0 pt-[10vh] bg-black/50 backdrop-blur-sm"),children:r.jsxs("div",{role:"dialog","aria-modal":!o,"aria-label":"Command Palette",onClick:h=>h.stopPropagation(),className:L("w-full max-w-xl bg-popover text-popover-foreground border shadow-2xl rounded-xl overflow-hidden animate-in fade-in zoom-in duration-200",d),children:[r.jsxs("div",{className:"flex items-center px-4 border-b",children:[r.jsx(O.Search,{size:18,className:"text-muted-foreground mr-3"}),r.jsx("input",{ref:u,type:"text",role:"combobox","aria-expanded":!0,"aria-controls":"command-palette-list","aria-label":"Command",placeholder:a,value:c,onChange:h=>i(h.target.value),onKeyDown:v,className:"flex-1 h-14 bg-transparent outline-none text-base text-foreground placeholder:text-muted-foreground"})]}),r.jsx("div",{id:"command-palette-list",role:"listbox",className:"max-h-[300px] overflow-y-auto py-2",children:N.length===0?r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:c?`No commands found matching "${c}"`:"No commands available."}):N.map((h,y)=>r.jsxs("div",{role:"option","aria-selected":y===g,onClick:()=>s(h),onMouseEnter:()=>f(y),className:L("px-4 py-2 cursor-pointer flex justify-between items-center text-sm",y===g?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[r.jsx("span",{children:h.label}),h.keybinding&&r.jsx("span",{className:"text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded border border-border/50",children:h.keybinding})]},h.id))}),r.jsxs("div",{className:"px-4 py-2 border-t bg-muted/30 flex justify-between items-center text-[10px] text-muted-foreground",children:[r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"↑↓"})," to navigate"]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"Enter"})," to select"]})]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border",children:"Esc"})," to close"]})]})]})})},sr=({shortcutKey:e="p",...t})=>{const[s,n]=b.useState(!1);return b.useEffect(()=>{if(e===null)return;const o=a=>{(a.metaKey||a.ctrlKey)&&a.shiftKey&&a.key.toLowerCase()===e&&(a.preventDefault(),n(l=>!l))};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e]),r.jsx(at,{...t,open:s,commands:V.getCommands(),onSelect:o=>{o.execute(),n(!1)},onClose:()=>n(!1)})},nr={alert:O.AlertCircle,confirm:O.HelpCircle,prompt:O.Info},or={alert:"text-destructive",confirm:"text-amber-500",prompt:"text-blue-500"},lt=({open:e,type:t="alert",title:s,message:n,defaultValue:o="",onConfirm:a,onCancel:l,confirmLabel:d,cancelLabel:c="Cancel",placeholder:i="Enter value…",className:g})=>{const[f,u]=b.useState(o),N=b.useRef(null);if(b.useEffect(()=>{if(!e||(u(o),t!=="prompt"))return;const k=window.setTimeout(()=>{var E,w;(E=N.current)==null||E.focus(),(w=N.current)==null||w.select()},50);return()=>window.clearTimeout(k)},[e,t,o]),b.useEffect(()=>{if(!e)return;const k=E=>{E.key==="Escape"&&(E.preventDefault(),l==null||l())};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[e,l]),!e)return null;const v=()=>a==null?void 0:a(t==="prompt"?f:void 0),h=k=>{k.key==="Enter"&&(k.preventDefault(),v())},y=nr[t];return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-background/80 backdrop-blur-sm transition-all duration-300",onClick:l,children:r.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:k=>k.stopPropagation(),onKeyDown:h,className:L("relative flex flex-col w-full max-w-md p-6 bg-card border border-border shadow-2xl rounded-2xl animate-in fade-in zoom-in-95 ring-1 ring-white/10",g),children:[r.jsx("button",{type:"button",onClick:l,"aria-label":"Close",className:"absolute top-4 right-4 p-1 rounded-full text-muted-foreground hover:bg-muted hover:text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:r.jsx(O.X,{size:18})}),r.jsxs("div",{className:"flex items-start space-x-4 mb-4",children:[r.jsx("div",{className:L("p-2 bg-muted rounded-full shrink-0",or[t]),children:r.jsx(y,{size:24})}),r.jsxs("div",{className:"flex-1 mt-1",children:[r.jsx("h2",{className:"text-lg font-semibold tracking-tight pr-6",children:s}),n&&r.jsx("p",{className:"text-sm text-muted-foreground mt-1 whitespace-pre-wrap",children:n})]})]}),t==="prompt"&&r.jsx("div",{className:"mt-2 mb-4",children:r.jsx("input",{ref:N,type:"text","aria-label":s,value:f,placeholder:i,onChange:k=>u(k.target.value),className:"w-full bg-background border border-border rounded-lg px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-all placeholder:text-muted-foreground/50"})}),r.jsxs("div",{className:"flex items-center justify-end space-x-3 mt-4",children:[t!=="alert"&&r.jsx("button",{type:"button",onClick:l,className:"px-4 py-2 text-sm font-medium rounded-lg border border-border hover:bg-muted transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:c}),r.jsx("button",{type:"button",onClick:v,autoFocus:t!=="prompt",className:"px-4 py-2 text-sm font-medium rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors focus:outline-none focus:ring-2 focus:ring-ring",children:d??(t==="alert"?"OK":"Confirm")})]})]})})},ar=e=>{const{isOpen:t,type:s,title:n,message:o,defaultValue:a,close:l}=Ne(),d=i=>{s==="prompt"?l(i??""):s==="confirm"?l(!0):l()},c=()=>{s==="prompt"?l(null):s==="confirm"?l(!1):l()};return r.jsx(lt,{...e,open:t,type:s,title:n,message:o,defaultValue:a,onConfirm:d,onCancel:c})},it=ae.map(e=>({id:e.id,label:e.shortLabel})),ct=({value:e,onChange:t,options:s=it,className:n,"aria-label":o="Theme"})=>r.jsx("div",{role:"radiogroup","aria-label":o,className:L("flex items-center border border-border rounded-lg p-0.5 bg-secondary/80 select-none",n),children:s.map(a=>r.jsx("button",{role:"radio","aria-checked":e===a.id,onClick:()=>t(a.id),className:L("px-2.5 py-1 text-[9px] font-extrabold uppercase rounded-md transition-all font-mono cursor-pointer outline-none focus-visible:ring-1 focus-visible:ring-ring",e===a.id?"bg-primary text-primary-foreground shadow":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:a.label},a.id))}),lr=e=>{const t=te(n=>n.theme),s=te(n=>n.setTheme);return r.jsx(ct,{...e,value:t,onChange:s})},dt=({profile:e,actions:t=[],onProfileChange:s,onAvatarChange:n,onClick:o,showName:a=!0,className:l})=>{const{name:d,role:c,email:i,avatarUrl:g}=e,[f,u]=b.useState(!1),[N,v]=b.useState(!1),[h,y]=b.useState(d),[k,E]=b.useState(c??""),w=b.useRef(null),m=b.useRef(null);b.useEffect(()=>{f&&(y(d),E(c??""),v(!1))},[f,d,c]),b.useEffect(()=>{if(!f)return;const M=C=>{w.current&&!w.current.contains(C.target)&&u(!1)};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[f]);const D=M=>{M.preventDefault(),s==null||s({name:h,role:k}),v(!1)},A=M=>{var x;const C=(x=M.target.files)==null?void 0:x[0];C&&(n==null||n(C)),M.target.value=""},P=M=>g?r.jsx("img",{src:g,alt:d,className:"w-full h-full object-cover"}):r.jsx(O.User,{size:M,className:"text-muted-foreground"});return r.jsxs("div",{ref:w,className:"relative inline-block text-left",children:[r.jsxs("button",{type:"button",onClick:()=>o?o():u(M=>!M),"aria-haspopup":o?void 0:"menu","aria-expanded":o?void 0:f,"aria-label":"User Profile Menu",className:L("focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none transition-all duration-200 select-none",a?"flex items-center space-x-2 px-2 py-1 rounded-md hover:bg-accent/50 hover:text-accent-foreground text-left cursor-pointer border border-transparent hover:border-border/30":"w-7 h-7 rounded-full bg-secondary/80 border border-border flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-secondary cursor-pointer",f&&(a?"bg-accent/60 border-border/40":"border-primary/50 text-foreground ring-1 ring-primary/20"),l),children:[r.jsx("div",{className:L("rounded-full overflow-hidden border border-border/50 bg-muted flex items-center justify-center shrink-0 shadow-sm",a?"w-6 h-6":"w-full h-full"),children:P(a?13:12)}),a&&r.jsxs("div",{className:"flex flex-col min-w-0 leading-tight pr-1",children:[r.jsx("span",{className:"text-[11px] font-semibold truncate text-foreground",children:d}),c&&r.jsx("span",{className:"text-[9px] text-muted-foreground/80 truncate font-medium",children:c})]})]}),n&&r.jsx("input",{type:"file",ref:m,onChange:A,accept:"image/*","aria-label":"Upload avatar",className:"hidden"}),f&&r.jsx("div",{role:"menu",className:L("absolute z-50 w-64 rounded-lg border border-border/50 bg-card text-card-foreground shadow-lg backdrop-blur-md p-2 flex flex-col gap-1 mt-1.5 animate-in fade-in slide-in-from-top-2 duration-150 origin-top-right",a?"left-0":"right-0"),children:N?r.jsxs("form",{onSubmit:D,className:"p-2 flex flex-col gap-2",children:[r.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:"Edit Profile"}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("label",{htmlFor:"profile-name",className:"text-[9px] font-semibold text-muted-foreground",children:"Name"}),r.jsx("input",{id:"profile-name",type:"text",value:h,onChange:M=>y(M.target.value),required:!0,className:"w-full px-2 py-1 text-xs border rounded bg-background focus:ring-1 focus:ring-primary focus:outline-none"})]}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("label",{htmlFor:"profile-role",className:"text-[9px] font-semibold text-muted-foreground",children:"Role"}),r.jsx("input",{id:"profile-role",type:"text",value:k,onChange:M=>E(M.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background focus:ring-1 focus:ring-primary focus:outline-none"})]}),r.jsxs("div",{className:"flex gap-1.5 mt-1 justify-end",children:[r.jsxs("button",{type:"button",onClick:()=>v(!1),className:"px-2 py-1 text-[10px] rounded hover:bg-accent text-muted-foreground flex items-center gap-1 border border-border/30",children:[r.jsx(O.X,{size:10})," Cancel"]}),r.jsxs("button",{type:"submit",className:"px-2 py-1 text-[10px] rounded bg-primary text-primary-foreground hover:bg-primary/95 flex items-center gap-1 font-semibold",children:[r.jsx(O.Check,{size:10})," Save"]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"p-2 flex items-center gap-3 border-b border-border/40 pb-2.5 mb-1",children:[r.jsxs("div",{onClick:()=>{var M;return n&&((M=m.current)==null?void 0:M.click())},title:n?"Upload avatar image":void 0,className:L("group relative w-12 h-12 rounded-full overflow-hidden border border-border/80 bg-muted flex items-center justify-center shrink-0 shadow-inner",n&&"cursor-pointer"),children:[P(24),n&&r.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 flex items-center justify-center transition-opacity",children:r.jsx(O.Camera,{size:14,className:"text-white"})})]}),r.jsxs("div",{className:"flex flex-col min-w-0 leading-normal flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-xs font-bold truncate text-foreground",children:d}),s&&r.jsx("button",{type:"button",onClick:()=>v(!0),title:"Edit Profile","aria-label":"Edit Profile",className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent/40 rounded transition-colors",children:r.jsx(O.Edit2,{size:10})})]}),c&&r.jsx("span",{className:"text-[10px] text-muted-foreground/80 truncate font-semibold",children:c}),i&&r.jsx("span",{className:"text-[9px] text-muted-foreground/60 truncate font-mono mt-0.5",children:i})]})]}),t.map(M=>{const C=M.icon;return r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{M.onSelect(),u(!1)},className:L("w-full px-2 py-1.5 text-left rounded-md text-[11px] font-medium flex items-center gap-2 cursor-pointer transition-colors",M.destructive?"text-destructive hover:bg-destructive/10":"hover:bg-accent/60 hover:text-accent-foreground",M.divider&&"border-t border-border/20 pt-2 mt-1"),children:[C&&r.jsx(C,{size:12,className:"opacity-70"}),M.label]},M.id)})]})})]})},ir=e=>{const t=Z(i=>i.name),s=Z(i=>i.role),n=Z(i=>i.email),o=Z(i=>i.avatarUrl),a=Z(i=>i.customAvatar),l=Z(i=>i.updateProfile),d=Z(i=>i.setCustomAvatar),c=i=>{const g=new FileReader;g.onloadend=()=>{typeof g.result=="string"&&d(g.result)},g.readAsDataURL(i)};return r.jsx(dt,{...e,profile:{name:t,role:s,email:n,avatarUrl:a||o},onProfileChange:l,onAvatarChange:c})},cr=({title:e,subtitle:t,icon:s,className:n})=>r.jsxs("div",{className:L("flex items-center space-x-3 select-none",n),children:[s&&r.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 border border-primary/30 flex items-center justify-center text-primary shadow-inner shrink-0",children:s}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h1",{className:"text-xs font-black uppercase tracking-wider text-foreground font-mono truncate",children:e}),t&&r.jsx("p",{className:"text-[9px] text-muted-foreground font-semibold truncate",children:t})]})]}),ut=({x:e,y:t,items:s,onClose:n,className:o})=>{const a=b.useRef(null);return b.useEffect(()=>{const l=c=>{a.current&&!a.current.contains(c.target)&&n()},d=c=>{c.key==="Escape"&&n()};return document.addEventListener("mousedown",l),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",d)}},[n]),r.jsx("div",{ref:a,role:"menu",style:{top:t,left:e},className:L("fixed z-[1000] min-w-[160px] bg-popover text-popover-foreground border shadow-md rounded-md py-1 animate-in fade-in zoom-in-95 duration-100",o),children:s.map((l,d)=>r.jsxs(b.Fragment,{children:[l.divider&&r.jsx("div",{className:"h-[1px] bg-border my-1"}),r.jsxs("div",{role:"menuitem",tabIndex:l.disabled?void 0:0,"aria-disabled":l.disabled,onClick:()=>{l.disabled||(l.onClick(),n())},onKeyDown:c=>{l.disabled||c.key!=="Enter"&&c.key!==" "||(c.preventDefault(),l.onClick(),n())},className:L("px-3 py-1.5 text-xs flex items-center focus:outline-none",l.disabled?"opacity-40 cursor-default":"cursor-pointer hover:bg-accent hover:text-accent-foreground focus:bg-accent"),children:[l.icon&&r.jsx("span",{className:"mr-2 opacity-70",children:l.icon}),r.jsx("span",{children:l.label})]})]},`${l.label}-${d}`))})},dr=({columns:e,data:t,onRowClick:s,selectedRowId:n,rowKey:o="id",virtualized:a=!0,showFilter:l=!0,loading:d=!1,placeholder:c="No data available",className:i})=>{const[g,f]=b.useState(""),[u,N]=b.useState(null),[v,h]=b.useState(-1),y=b.useRef(null);b.useEffect(()=>{h(-1)},[g,u]);const k=b.useMemo(()=>{if(!g)return t;const x=g.toLowerCase();return t.filter(T=>Object.values(T).some(I=>I==null?!1:String(I).toLowerCase().includes(x)))},[t,g]),E=b.useMemo(()=>{if(!u)return k;const{key:x,direction:T}=u;return[...k].sort((I,$)=>{const K=I[x],z=$[x];if(K===z)return 0;if(K==null)return 1;if(z==null)return-1;const j=Number(K),S=Number(z);if(!isNaN(j)&&!isNaN(S))return T==="asc"?j-S:S-j;const _=String(K).toLowerCase(),F=String(z).toLowerCase();return T==="asc"?_.localeCompare(F):F.localeCompare(_)})},[k,u]),w=(x,T)=>{T!==!1&&N(I=>!I||I.key!==x?{key:x,direction:"asc"}:I.direction==="asc"?{key:x,direction:"desc"}:null)},m=x=>{if(!(E.length===0||d)){if(x.key==="ArrowDown")x.preventDefault(),h(T=>{const I=T+1;return I>=E.length?0:I});else if(x.key==="ArrowUp")x.preventDefault(),h(T=>{const I=T-1;return I<0?E.length-1:I});else if((x.key==="Enter"||x.key===" ")&&(x.preventDefault(),v>=0&&v<E.length)){const T=E[v];s&&s(T)}}},D=x=>x.sortable===!1?null:(u==null?void 0:u.key)!==x.key?r.jsx(O.ChevronsUpDown,{size:14,className:"text-muted-foreground/60 ml-1.5 opacity-0 group-hover:opacity-100 transition-opacity"}):u.direction==="asc"?r.jsx(O.ChevronUp,{size:14,className:"text-primary ml-1.5"}):r.jsx(O.ChevronDown,{size:14,className:"text-primary ml-1.5"}),A=()=>r.jsx("tr",{role:"row",className:"border-b border-border bg-muted/30 select-none",children:e.map(x=>r.jsx("th",{role:"columnheader","aria-sort":(u==null?void 0:u.key)===x.key?u.direction==="asc"?"ascending":"descending":"none",className:L("p-3 text-xs font-semibold text-muted-foreground uppercase tracking-wider text-left transition-colors",x.sortable!==!1&&"cursor-pointer hover:bg-accent/30 hover:text-foreground group"),style:{width:x.width},onClick:()=>w(x.key,x.sortable),children:r.jsxs("div",{className:"flex items-center",children:[r.jsx("span",{children:x.header}),D(x)]})},x.key))}),P=(x,T)=>{const I=n!==void 0&&x[o]===n,$=v===T;return r.jsx("tr",{role:"row","aria-selected":I,onClick:()=>s&&s(x),className:L("border-b border-border/40 hover:bg-accent/40 transition-colors cursor-pointer text-sm outline-none",I&&"bg-primary/10 text-primary hover:bg-primary/15 font-medium border-l-2 border-l-primary",$&&"bg-accent/60 ring-1 ring-inset ring-ring"),children:e.map(K=>{const z=x[K.key];return r.jsx("td",{role:"gridcell",className:"p-3 align-middle truncate max-w-xs",children:K.render?K.render(z,x):z!=null?String(z):""},K.key)})},String(x[o]||T))},M=b.useMemo(()=>({Table:x=>r.jsx("table",{...x,role:"grid",className:"w-full border-collapse text-left bg-background text-foreground"}),TableHead:b.forwardRef((x,T)=>r.jsx("thead",{ref:T,...x,className:"sticky top-0 bg-background z-10 shadow-[0_1px_0_0_rgba(0,0,0,0.1)] dark:shadow-[0_1px_0_0_rgba(255,255,255,0.05)]"})),TableBody:b.forwardRef((x,T)=>r.jsx("tbody",{ref:T,...x})),TableRow:({item:x,context:T,...I})=>{if(!T||!x)return r.jsx("tr",{...I});const $=T.selectedRowId!==void 0&&x[T.rowKey]===T.selectedRowId,K=T.focusedIndex===I["data-index"];return r.jsx("tr",{...I,onClick:()=>{var z;return(z=T.onRowClick)==null?void 0:z.call(T,x)},className:L("border-b border-border/40 hover:bg-accent/40 transition-colors cursor-pointer text-sm outline-none",$&&"bg-primary/10 text-primary hover:bg-primary/15 font-medium border-l-2 border-l-primary",K&&"bg-accent/60 ring-1 ring-inset ring-ring")})}}),[]),C=()=>d?r.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-3",children:[r.jsx(O.Loader2,{className:"animate-spin text-primary",size:24}),r.jsx("span",{className:"text-xs text-muted-foreground",children:"Loading dataset..."})]}):E.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-48 text-center px-4",children:[r.jsx("span",{className:"text-sm font-medium text-foreground",children:c}),r.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"No items matched your search query."})]}):a?r.jsx("div",{className:"flex-1 min-h-[300px] h-full relative",children:r.jsx(Ie.TableVirtuoso,{data:E,context:{selectedRowId:n,focusedIndex:v,rowKey:o,onRowClick:s},components:M,fixedHeaderContent:A,itemContent:(x,T)=>r.jsx(r.Fragment,{children:e.map(I=>{const $=T[I.key];return r.jsx("td",{role:"gridcell",className:"p-3 align-middle truncate max-w-xs",children:I.render?I.render($,T):$!=null?String($):""},I.key)})})})}):r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("table",{role:"grid",className:"w-full border-collapse text-left bg-background text-foreground",children:[r.jsx("thead",{children:A()}),r.jsx("tbody",{children:E.map((x,T)=>P(x,T))})]})});return r.jsxs("div",{ref:y,role:"region","aria-label":"Data Grid",tabIndex:0,onKeyDown:m,className:L("flex flex-col h-full bg-background border border-border rounded-lg shadow-sm overflow-hidden focus:outline-none focus:ring-1 focus:ring-ring focus:border-transparent",i),children:[l&&r.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border bg-muted/20",children:[r.jsxs("div",{className:"relative flex-1 max-w-sm",children:[r.jsx(O.Search,{size:14,className:"absolute left-2.5 top-2.5 text-muted-foreground"}),r.jsx("input",{type:"text",placeholder:"Filter table rows...",className:"w-full bg-secondary/40 border border-border rounded-md pl-8 pr-7 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary focus:border-transparent transition-all",value:g,onChange:x=>f(x.target.value)}),g&&r.jsx("button",{onClick:()=>f(""),className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground","aria-label":"Clear filter",children:r.jsx(O.X,{size:12})})]}),r.jsxs("div",{className:"text-[11px] text-muted-foreground font-medium ml-4",children:[E.length," of ",t.length," records"]})]}),C()]})},ur=({results:e,onQueryChange:t,onSelect:s,categories:n,placeholder:o="Search…",debounceMs:a=200,className:l})=>{const[d,c]=b.useState(""),[i,g]=b.useState(!1),[f,u]=b.useState(0),N=b.useRef(null),v=b.useRef(null),h=b.useMemo(()=>n||[...new Set(e.map(w=>w.category))],[n,e]),y=b.useMemo(()=>h.flatMap(w=>e.filter(m=>m.category===w)),[h,e]);b.useEffect(()=>{const w=m=>{N.current&&!N.current.contains(m.target)&&g(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]),b.useEffect(()=>{if(!t)return;const w=window.setTimeout(()=>t(d),a);return()=>window.clearTimeout(w)},[d,a,t]),b.useEffect(()=>{u(0)},[e]);const k=w=>{s(w),g(!1),c("")},E=w=>{var m;if(!i){(w.key==="ArrowDown"||w.key==="Enter")&&g(!0);return}w.key==="ArrowDown"?(w.preventDefault(),u(D=>y.length?(D+1)%y.length:0)):w.key==="ArrowUp"?(w.preventDefault(),u(D=>y.length?(D-1+y.length)%y.length:0)):w.key==="Enter"?(w.preventDefault(),y[f]&&k(y[f])):w.key==="Escape"&&(w.preventDefault(),g(!1),(m=v.current)==null||m.blur())};return r.jsxs("div",{ref:N,className:L("relative w-full",l),children:[r.jsxs("div",{className:"relative flex items-center",children:[r.jsx(O.Search,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),r.jsx("input",{ref:v,type:"text",role:"combobox","aria-expanded":i,"aria-label":o,value:d,placeholder:o,onChange:w=>{c(w.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:E,className:"w-full h-7 pl-8 pr-7 bg-secondary/35 border border-border/40 rounded-md text-xs text-foreground placeholder:text-muted-foreground/75 focus:outline-none focus:ring-1 focus:ring-primary/40 focus:bg-background/95 focus:border-primary/50 transition-all font-sans"}),d&&r.jsx("button",{type:"button",onClick:()=>{var w;c(""),(w=v.current)==null||w.focus()},"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:r.jsx(O.X,{size:11})})]}),i&&d.trim()&&r.jsxs("div",{role:"listbox",className:"absolute right-0 md:left-0 mt-1.5 w-80 max-h-[380px] bg-popover text-popover-foreground border border-border shadow-lg rounded-lg overflow-hidden flex flex-col z-[100] animate-in fade-in-50 slide-in-from-top-1 duration-100",children:[r.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:y.length===0?r.jsxs("div",{className:"px-4 py-6 text-center text-xs text-muted-foreground italic",children:['No results found matching "',d,'"']}):h.map(w=>{const m=e.filter(D=>D.category===w);return m.length===0?null:r.jsxs("div",{className:"flex flex-col",children:[r.jsx("div",{className:"px-3 py-1 text-[9px] font-bold uppercase tracking-wider text-muted-foreground/80 bg-muted/40 border-y border-border/20 first:border-t-0",children:w}),m.map(D=>{const A=D.icon,P=y.indexOf(D),M=P===f;return r.jsxs("div",{role:"option","aria-selected":M,onClick:()=>k(D),onMouseEnter:()=>u(P),className:L("px-3 py-2 cursor-pointer flex items-start space-x-2.5 transition-colors border-l-2",M?"bg-accent text-accent-foreground border-primary":"border-transparent hover:bg-accent/40"),children:[A&&r.jsx("div",{className:L("mt-0.5 p-1 rounded bg-muted/50",M&&"bg-background text-primary"),children:r.jsx(A,{size:12})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs font-medium truncate",children:D.title}),D.description&&r.jsx("div",{className:"text-[10px] text-muted-foreground truncate mt-0.5",children:D.description})]})]},`${D.category}-${D.id}`)})]},w)})}),y.length>0&&r.jsxs("div",{className:"px-3 py-1.5 border-t border-border bg-muted/20 flex items-center justify-between text-[9px] text-muted-foreground select-none shrink-0 font-mono",children:[r.jsxs("div",{className:"flex space-x-2",children:[r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border border-border/60",children:"↑↓"})," ","navigate"]}),r.jsxs("span",{children:[r.jsx("kbd",{className:"bg-muted px-1 rounded border border-border/60",children:"↵"})," ","select"]})]}),r.jsx("span",{children:"ESC to close"})]})]})]})},fr=({placeholder:e="Search...",onSearch:t,results:s,onSelect:n,suggestions:o=[],loading:a=!1,className:l})=>{const[d,c]=b.useState(""),[i,g]=b.useState(!1),[f,u]=b.useState(-1),N=b.useRef(null);b.useEffect(()=>{const y=setTimeout(()=>{t(d)},300);return()=>clearTimeout(y)},[d,t]);const v=o.filter(y=>y.toLowerCase().includes(d.toLowerCase())&&y.toLowerCase()!==d.toLowerCase()),h=y=>{i&&v.length>0&&(y.key==="ArrowDown"?(y.preventDefault(),u(k=>(k+1)%v.length)):y.key==="ArrowUp"?(y.preventDefault(),u(k=>(k-1+v.length)%v.length)):y.key==="Enter"&&f>=0&&(y.preventDefault(),c(v[f]),g(!1)))};return r.jsxs("div",{ref:N,className:L("flex flex-col h-full bg-background",l),children:[r.jsxs("div",{className:"p-3 border-b border-border/50",children:[r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-2.5 top-2.5 text-muted-foreground",children:a?r.jsx(O.Loader2,{size:14,className:"animate-spin"}):r.jsx(O.Search,{size:14})}),r.jsx("input",{type:"text",className:"w-full bg-secondary/50 border border-border rounded-md pl-9 pr-8 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all",placeholder:e,value:d,onChange:y=>{c(y.target.value),g(!0),u(-1)},onKeyDown:h,onFocus:()=>g(!0)}),d&&r.jsx("button",{onClick:()=>{c(""),t("")},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:r.jsx(O.X,{size:14})})]}),i&&v.length>0&&r.jsx("div",{className:"absolute left-3 right-3 mt-1 bg-popover border shadow-lg rounded-md z-50 py-1 overflow-hidden",children:v.map((y,k)=>r.jsxs("div",{className:L("px-3 py-1.5 text-xs cursor-pointer flex items-center space-x-2",k===f?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onClick:()=>{c(y),g(!1)},children:[r.jsx(O.Clock,{size:12,className:"text-muted-foreground"}),r.jsx("span",{children:y})]},y))})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:s.length===0?r.jsx("div",{className:"p-8 text-center text-xs text-muted-foreground italic",children:d?`No results found for "${d}"`:"Type to start searching..."}):r.jsx("div",{className:"py-2",children:s.map(y=>{const k=y.icon;return r.jsx("div",{onClick:()=>n(y),className:"px-4 py-2 hover:bg-accent/50 cursor-pointer group transition-colors border-l-2 border-transparent hover:border-primary",children:r.jsxs("div",{className:"flex items-start space-x-3",children:[k&&r.jsx("div",{className:"mt-0.5 p-1 rounded bg-muted group-hover:bg-background transition-colors",children:r.jsx(k,{size:14,className:"text-muted-foreground group-hover:text-primary"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-medium truncate",children:y.title}),y.category&&r.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-bold px-1.5 py-0.5 bg-muted rounded",children:y.category})]}),y.description&&r.jsx("p",{className:"text-[11px] text-muted-foreground truncate mt-0.5",children:y.description})]})]})},y.id)})})})]})},ft=(e,t=0)=>e.reduce((s,n)=>(s.push({...n,level:t}),n.isOpen&&n.children&&s.push(...ft(n.children,t+1)),s),[]),hr=e=>{if(!e)return["background"];const t=[e.isBranch?"branch":"leaf"];return e.kind&&t.push(e.kind),t},pr=({data:e,onToggle:t,onActivate:s,onMoveNode:n,actions:o=[],indent:a=12,virtualized:l=!0,"aria-label":d="Tree",className:c})=>{const[i,g]=b.useState(null),[f,u]=b.useState(null),N=b.useMemo(()=>ft(e),[e]);b.useEffect(()=>{u(null)},[e]);const v=o.filter(k=>!k.showFor||i&&k.showFor.some(E=>i.scopes.includes(E))).map(k=>({label:k.label,icon:k.icon,divider:k.divider,onClick:()=>i&&k.onSelect(i.context)})),h=(k,E)=>{o.length!==0&&(k.preventDefault(),k.stopPropagation(),g({x:k.clientX,y:k.clientY,scopes:hr(E),context:{nodeId:(E==null?void 0:E.id)??null,node:E}}))},y=k=>{const E=N[k],w=!!E.isBranch;return r.jsxs("div",{role:"treeitem","aria-expanded":w?!!E.isOpen:void 0,"aria-level":E.level+1,tabIndex:0,draggable:!0,onDragStart:m=>{m.dataTransfer.setData("text/plain",E.id),m.dataTransfer.effectAllowed="move"},onDragOver:m=>{w&&(m.preventDefault(),u(E.id))},onDragLeave:()=>u(null),onDrop:m=>{m.preventDefault(),u(null);const D=m.dataTransfer.getData("text/plain");D&&D!==E.id&&w&&(n==null||n(D,E.id))},onClick:()=>w&&(t==null?void 0:t(E)),onDoubleClick:()=>s==null?void 0:s(E),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),w?t==null||t(E):s==null||s(E))},onContextMenu:m=>h(m,E),style:{paddingLeft:`${E.level*a+8}px`},className:L("flex items-center py-1 px-2 cursor-pointer hover:bg-accent hover:text-accent-foreground select-none text-xs","transition-colors duration-150 relative focus:outline-none focus:ring-1 focus:ring-ring",f===E.id&&"bg-primary/20 ring-1 ring-primary/50 rounded-sm",E.className),children:[r.jsx("div",{className:"w-4 h-4 mr-1 flex items-center justify-center shrink-0",children:w&&(E.isOpen?r.jsx(O.ChevronDown,{size:14}):r.jsx(O.ChevronRight,{size:14}))}),E.icon&&r.jsx("div",{className:"mr-2 flex items-center shrink-0",children:E.icon}),r.jsx("span",{className:"truncate",children:E.label})]},E.id)};return r.jsxs("div",{role:"tree","aria-label":d,className:L("h-full w-full bg-muted/30",c),onContextMenu:k=>h(k,null),children:[l?r.jsx(Ie.Virtuoso,{style:{height:"100%"},totalCount:N.length,itemContent:y}):r.jsx("div",{className:"h-full overflow-auto",children:N.map((k,E)=>y(E))}),i&&v.length>0&&r.jsx(ut,{x:i.x,y:i.y,items:v,onClose:()=>g(null)})]})},ie={width:180,height:72},ke={x:0,y:0,scale:1},G=e=>{var t,s;return{x:e.position.x,y:e.position.y,width:((t=e.size)==null?void 0:t.width)??ie.width,height:((s=e.size)==null?void 0:s.height)??ie.height}},Y=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),pe=(e,t)=>({x:(e.x-t.x)/t.scale,y:(e.y-t.y)/t.scale}),gr=(e,t)=>({x:e.x*t.scale+t.x,y:e.y*t.scale+t.y}),Ee=(e,t,s)=>{const n=pe(t,e);return{scale:s,x:t.x-n.x*s,y:t.y-n.y*s}},ge=(e,t=.1,s=4)=>Math.min(s,Math.max(t,e)),Se=(e,t)=>{const s=Y(e);switch(t){case"top":return{x:s.x,y:e.y};case"bottom":return{x:s.x,y:e.y+e.height};case"left":return{x:e.x,y:s.y};case"right":return{x:e.x+e.width,y:s.y}}},ht=(e,t)=>{const s=Y(e),n=Y(t),o=n.x-s.x,a=n.y-s.y;return Math.abs(o)>=Math.abs(a)?o>=0?{source:"right",target:"left"}:{source:"left",target:"right"}:a>=0?{source:"bottom",target:"top"}:{source:"top",target:"bottom"}},Te=e=>{if(e.length===0)return null;const t=e.map(G),s=Math.min(...t.map(l=>l.x)),n=Math.min(...t.map(l=>l.y)),o=Math.max(...t.map(l=>l.x+l.width)),a=Math.max(...t.map(l=>l.y+l.height));return{x:s,y:n,width:o-s,height:a-n}},pt=(e,t)=>({x:(0-e.x)/e.scale,y:(0-e.y)/e.scale,width:t.width/e.scale,height:t.height/e.scale}),Me=(e,t,s)=>({scale:s,x:t.width/2-e.x*s,y:t.height/2-e.y*s}),gt=(e,t)=>{const s=Math.min(e.x,t.x),n=Math.min(e.y,t.y);return{x:s,y:n,width:Math.max(e.x+e.width,t.x+t.width)-s,height:Math.max(e.y+e.height,t.y+t.height)-n}},mt=(e,t,s=48)=>{const n=Te(e);if(!n||t.width===0||t.height===0)return ke;const o=ge(Math.min((t.width-s*2)/Math.max(n.width,1),(t.height-s*2)/Math.max(n.height,1))),a=Y(n);return{scale:o,x:t.width/2-a.x*o,y:t.height/2-a.y*o}},bt={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}},me=(e,t,s)=>{const n=e.find(d=>d.id===t);if(!n)return null;const o=Y(G(n)),a=bt[s];let l=null;for(const d of e){if(d.id===t)continue;const c=Y(G(d)),i=c.x-o.x,g=c.y-o.y,f=i*a.x+g*a.y;if(f<=0)continue;const u=Math.abs(i*a.y-g*a.x);if(u>f*2)continue;const N=f+u*2;(!l||N<l.score)&&(l={node:d,score:N})}return(l==null?void 0:l.node)??null},xt=(e,t,s,n=64)=>{const o=e.find(i=>i.id===t);if(!o)return{x:0,y:0};const a=G(o),l=bt[s],d={x:l.x*(a.width+n),y:l.y*(a.height+n)};let c={x:a.x+d.x,y:a.y+d.y};for(let i=0;i<24;i+=1){const g={...c,width:a.width,height:a.height};if(!e.some(u=>mr(G(u),g)))break;c=l.x!==0?{x:c.x,y:c.y+a.height+n}:{x:c.x+a.width+n,y:c.y}}return c},mr=(e,t)=>e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y,br=(e,t)=>e.filter(s=>s.source===t||s.target===t),xr=(e,t,s)=>e.some(n=>n.source===t&&n.target===s||n.source===s&&n.target===t),yr=(e,t,s)=>({nodes:e.filter(n=>n.id!==s),edges:t.filter(n=>n.source!==s&&n.target!==s)}),vr=(e,t)=>{let s=t.length+1;const n=new Set(t.map(o=>o.id));for(;n.has(`${e}-${s}`);)s+=1;return`${e}-${s}`},yt=b.forwardRef(({children:e,overlay:t,viewport:s,defaultViewport:n=ke,onViewportChange:o,onSizeChange:a,onCanvasClick:l,onCanvasDoubleClick:d,onCanvasContextMenu:c,onDrop:i,grid:g=!0,gridSize:f=24,minScale:u=.1,maxScale:N=4,pannable:v=!0,zoomable:h=!0,"aria-label":y="Graph canvas",className:k},E)=>{const w=b.useRef(null),[m,D]=b.useState(n),[A,P]=b.useState(!1),[M,C]=b.useState(!1),x=s??m,T=b.useRef(x);T.current=x;const I=b.useCallback(S=>{s||D(S),o==null||o(S)},[s,o]),$=b.useCallback(S=>{var F;const _=(F=w.current)==null?void 0:F.getBoundingClientRect();return _?{x:S.x-_.left,y:S.y-_.top}:S},[]);b.useEffect(()=>{const S=w.current;if(!S||!a)return;const _=()=>{const B=S.getBoundingClientRect();a({width:B.width,height:B.height})};_();const F=new ResizeObserver(_);return F.observe(S),()=>F.disconnect()},[a]),b.useEffect(()=>{const S=w.current;if(!S||!h)return;const _=F=>{F.preventDefault();const B=T.current,H=$({x:F.clientX,y:F.clientY}),xe=F.ctrlKey?.01:.002,ye=ge(B.scale*Math.exp(-F.deltaY*xe),u,N);I(Ee(B,H,ye))};return S.addEventListener("wheel",_,{passive:!1}),()=>S.removeEventListener("wheel",_)},[h,u,N,I,$]),b.useEffect(()=>{if(!v)return;const S=F=>{var H;if(F.code!=="Space")return;const B=F.target;B!=null&&B.closest('input, textarea, [contenteditable="true"]')||(H=w.current)!=null&&H.contains(document.activeElement)&&(F.preventDefault(),C(!0))},_=F=>{F.code==="Space"&&C(!1)};return window.addEventListener("keydown",S),window.addEventListener("keyup",_),()=>{window.removeEventListener("keydown",S),window.removeEventListener("keyup",_)}},[v]);const K=S=>{if(!v)return;const _=S.target===S.currentTarget,F=S.button===1;if(!_&&!F&&!M||S.button!==0&&!F)return;S.preventDefault(),P(!0);const B={x:S.clientX,y:S.clientY},H={...T.current},xe=zt=>{I({...H,x:H.x+(zt.clientX-B.x),y:H.y+(zt.clientY-B.y)})},ye=()=>{P(!1),window.removeEventListener("pointermove",xe),window.removeEventListener("pointerup",ye)};window.addEventListener("pointermove",xe),window.addEventListener("pointerup",ye)};b.useImperativeHandle(E,()=>({getViewport:()=>T.current,setViewport:I,fitTo:(S,_)=>{var B;const F=(B=w.current)==null?void 0:B.getBoundingClientRect();F&&I(mt(S,{width:F.width,height:F.height},_))},zoomBy:S=>{var H;const _=(H=w.current)==null?void 0:H.getBoundingClientRect();if(!_)return;const F={x:_.width/2,y:_.height/2},B=ge(T.current.scale*S,u,N);I(Ee(T.current,F,B))},clientToGraph:S=>pe($(S),T.current),getSize:()=>{var _;const S=(_=w.current)==null?void 0:_.getBoundingClientRect();return{width:(S==null?void 0:S.width)??0,height:(S==null?void 0:S.height)??0}},focus:()=>{var S;return(S=w.current)==null?void 0:S.focus()}}),[I,u,N,$]);const z=S=>pe($({x:S.clientX,y:S.clientY}),x),j=S=>S.target===S.currentTarget;return r.jsxs("div",{ref:w,role:"application","aria-label":y,tabIndex:0,onPointerDown:K,onClick:S=>j(S)&&(l==null?void 0:l(z(S),S)),onDoubleClick:S=>j(S)&&(d==null?void 0:d(z(S),S)),onContextMenu:S=>{!c||!j(S)||(S.preventDefault(),c(z(S),S))},onDragOver:S=>{i&&(S.preventDefault(),S.dataTransfer.dropEffect="copy")},onDrop:S=>{i&&(S.preventDefault(),i(z(S),S))},style:g?{backgroundImage:"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)",backgroundSize:`${f*x.scale}px ${f*x.scale}px`,backgroundPosition:`${x.x}px ${x.y}px`}:void 0,className:L("relative w-full h-full overflow-hidden bg-background outline-none","focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset",M||A?"cursor-grabbing":"cursor-grab",k),children:[r.jsx("div",{style:{transform:`translate(${x.x}px, ${x.y}px) scale(${x.scale})`,transformOrigin:"0 0",willChange:"transform"},className:"absolute inset-0 pointer-events-none [&>*]:pointer-events-auto",children:e}),t&&r.jsx("div",{className:"absolute inset-0 pointer-events-none [&>*]:pointer-events-auto",children:t})]})});yt.displayName="GraphCanvas";const wr=["top","right","bottom","left"],Nr={top:"left-1/2 -translate-x-1/2 -top-1.5",bottom:"left-1/2 -translate-x-1/2 -bottom-1.5",left:"top-1/2 -translate-y-1/2 -left-1.5",right:"top-1/2 -translate-y-1/2 -right-1.5"},kr=({node:e,children:t,onMove:s,onMoveEnd:n,onSelect:o,onActivate:a,onContextMenu:l,onConnectStart:d,onConnectEnd:c,selected:i=!1,focused:g=!1,ports:f=!0,draggable:u=!0,className:N})=>{var E,w;const v=b.useRef(!1),h=((E=e.size)==null?void 0:E.width)??ie.width,y=((w=e.size)==null?void 0:w.height)??ie.height,k=m=>{if(!u||!s||m.button!==0||m.nativeEvent.shiftKey)return;m.stopPropagation(),v.current=!1;const D={x:m.clientX,y:m.clientY},A={...e.position},P=Er(m.currentTarget);let M=A;const C=T=>{const I=(T.clientX-D.x)/P,$=(T.clientY-D.y)/P;(Math.abs(I)>1||Math.abs($)>1)&&(v.current=!0),M={x:A.x+I,y:A.y+$},s(e.id,M)},x=()=>{v.current&&(n==null||n(e.id,M)),window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",x)};window.addEventListener("pointermove",C),window.addEventListener("pointerup",x)};return r.jsxs("div",{"data-graph-node":e.id,role:"button",tabIndex:-1,"aria-pressed":i,style:{position:"absolute",left:e.position.x,top:e.position.y,width:h,height:y},onPointerDown:k,onClick:m=>{m.stopPropagation(),v.current||o==null||o(e.id,m)},onDoubleClick:m=>{m.stopPropagation(),a==null||a(e.id)},onContextMenu:m=>{l&&(m.preventDefault(),m.stopPropagation(),l(e.id,{x:m.clientX,y:m.clientY},m))},onPointerUp:()=>c==null?void 0:c(e.id),className:L("group rounded-lg border bg-card text-card-foreground shadow-sm select-none","flex flex-col overflow-hidden transition-shadow",u&&s&&"cursor-grab active:cursor-grabbing",i?"border-primary shadow-md":"border-border",g&&"ring-2 ring-ring ring-offset-1 ring-offset-background",N),children:[t,f&&d&&wr.map(m=>r.jsx("button",{type:"button",tabIndex:-1,"aria-label":`Connect from ${m}`,onPointerDown:D=>{D.stopPropagation(),d(e.id,m)},className:L("absolute w-3 h-3 rounded-full border-2 border-background bg-primary","opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity",g&&"opacity-100",Nr[m])},m))]})},Er=e=>{let t=e.parentElement;for(;t;){const s=window.getComputedStyle(t).transform;if(s&&s!=="none"){const n=/matrix\(([^,]+),/.exec(s),o=n?parseFloat(n[1]):NaN;if(Number.isFinite(o)&&o!==0)return o}t=t.parentElement}return 1},vt=(e,t,s,n)=>{if(n==="straight")return`M ${e.x} ${e.y} L ${t.x} ${t.y}`;const o=s==="left"||s==="right";if(n==="smoothstep"){const i=o?(e.x+t.x)/2:(e.y+t.y)/2;return o?`M ${e.x} ${e.y} L ${i} ${e.y} L ${i} ${t.y} L ${t.x} ${t.y}`:`M ${e.x} ${e.y} L ${e.x} ${i} L ${t.x} ${i} L ${t.x} ${t.y}`}const a=Math.hypot(t.x-e.x,t.y-e.y),l=Math.min(Math.max(a/2,24),160),d=o?{x:e.x+(s==="right"?l:-l),y:e.y}:{x:e.x,y:e.y+(s==="bottom"?l:-l)},c=o?{x:t.x-(s==="right"?l:-l),y:t.y}:{x:t.x,y:t.y-(s==="bottom"?l:-l)};return`M ${e.x} ${e.y} C ${d.x} ${d.y}, ${c.x} ${c.y}, ${t.x} ${t.y}`},Sr=({edge:e,source:t,target:s,routing:n="bezier",selected:o=!1,arrow:a=!0,onSelect:l,onContextMenu:d,className:c})=>{const i=G(t),g=G(s),f=ht(i,g),u=Se(i,f.source),N=Se(g,f.target),v=vt(u,N,f.source,n),h={x:(u.x+N.x)/2,y:(u.y+N.y)/2},y=!!(l||d);return r.jsxs("g",{"data-graph-edge":e.id,className:L(y&&"cursor-pointer"),onClick:k=>{l&&(k.stopPropagation(),l(e.id,k))},onContextMenu:k=>{d&&(k.preventDefault(),k.stopPropagation(),d(e.id,{x:k.clientX,y:k.clientY},k))},children:[y&&r.jsx("path",{d:v,fill:"none",stroke:"transparent",strokeWidth:16}),r.jsx("path",{d:v,fill:"none",strokeWidth:o?2.5:1.5,markerEnd:a?"url(#nexus-graph-arrow)":void 0,className:L("transition-[stroke]",o?"stroke-primary":"stroke-border",c)}),e.label&&r.jsx("text",{x:h.x,y:h.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-muted-foreground text-[10px] font-medium select-none",style:{paintOrder:"stroke",stroke:"hsl(var(--background))",strokeWidth:4},children:e.label})]})},Tr=({children:e,className:t})=>r.jsxs("svg",{style:{position:"absolute",left:-5e4,top:-5e4,overflow:"visible"},width:1e5,height:1e5,viewBox:"-50000 -50000 100000 100000",className:L("pointer-events-none [&_g]:pointer-events-auto",t),children:[r.jsx("defs",{children:r.jsx("marker",{id:"nexus-graph-arrow",viewBox:"0 0 10 10",refX:9,refY:5,markerWidth:6,markerHeight:6,orient:"auto-start-reverse",children:r.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-border"})})}),e]}),Mr={moveFocus:["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],createConnected:"Tab",edit:"Enter",cancel:"Escape",delete:["Delete","Backspace"],connect:"c",nudgeModifier:"shiftKey"},Dr={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},Cr=({nodes:e,edges:t,focusedId:s,defaultFocusedId:n=null,onFocusChange:o,targetRef:a,nudgeDistance:l=16,disabled:d=!1,onCreateNode:c,onConnect:i,onDeleteNode:g,onMoveNode:f,onEditNode:u})=>{const[N,v]=b.useState(n),[h,y]=b.useState(null),[k,E]=b.useState(null),w=s!==void 0?s:N,m=b.useCallback(M=>{s===void 0&&v(M),o==null||o(M)},[s,o]),D=b.useRef({nodes:e,edges:t,focusedId:w,editingId:h,connectingFrom:k});D.current={nodes:e,edges:t,focusedId:w,editingId:h,connectingFrom:k};const A=b.useCallback(M=>{const{nodes:C,focusedId:x}=D.current;if(C.length===0)return;if(!x){m(C[0].id);return}const T=me(C,x,M);T&&m(T.id)},[m]),P=b.useCallback((M="right")=>{const{nodes:C,focusedId:x}=D.current;if(!c)return;const T=x?xt(C,x,M):{x:0,y:0},I=c(T,{from:x??void 0,direction:M});I&&(x&&(i==null||i(x,I)),m(I),y(I))},[c,i,m]);return b.useEffect(()=>{if(d)return;const M=a.current;if(!M)return;const C=x=>{const{focusedId:T,editingId:I,connectingFrom:$}=D.current;if(I){x.key==="Escape"&&(x.preventDefault(),y(null));return}const K=x.target;if(K!=null&&K.closest('input, textarea, select, [contenteditable="true"]'))return;const z=Dr[x.key];if(z){x.preventDefault();const j=D.current.nodes.find(S=>S.id===T);if(x.shiftKey&&j&&f){const S={up:{x:0,y:-l},down:{x:0,y:l},left:{x:-l,y:0},right:{x:l,y:0}}[z];f(j.id,{x:j.position.x+S.x,y:j.position.y+S.y});return}A(z);return}switch(x.key){case"Tab":{if(!c)return;x.preventDefault(),P(x.shiftKey?"left":"right");return}case"Enter":{if(!T)return;if(x.preventDefault(),$&&$!==T){i==null||i($,T),E(null);return}u==null||u(T),y(T);return}case"Escape":{x.preventDefault(),$?E(null):m(null);return}case"Delete":case"Backspace":{if(!T||!g)return;x.preventDefault();const j=D.current.nodes.filter(_=>_.id!==T),S=me(D.current.nodes,T,"left")??me(D.current.nodes,T,"right")??j[0]??null;g(T),m((S==null?void 0:S.id)??null);return}case"c":case"C":{if(!T||!i||x.metaKey||x.ctrlKey)return;x.preventDefault(),E($===T?null:T);return}}};return M.addEventListener("keydown",C),()=>M.removeEventListener("keydown",C)},[d,a,A,P,l,i,c,g,u,f,m]),b.useEffect(()=>{w&&!e.some(M=>M.id===w)&&m(null),h&&!e.some(M=>M.id===h)&&y(null),k&&!e.some(M=>M.id===k)&&E(null)},[e,w,h,k,m]),b.useMemo(()=>({focusedId:w,setFocusedId:m,editingId:h,setEditingId:y,connectingFrom:k,setConnectingFrom:E,moveFocus:A,createConnected:P}),[w,m,h,k,A,P])},Lr=({nodes:e,viewport:t,canvasSize:s,onViewportChange:n,width:o=180,height:a=120,nodeColor:l,highlightIds:d,padding:c=8,panDistance:i=80,"aria-label":g="Graph minimap",className:f})=>{const u=b.useRef(null),N=b.useMemo(()=>new Set(d??[]),[d]),v=pt(t,s),h=b.useMemo(()=>{const C=Te(e);return C?gt(C,v):v},[e,v.x,v.y,v.width,v.height]),y=Math.min((o-c*2)/Math.max(h.width,1),(a-c*2)/Math.max(h.height,1)),k={x:(o-h.width*y)/2-h.x*y,y:(a-h.height*y)/2-h.y*y},E=C=>({x:C.x*y+k.x,y:C.y*y+k.y}),w=C=>({x:(C.x-k.x)/y,y:(C.y-k.y)/y}),m=b.useCallback(C=>{var I;if(!n)return;const x=(I=u.current)==null?void 0:I.getBoundingClientRect();if(!x)return;const T=w({x:C.x-x.left,y:C.y-x.top});n(Me(T,s,t.scale))},[n,s,t.scale,y,k.x,k.y]),D=C=>{var I;if(!n||C.button!==0)return;C.preventDefault(),(I=u.current)==null||I.focus(),m({x:C.clientX,y:C.clientY});const x=$=>m({x:$.clientX,y:$.clientY}),T=()=>{window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",T)};window.addEventListener("pointermove",x),window.addEventListener("pointerup",T)},A=C=>{if(!n)return;const x={ArrowUp:{x:0,y:-i},ArrowDown:{x:0,y:i},ArrowLeft:{x:-i,y:0},ArrowRight:{x:i,y:0}}[C.key];if(!x)return;C.preventDefault();const T=Y(v);n(Me({x:T.x+x.x,y:T.y+x.y},s,t.scale))},P={x:E(v).x,y:E(v).y,width:v.width*y,height:v.height*y},M=!!n;return r.jsx("div",{ref:u,role:M?"slider":"img","aria-label":g,"aria-valuetext":e.length===0?"Empty graph":`${e.length} nodes, viewing around ${Math.round(Y(v).x)}, ${Math.round(Y(v).y)}`,tabIndex:M?0:void 0,onPointerDown:D,onKeyDown:A,style:{width:o,height:a},className:L("rounded-lg border border-border bg-card/90 backdrop-blur-sm shadow-sm overflow-hidden","focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",M&&"cursor-pointer",f),children:r.jsxs("svg",{width:o,height:a,className:"block",children:[e.map(C=>{const x=G(C),T=E(x),I=N.has(C.id);return r.jsx("rect",{x:T.x,y:T.y,width:Math.max(x.width*y,2),height:Math.max(x.height*y,2),rx:1,fill:I||l==null?void 0:l(C),className:L(!l&&!I&&"fill-muted-foreground/50",I&&"fill-primary")},C.id)}),s.width>0&&r.jsx("rect",{x:P.x,y:P.y,width:Math.max(P.width,4),height:Math.max(P.height,4),rx:2,className:"fill-primary/10 stroke-primary",strokeWidth:1.5})]})})},Ir=(e,t)=>{const s=new Set(e.map(i=>i.id)),n=new Map,o=new Map;e.forEach(i=>{n.set(i.id,[]),o.set(i.id,0)}),t.forEach(i=>{!s.has(i.source)||!s.has(i.target)||(n.get(i.source).push(i.target),o.set(i.target,(o.get(i.target)??0)+1))});const a=new Map,l=[],d=i=>{a.set(i,0),l.push(i)};e.forEach(i=>{(o.get(i.id)??0)===0&&d(i.id)}),l.length===0&&e.length>0&&d(e[0].id);let c=e.length*e.length+e.length;for(;l.length>0&&c>0;){c-=1;const i=l.shift(),g=a.get(i)??0;for(const f of n.get(i)??[]){const u=a.get(f);(u===void 0||u<g+1)&&(a.set(f,g+1),l.push(f))}}return e.forEach(i=>{a.has(i.id)||d(i.id)}),a},De=({direction:e="down",nodeSpacing:t=48,layerSpacing:s=96,origin:n={x:0,y:0},align:o="center"}={})=>(a,l)=>{if(a.length===0)return a;const d=Ir(a,l),c=e==="down"||e==="up",i=new Map;a.forEach(w=>{const m=d.get(w.id)??0,D=i.get(m)??[];D.push(w),i.set(m,D)});const g=[...i.keys()].sort((w,m)=>w-m),f=new Map;g.forEach(w=>{const m=i.get(w),D=Math.max(...m.map(A=>{const P=G(A);return c?P.height:P.width}));f.set(w,D)});const u=new Map;let N=0;g.forEach(w=>{u.set(w,N),N+=(f.get(w)??0)+s});const v=w=>{const m=i.get(w);return m.map(A=>{const P=G(A);return c?P.width:P.height}).reduce((A,P)=>A+P,0)+t*(m.length-1)},h=Math.max(...g.map(v)),y=e==="up"||e==="left",k=N-s,E=new Map;return g.forEach(w=>{const m=i.get(w),D=v(w);let A=o==="center"?(h-D)/2:0;const P=u.get(w)??0,M=y?k-P-(f.get(w)??0):P;m.forEach(C=>{const x=G(C),T=c?x.width:x.height,I=c?x.height:x.width,$=M+((f.get(w)??0)-I)/2;E.set(C.id,c?{x:n.x+A,y:n.y+$}:{x:n.x+$,y:n.y+A}),A+=T+t})}),a.map(w=>{const m=E.get(w.id);return m?{...w,position:m}:w})},wt=({columns:e,spacingX:t=48,spacingY:s=48,origin:n={x:0,y:0}}={})=>o=>{if(o.length===0)return o;const a=Math.max(1,e??Math.ceil(Math.sqrt(o.length))),l=Math.ceil(o.length/a),d=Array.from({length:a},(f,u)=>Math.max(...o.filter((N,v)=>v%a===u).map(N=>G(N).width))),c=Array.from({length:l},(f,u)=>Math.max(...o.filter((N,v)=>Math.floor(v/a)===u).map(N=>G(N).height))),i=[];d.reduce((f,u,N)=>(i[N]=f,f+u+t),0);const g=[];return c.reduce((f,u,N)=>(g[N]=f,f+u+s),0),o.map((f,u)=>({...f,position:{x:n.x+i[u%a],y:n.y+g[Math.floor(u/a)]}}))},Nt={vertical:De({direction:"down"}),horizontal:De({direction:"right"}),grid:wt()},ce="freeform",Ar=({nodes:e,edges:t,layouts:s=Nt,mode:n,defaultMode:o=ce,onModeChange:a,onNodeMove:l,escapeOnDrag:d=!0})=>{const[c,i]=b.useState(o),g=n??c,f=b.useCallback(E=>{n===void 0&&i(E),a==null||a(E)},[n,a]),u=g===ce?void 0:s[g],N=!!u,v=b.useMemo(()=>u?u(e,t):e,[u,e,t]),h=b.useCallback((E,w)=>{N&&d&&f(ce),l==null||l(E,w)},[N,d,f,l]),y=b.useCallback(()=>v,[v]),k=b.useMemo(()=>Object.keys(s).filter(E=>E!==ce),[s]);return b.useMemo(()=>({nodes:v,mode:g,setMode:f,available:k,isAuto:N,onMove:h,bake:y}),[v,g,f,k,N,h,y])},Ce="application/x-nexus-graph-node",Pr=({items:e,onSelect:t,onDragStart:s,orientation:n="auto",onOrientationChange:o,iconOnly:a=!1,className:l,"aria-label":d="Node palette"})=>{const c=b.useRef(null),[i,g]=b.useState("horizontal"),f=n==="auto"?i:n,u=b.useRef(o);u.current=o;const N=b.useCallback(()=>{const h=c.current;if(!h)return;const y=[...h.querySelectorAll("[data-palette-item]")];if(y.length===0)return;const k=window.getComputedStyle(h),E=parseFloat(k.gap)||0,w=(parseFloat(k.paddingLeft)||0)+(parseFloat(k.paddingRight)||0),m=y.reduce((C,x)=>C+x.offsetWidth,0)+E*(y.length-1)+w,D=y.reduce((C,x)=>C+x.offsetHeight,0)+E*(y.length-1)+w,A=Or(h);if(!A)return;const P=4,M=m<=A.width+P?"horizontal":D<=A.height+P?"vertical":"horizontal";g(C=>{var x;return C===M?C:((x=u.current)==null||x.call(u,M),M)})},[]);b.useEffect(()=>{if(n!=="auto")return;const h=c.current;if(!h)return;N();const y=new ResizeObserver(N);y.observe(h);const k=kt(h);return k&&k!==h&&y.observe(k),()=>y.disconnect()},[n,N,e.length]);const v=f==="vertical";return r.jsx("div",{ref:c,role:"toolbar","aria-label":d,"aria-orientation":f,"data-orientation":f,className:L("flex gap-1.5 p-1.5 rounded-lg border border-border bg-card/90 backdrop-blur-sm shadow-sm",v?"flex-col items-stretch":"flex-wrap items-center",l),children:e.map(h=>r.jsxs("button",{type:"button","data-palette-item":!0,draggable:!0,title:h.description??(a?h.label:void 0),"aria-label":a?h.label:void 0,onDragStart:y=>{y.dataTransfer.setData(Ce,h.kind),y.dataTransfer.setData("text/plain",h.label),y.dataTransfer.effectAllowed="copy",s==null||s(h)},onClick:()=>t==null?void 0:t(h),className:L("flex items-center gap-1.5 rounded-md text-xs font-medium","border border-border bg-background text-foreground","hover:bg-accent hover:text-accent-foreground transition-colors","cursor-grab active:cursor-grabbing","focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",a?"p-2 justify-center":"px-2.5 py-1.5",v&&!a&&"justify-start"),children:[h.icon,!a&&h.label]},h.kind))})},kt=e=>{let t=e.parentElement;for(let s=0;t&&s<6;s+=1){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();if(n.width>o.width+8)return t;t=t.parentElement}return null},Or=e=>{const t=kt(e);if(!t)return null;const s=window.getComputedStyle(t),n=t.getBoundingClientRect();return{width:n.width-(parseFloat(s.paddingLeft)||0)-(parseFloat(s.paddingRight)||0),height:n.height-(parseFloat(s.paddingTop)||0)-(parseFloat(s.paddingBottom)||0)}},$r=e=>e.dataTransfer.getData(Ce)||null,X=({label:e,htmlFor:t,description:s,error:n,mixed:o,children:a,inline:l=!1,className:d})=>r.jsxs("div",{className:L("flex flex-col gap-1.5",d),children:[!l&&r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsx("label",{htmlFor:t,className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:e}),o&&r.jsx("span",{className:"text-[9px] uppercase tracking-wider text-muted-foreground/70",children:"Mixed"})]}),l?r.jsxs("div",{className:"flex items-center gap-2",children:[a,r.jsx("label",{htmlFor:t,className:"text-xs text-foreground select-none",children:e}),o&&r.jsx("span",{className:"text-[9px] uppercase tracking-wider text-muted-foreground/70",children:"Mixed"})]}):a,s&&!n&&r.jsx("p",{className:"text-[11px] text-muted-foreground/80 leading-snug",children:s}),n&&r.jsx("p",{className:"text-[11px] text-destructive leading-snug",children:n})]}),R="w-full rounded-md border bg-background px-2.5 py-1.5 text-xs text-foreground placeholder:text-muted-foreground/60 transition-colors focus:outline-none focus:ring-2 focus:ring-primary/40 focus:border-primary/50 disabled:opacity-50 disabled:cursor-not-allowed",ee=e=>e?"border-destructive":"border-border",J=(e,t="")=>`property-${e.toLowerCase().replace(/[^a-z0-9]+/g,"-")}${t}`,se="Mixed values",Et=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,placeholder:d,inputType:c="text",className:i})=>{const g=J(e);return r.jsx(X,{label:e,htmlFor:g,description:n,error:l,mixed:o,className:i,children:r.jsx("input",{id:g,type:c,value:o?"":t??"",placeholder:o?se:d,disabled:a,onChange:f=>s==null?void 0:s(f.target.value),className:L(R,ee(l))})})},St=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,placeholder:d,rows:c=4,className:i})=>{const g=J(e);return r.jsx(X,{label:e,htmlFor:g,description:n,error:l,mixed:o,className:i,children:r.jsx("textarea",{id:g,rows:c,value:o?"":t??"",placeholder:o?se:d,disabled:a,onChange:f=>s==null?void 0:s(f.target.value),className:L(R,ee(l),"resize-y leading-relaxed")})})},Tt=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,options:d,placeholder:c,className:i})=>{const g=J(e);return r.jsx(X,{label:e,htmlFor:g,description:n,error:l,mixed:o,className:i,children:r.jsxs("select",{id:g,value:o?"":t??"",disabled:a,onChange:f=>s==null?void 0:s(f.target.value),className:L(R,ee(l),"cursor-pointer"),children:[(o||c||t===void 0)&&r.jsx("option",{value:"",disabled:!c,children:o?se:c??"—"}),d.map(f=>r.jsx("option",{value:f.value,disabled:f.disabled,children:f.label},f.value))]})})},Mt=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,className:d})=>{const c=J(e);return r.jsx(X,{label:e,htmlFor:c,description:n,error:l,mixed:o,inline:!0,className:d,children:r.jsx("input",{id:c,type:"checkbox",checked:o?!1:!!t,ref:i=>{i&&(i.indeterminate=!!o)},disabled:a,onChange:i=>s==null?void 0:s(i.target.checked),className:"h-3.5 w-3.5 shrink-0 rounded border-border text-primary focus:ring-2 focus:ring-primary/40 disabled:opacity-50"})})},Dt=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,min:d,max:c,step:i,unit:g,placeholder:f,className:u})=>{const N=J(e);return r.jsx(X,{label:e,htmlFor:N,description:n,error:l,mixed:o,className:u,children:r.jsxs("div",{className:"relative",children:[r.jsx("input",{id:N,type:"number",value:o||t===void 0?"":t,placeholder:o?se:f,min:d,max:c,step:i,disabled:a,onChange:v=>{if(v.target.value==="")return;const h=Number(v.target.value);Number.isFinite(h)&&(s==null||s(h))},className:L(R,ee(l),g&&"pr-8")}),g&&r.jsx("span",{className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground",children:g})]})})},Ct=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,showValue:d=!0,className:c})=>{const i=J(e);return r.jsx(X,{label:e,htmlFor:i,description:n,error:l,mixed:o,className:c,children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{id:i,type:"color",value:o?"#888888":t??"#000000",disabled:a,onChange:g=>s==null?void 0:s(g.target.value),className:"h-7 w-10 shrink-0 cursor-pointer rounded border border-border bg-background disabled:opacity-50"}),d&&r.jsx("input",{type:"text","aria-label":`${e} value`,value:o?"":t??"",placeholder:o?se:"#000000",disabled:a,onChange:g=>s==null?void 0:s(g.target.value),className:L(R,ee(l),"font-mono")})]})})},Lt=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,withTime:d=!1,min:c,max:i,className:g})=>{const f=J(e);return r.jsx(X,{label:e,htmlFor:f,description:n,error:l,mixed:o,className:g,children:r.jsx("input",{id:f,type:d?"datetime-local":"date",value:o?"":t??"",min:c,max:i,disabled:a,onChange:u=>s==null?void 0:s(u.target.value),className:L(R,ee(l))})})},It=({label:e,value:t,onChange:s,description:n,mixed:o,disabled:a,error:l,placeholder:d="Add and press Enter",suggestions:c,className:i})=>{const[g,f]=b.useState(""),u=J(e),N=o?[]:t??[],v=()=>{const h=g.trim();if(!h||N.includes(h)){f("");return}s==null||s([...N,h]),f("")};return r.jsxs(X,{label:e,htmlFor:u,description:n,error:l,mixed:o,className:i,children:[N.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:N.map(h=>r.jsxs("span",{className:"flex items-center gap-1 rounded-md border border-border bg-secondary px-1.5 py-0.5 text-[11px] text-secondary-foreground",children:[h,!a&&r.jsx("button",{type:"button","aria-label":`Remove ${h}`,onClick:()=>s==null?void 0:s(N.filter(y=>y!==h)),className:"text-muted-foreground hover:text-destructive",children:r.jsx(O.X,{size:10})})]},h))}),r.jsxs("div",{className:"flex gap-1.5",children:[r.jsx("input",{id:u,type:"text",list:c?`${u}-suggestions`:void 0,value:g,placeholder:o?se:d,disabled:a,onChange:h=>f(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),v())},className:L(R,ee(l))}),r.jsx("button",{type:"button","aria-label":`Add ${e}`,disabled:a||!g.trim(),onClick:v,className:"shrink-0 rounded-md border border-border px-2 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-40",children:r.jsx(O.Plus,{size:13})})]}),c&&r.jsx("datalist",{id:`${u}-suggestions`,children:c.map(h=>r.jsx("option",{value:h},h))})]})},At=({label:e,value:t,description:s,mixed:n,mono:o=!1,className:a})=>r.jsx(X,{label:e,description:s,mixed:n,className:a,children:r.jsx("p",{className:L("break-words text-xs text-foreground",o&&"font-mono text-[11px]",(n||t===void 0||t==="")&&"text-muted-foreground/60"),children:n?se:t??"—"})}),Pt=(e,t)=>{if(e!=null)return t.split(".").reduce((s,n)=>s==null?void 0:s[n],e)},Le=(e,t,s)=>{const[n,...o]=t.split(".");if(n===void 0)return e;const a=e??{};if(o.length===0)return{...a,[n]:s};const l=a[n],d=l!=null&&typeof l=="object"?l:{};return{...a,[n]:Le(d,o.join("."),s)}},be=(e,t)=>t.get?t.get(e):Pt(e,t.key),Ot=(e,t,s)=>t.set?t.set(e,s):Le(e,t.key,s),$t=(e,t)=>{if(e.length===0)return{value:void 0,mixed:!1};const s=be(e[0],t);return e.every(o=>Object.is(be(o,t),s))?{value:s,mixed:!1}:{value:void 0,mixed:!0}},Ft=(e,t,s)=>e.map(n=>Object.is(be(n,t),s)?n:Ot(n,t,s)),_t={text:({field:e,state:t,onChange:s,error:n})=>r.jsx(Et,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),textarea:({field:e,state:t,onChange:s,error:n})=>r.jsx(St,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),select:({field:e,state:t,onChange:s,error:n})=>{var o;return r.jsx(Tt,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,options:((o=e.props)==null?void 0:o.options)??[],...e.props})},checkbox:({field:e,state:t,onChange:s,error:n})=>r.jsx(Mt,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),number:({field:e,state:t,onChange:s,error:n})=>r.jsx(Dt,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),color:({field:e,state:t,onChange:s,error:n})=>r.jsx(Ct,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),date:({field:e,state:t,onChange:s,error:n})=>r.jsx(Lt,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),tags:({field:e,state:t,onChange:s,error:n})=>r.jsx(It,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,disabled:e.disabled,error:n,onChange:s,...e.props}),static:({field:e,state:t})=>r.jsx(At,{label:e.label,description:e.description,value:t.value,mixed:t.mixed,...e.props})},Fr=r.jsx("div",{className:"grid h-full place-items-center px-6 py-10 text-center",children:r.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing selected. Choose an item to see its properties."})}),_r=({subjects:e,fields:t,onChange:s,fieldTypes:n=_t,emptyState:o=Fr,title:a,groupOrder:l,className:d,"aria-label":c="Properties"})=>{const i=b.useMemo(()=>t.filter(u=>!u.when||u.when(e)),[t,e]),g=b.useMemo(()=>{const u=new Map;i.forEach(h=>{const y=h.group??"";u.set(y,[...u.get(y)??[],h])});const N=[...u.keys()];return(l?[...u.has("")?[""]:[],...l.filter(h=>u.has(h)),...N.filter(h=>h!==""&&!l.includes(h))]:N).map(h=>({group:h,fields:u.get(h)}))},[i,l]);if(e.length===0)return r.jsx("section",{"aria-label":c,className:L("h-full overflow-y-auto",d),children:o});const f=typeof a=="function"?a(e):a;return r.jsxs("section",{"aria-label":c,className:L("h-full overflow-y-auto",d),children:[f!=null&&r.jsx("header",{className:"sticky top-0 z-10 border-b border-border/60 bg-background/95 px-4 py-2.5 backdrop-blur-sm",children:r.jsx("div",{className:"text-xs font-semibold text-foreground",children:f})}),r.jsx("div",{className:"flex flex-col gap-5 p-4",children:g.map(({group:u,fields:N})=>r.jsxs("div",{className:"flex flex-col gap-4",children:[u&&r.jsx("h3",{className:"border-b border-border/40 pb-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70",children:u}),N.map(v=>{var k;const h=$t(e,v),y=n[v.type??"text"];return y?r.jsx(b.Fragment,{children:y({field:v,state:h,subjects:e,error:(k=v.validate)==null?void 0:k.call(v,h.value,e),onChange:E=>s==null?void 0:s(Ft(e,v,E),v,E)})},v.key):r.jsxs("p",{className:"text-[11px] text-destructive",children:["No renderer registered for field type “",v.type,"”."]},v.key)})]},u||"_"))})]})};p.ActivityBar=Ae,p.AppTitle=cr,p.BUILT_IN_FIELD_TYPES=_t,p.BUILT_IN_LAYOUTS=Nt,p.BUNDLED_THEMES=ae,p.BUNDLED_THEME_CLASSES=Ge,p.CONTROL_CLASS=R,p.ChatPane=Oe,p.CheckboxField=Mt,p.ColorField=Ct,p.CommandPalette=at,p.CommandRegistry=ze,p.ConnectedActivityBar=Pe,p.ConnectedChatPane=$e,p.ConnectedCommandPalette=sr,p.ConnectedMenuBar=Be,p.ConnectedModal=ar,p.ConnectedSidebarPane=qe,p.ConnectedStatusBar=Ve,p.ConnectedTerminalPane=Ze,p.ConnectedThemeSwitcher=lr,p.ConnectedUserProfile=ir,p.ContextMenu=ut,p.DEFAULT_COMMAND_IDS=qt,p.DEFAULT_GRAPH_KEYS=Mr,p.DEFAULT_NODE_SIZE=ie,p.DEFAULT_SETTINGS_THEMES=He,p.DEFAULT_THEME_OPTIONS=it,p.DataGrid=dr,p.DateField=Lt,p.FREEFORM=ce,p.FieldShell=X,p.GRAPH_NODE_MIME=Ce,p.GraphCanvas=yt,p.GraphEdge=Sr,p.GraphEdgeLayer=Tr,p.GraphMiniMap=Lr,p.GraphNode=kr,p.IDENTITY_VIEWPORT=ke,p.MenuBar=Fe,p.MenuRegistry=_e,p.Modal=lt,p.NexusWorkspaceShell=rt,p.NodePalette=Pr,p.NumberField=Dt,p.PropertyPanel=_r,p.QuickSearch=ur,p.SearchWidget=fr,p.SelectField=Tt,p.SettingsPanel=We,p.ShellLayout=rt,p.SidebarPane=fe,p.StaticField=At,p.StatusBar=Je,p.TagField=It,p.TerminalPane=Qe,p.TextAreaField=St,p.TextField=Et,p.ThemeSwitcher=ct,p.TreeWidget=pr,p.UserProfile=dt,p.borderClass=ee,p.centerOn=Me,p.clampScale=ge,p.cn=L,p.commandRegistry=V,p.componentRegistry=Re,p.edgePath=vt,p.edgesOf=br,p.fieldId=J,p.findNeighbour=me,p.fitViewport=mt,p.getPath=Pt,p.graphBounds=Te,p.gridLayout=wt,p.initializeShell=Qt,p.isConnected=xr,p.layeredLayout=De,p.menuRegistry=ue,p.nextId=vr,p.nodeRect=G,p.placeRelativeTo=xt,p.pluginRegistry=Rt,p.portPoint=Se,p.readPaletteDrag=$r,p.readValue=be,p.readValues=$t,p.rectCenter=Y,p.removeNode=yr,p.resolvePorts=ht,p.setPath=Le,p.themeClass=je,p.toGraphSpace=pe,p.toScreenSpace=gr,p.unionRect=gt,p.useChatStore=oe,p.useGraphKeyboard=Cr,p.useGraphLayout=Ar,p.useKeyboardShortcuts=er,p.useLayoutStore=tt,p.useModalStore=Ne,p.useRightSidebarStore=de,p.useSidebarStore=W,p.useStatusBarStore=he,p.useTerminalStore=re,p.useThemeStore=te,p.useUserProfileStore=Z,p.viewportRect=pt,p.writeValue=Ot,p.writeValues=Ft,p.zoomAt=Ee,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|