import{d as A,k as q,m as C,r as l,o as a,a as r,b as _,e as N,h as T,w as I,f as n,v as O,x as R,t as c,j as f,F as v,n as h}from"./app-bWy6VYs1.js";import{_ as V,g as B}from"./AppLayout.vue_vue_type_script_setup_true_lang-BwuDxc8O.js";import"./index-C32fBP6Q.js";import"./index-CMWG4mbA.js";import"./useForwardExpose-Cx2E44RD.js";import"./VisuallyHidden-0BfmsMPn.js";import"./RovingFocusGroup-D20OvR_w.js";import"./useArrowNavigation-C6Y-ieo6.js";import"./_plugin-vue_export-helper-DmjF0He4.js";const F={class:"space-y-4 p-4"},J={key:0,class:"rounded border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900"},D={key:1,class:"rounded-lg border bg-white p-4"},E={class:"flex gap-2"},L=["disabled"],M={key:0,class:"mt-3 text-sm text-gray-700"},P={key:1,class:"mt-4 grid gap-3 md:grid-cols-2"},Q={class:"mb-2 text-sm font-semibold text-gray-900"},H={class:"space-y-2 text-xs text-gray-700"},K=["href"],U={class:"mt-0.5 text-gray-600"},X={key:0,class:"text-gray-500"},rt=A({__name:"Assistant",setup(z){const p=q(),y=C(()=>!!p.props.ai?.allowed),o=l(""),d=l(!1),u=l(""),m=l({}),x={jobcards:"Jobcards",quotes:"Quotes",invoices:"Invoices",tasks:"Tasks",customers:"Customers",contacts:"Contacts"},k=(e,t)=>{const s=Number(t.id??0);return s?e==="jobcards"?`/jobcards/${s}`:e==="quotes"?`/quotes/${s}`:e==="invoices"?`/invoices/${s}`:e==="tasks"?`/tasks/${s}/edit`:e==="customers"?`/customers/${s}`:e==="contacts"?`/contacts/${s}`:"#":"#"},g=(e,t)=>e==="jobcards"?String(t.job_number||t.title||`Jobcard #${t.id}`):e==="quotes"?String(t.quote_number||`Quote #${t.id}`):e==="invoices"?String(t.invoice_number||`Invoice #${t.id}`):e==="tasks"?String(t.title||`Task #${t.id}`):e==="customers"||e==="contacts"?String(t.name||`Record #${t.id}`):`Record #${t.id??"?"}`,$=(e,t)=>e==="jobcards"||e==="quotes"||e==="invoices"||e==="tasks"?String(t.status||"No status"):e==="customers"||e==="contacts"?String(t.email||"No email"):"",S=async()=>{if(!o.value.trim()||!y.value)return;d.value=!0;const e=await fetch("/ai/assistant",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json","X-CSRF-TOKEN":B()},body:JSON.stringify({query:o.value.trim()})});if(d.value=!1,!e.ok)return;const t=await e.json();u.value=t.summary||"",m.value=t.results||{}};return(e,t)=>(a(),r(v,null,[_(N(T),{title:"AI Assistant"}),_(V,{breadcrumbs:[{title:"AI Assistant",href:"/ai-assistant"}]},{default:I(()=>[n("div",F,[t[1]||(t[1]=n("h1",{class:"text-2xl font-bold text-gray-900"},"AI Assistant",-1)),t[2]||(t[2]=n("p",{class:"text-sm text-gray-600"},"Read-only assistant over company data (jobcards, quotes, invoices, tasks, customers, contacts).",-1)),y.value?(a(),r("div",D,[n("div",E,[O(n("input",{"onUpdate:modelValue":t[0]||(t[0]=s=>o.value=s),type:"text",class:"flex-1 rounded border px-3 py-2 text-sm",placeholder:"Ask about records, references, statuses, customers..."},null,512),[[R,o.value]]),n("button",{type:"button",class:"rounded bg-indigo-600 px-3 py-2 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-60",disabled:d.value||!o.value.trim(),onClick:S},c(d.value?"Searching…":"Search"),9,L)]),u.value?(a(),r("p",M,c(u.value),1)):f("",!0),Object.keys(m.value).length?(a(),r("div",P,[(a(!0),r(v,null,h(m.value,(s,i)=>(a(),r("div",{key:i,class:"rounded border border-gray-200 p-3"},[n("h2",Q,c(x[i]||i),1),n("ul",H,[(a(!0),r(v,null,h(s,(b,j)=>(a(),r("li",{key:`${i}-${j}`,class:"rounded border border-gray-200 bg-gray-50 px-2 py-2"},[n("a",{href:k(i,b),class:"font-semibold text-indigo-700 hover:underline"},c(g(i,b)),9,K),n("p",U,c($(i,b)),1)]))),128)),s.length===0?(a(),r("li",X,"No matches")):f("",!0)])]))),128))])):f("",!0)])):(a(),r("div",J," AI access is currently unavailable for this user or instance. "))])]),_:1})],64))}});export{rt as default};
