1import{j as e}from"./vendor-radix-BnNg3BH5.js";import{r as i}from"./vendor-react-67mgcWXU.js";import{C as m,d,a as v,b as w}from"./card-DpKBVi42.js";import{b as k,a4 as S,B as j,L as C,S as T,s as A}from"./index-Epr9psQo.js";import{m as g,A as D}from"./vendor-motion-CSzk-Fqg.js";import{S as E}from"./sparkles-BcySMUTB.js";import{M as q}from"./message-square-7cL_4-It.js";import{M as O}from"./index-BMcbOcU5.js";import{T as I}from"./trending-up-CXZcoU_y.js";import{U as L}from"./users-uAR6_Qvs.js";import{D as M}from"./dollar-sign-CC-jyV1q.js";import{F as _}from"./folder-kanban-C52eeuLF.js";import{C as K}from"./clock-BYWbH6MV.js";import{C as U}from"./chart-column-6WlVTHnt.js";import"./vendor-supabase-CTlrDMdV.js";import"./vendor-charts-Dck3qfzI.js";import"./vendor-query-PMAhJHCS.js";const W=[{text:"What is our average project margin this quarter?",icon:I},{text:"Which team members have the highest utilization?",icon:L},{text:"How much revenue is at risk from overdue projects?",icon:M},{text:"Which clients have the most active projects?",icon:_},{text:"What is our billable vs non-billable ratio this month?",icon:K},{text:"Show me projects that are over budget",icon:U}];function ae(){const{currentTenant:n}=k(),[s,o]=i.useState(""),[l,x]=i.useState(!1),[h,p]=i.useState([]),u=i.useRef(null),f=async()=>{if(!(!s.trim()||!n?.id)){x(!0);try{const{data:t,error:a}=await A.functions.invoke("nl-analytics",{body:{question:s.trim(),tenant_id:n.id}});if(a)throw a;const r={question:s.trim(),answer:t?.answer||"I couldn't generate an answer. Please try rephrasing your question.",data:t?.data,timestamp:new Date().toISOString()};p(c=>[r,...c]),o("")}catch(t){p(a=>[{question:s.trim(),answer:`Error: ${t.message||"Failed to process question"}. The analytics engine will be fully available once the backend function is deployed.`,timestamp:new Date().toISOString()},...a])}finally{x(!1)}}},y=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),f())};return e.jsxs(g.div,{initial:{opacity:0}
1,animate:{opacity:1},className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold tracking-tight flex items-center gap-2",children:[e.jsx(E,{className:"h-7 w-7 text-primary"}),"Ask CommandOS"]}),e.jsx("p",{className:"text-muted-foreground",children:"Ask questions about your firm's data in plain English"})]}),e.jsx(m,{children:e.jsx(d,{className:"pt-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{ref:u,value:s,onChange:t=>o(t.target.value),onKeyDown:y,placeholder:"Ask anything about your projects, clients, team, or financials...",className:"min-h-[60px] resize-none",disabled:l}),e.jsx(j,{onClick:f,disabled:l||!s.trim()||!n?.id,size:"icon",className:"shrink-0 h-[60px] w-[60px]",children:l?e.jsx(C,{className:"h-5 w-5 animate-spin"}):e.jsx(T,{className:"h-5 w-5"})})]})})}),h.length===0&&e.jsxs(m,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(w,{className:"text-base",children:"Try asking"})}),e.jsx(d,{children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:W.map(t=>e.jsxs(j,{variant:"outline",className:"justify-start h-auto py-3 px-4 text-left text-sm",onClick:()=>{o(t.text),u.current?.focus()},children:[e.jsx(t.icon,{className:"h-4 w-4 mr-2 shrink-0 text-primary"}),e.jsx("span",{className:"truncate",children:t.text})]},t.text))})})]}),e.jsx(D,{children:h.map((t,a)=>e.jsx(g.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},children:e.jsx(m,{children:e.jsxs(d,{className:"pt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(q,{className:"h-4 w-4 mt-0.5 text-muted-foreground shrink-0"}),e.jsx("p",{className:"text-sm font-medium",children:t.question})]}),e.jsx("div",{className:"pl-6 border-l-2 border-primary/20",children:e.jsx("div",{className:"prose prose-sm max-w-none text-foreground [&_p]:text-foreground [&_li]:text-foreground [&_strong]:text-foreground",children:e.jsx(O,{children:t.answer})})}),t.data&&t.data.length>0&&e.jsx("div",{className:"mt-3 rounded border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b bg-muted/50",children:Object.keys(t.data[0]).map(r=>e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:r},r))})}),e.jsx("tbody",{children:t.data.slice(0,10).map((r,c)=>e.jsx("tr",{className:"border-b last:border-0",children:Object.values(r).map((b,N)=>e.jsx("td",{className:"px-3 py-1.5",children:String(b)},N))},c))})]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.timestamp).toLocaleTimeString()})]})})},t.timestamp+a))})]})}export{ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.