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 i,v as O,x as R,t as c,j as f,F as v,n as p}from"./app-D9-EssCM.js";import{_ as V,g as B}from"./AppLayout.vue_vue_type_script_setup_true_lang-C-UlPCqH.js";import"./index-CcjNLu6f.js";import"./index-CMWG4mbA.js";import"./useForwardExpose-MNmriUeS.js";import"./VisuallyHidden-DG35s1YI.js";import"./RovingFocusGroup-Diffidi3.js";import"./useArrowNavigation-C6Y-ieo6.js";import"./x-DwmBYYXD.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"},it=A({__name:"Assistant",setup(z){const h=q(),y=C(()=>!!h.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(()=>[i("div",F,[t[1]||(t[1]=i("h1",{class:"text-2xl font-bold text-gray-900"},"AI Assistant",-1)),t[2]||(t[2]=i("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,[i("div",E,[O(i("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]]),i("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,p(m.value,(s,n)=>(a(),r("div",{key:n,class:"rounded border border-gray-200 p-3"},[i("h2",Q,c(x[n]||n),1),i("ul",H,[(a(!0),r(v,null,p(s,(b,j)=>(a(),r("li",{key:`${n}-${j}`,class:"rounded border border-gray-200 bg-gray-50 px-2 py-2"},[i("a",{href:k(n,b),class:"font-semibold text-indigo-700 hover:underline"},c(g(n,b)),9,K),i("p",U,c($(n,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{it as default};
