1import{a as Ve,_ as Ge}from"./D5x5C11H.js";import{j as je,h as Ke,i as Qe,_ as Xe,a as Ye,b as Je,d as Ze,e as et,c as tt,u as ot,g as at}from"./Bo-yXcDB.js";import{$ as nt,ce as st,aP as rt,ci as it,B as M,co as d,w as u,aT as m,z as r,X as a,bi as U,bu as t,av as lt,k as ct,H as y,K as f,b as q,W as dt,b7 as ut,cs as mt,l as pt,b2 as w,aE as Z,aF as ft}from"./CXIuakc8.js";import{_ as ht}from"./Co_NMAav.js";import{_ as _t,a as gt}from"./Sa26LwZ2.js";import{_ as vt}from"./BAhCWhUx.js";import{_ as bt}from"./DZv0qkZN.js";import{c as xt,a as kt,i as Ct}from"./5tKukZDQ.js";import{F as yt,G as wt,E as St,s as Pt}from"./DWKLVxxn.js";import{b as It}from"./DPJ6B0B3.js";import{u as $t}from"./BA9kmLZz.js";import{u as Rt}from"./CysviCYJ.js";import{u as At}from"./BOThZyKQ.js";import{u as ee}from"./CD497f2P.js";import"./DHvFfwqU.js";import"./DlAUqK2U.js";import"./DrAEqdg5.js";import"./BSTo-zps.js";import"./DAtxuE7g.js";import"./DpYDoxR8.js";import"./D6yXboVo.js";import"./LwFMw-kF.js";import"./bkkbg8BH.js";import"./CpdIDv4v.js";import"./B193RgFN.js";import"./CorxmX04.js";import"./C6GXrjSJ.js";import"./BibHzK5f.js";import"./D48wv2qz.js";import"./D0UrfZ70.js";import"./C8zl_MXD.js";import"./xixxMBiS.js";import"./Bwba5Qg3.js";import"./DhwD76XX.js";import"./CdmAYfpB.js";import"./GyRElevG.js";import"./BtrMiW2h.js";import"./v_xTvXme.js";import"./D5JIIQ-v.js";import"./bcaiVf74.js";import"./DXETF7aB.js";import"./DeriO5s2.js";import"./B5HgHlOm.js";import"./BRD1O8tw.js";import"./ZGevpTRP.js";import"./ByiqjLcu.js";const Ot={class:"flex min-h-full flex-1"},zt={class:"text-3xl sm:text-4xl text-highlighted font-bold"},Et={class:"w-full"},Ft={class:"relative"},Tt={class:"flex items-center gap-1"},Mt={class:"flex flex-col gap-2"},Ut={class:"flex flex-wrap gap-2"},qt={key:0},Bt={key:1,class:"space-y-2 pt-1"},Dt={class:"flex items-center gap-2"},Ht={class:"flex flex-wrap gap-2"},Wt={key:0,class:"relative"},Lt={key:0,class:"absolute bottom-full left-0 z-10 mb-2 w-72 rounded-lg border border-primary/30 bg-elevated p-3 shadow-lg"},Nt={class:"mt-3 flex flex-wrap gap-2"},Vt={key:1,class:"relative inline-flex"},Gt=["onClick"],Ho=nt({__name:"index",setup(jt){const i=w(""),l=w(!1),S=w(!1),B=st(),{user:R}=$t(),{currentWorkspace:h,ensureCurrentWorkspace:D}=xt(),{createChatSession:te}=Rt(),{canCreate:H,guardCreate:oe,upgradeMessage:ae,loadPlanSummary:W}=kt(),{loadProvidersForCurrentWorkspace:ne}=yt(),{connectTrello:se}=At(),{pendingAttachments:L,addFiles:re,removeStagedFile:ie,clearStagedFiles:le,getStagedFiles:ce,hasStagedFiles:N}=je(),{prompts:de}=Ke(),V=w(null),{openItems:G,completedCount:ue,items:me,showOnboarding:j,loadOnboardingStatus:K,dismissOptionalStep:pe,loadOptionalDismissals:Q}=wt(),fe=u(()=>{const e=new Date().getHours();let o="Good evening";e<12?o="Good morning":e<18&&(o="Good afternoon");const s=It(R.value);return s?`${o}, ${s}`:`${o}`}),_=u(()=>H("chatSessions")),P=u(()=>{if(!H("chatSessions"))return ae("chatSessions")});async function g(e){if(!oe("chatSessions"))return;const o=e.trim(),s=ce();if(!o&&s.length===0)return;const F=o||"Screenshot upload";i.value=o,l.value=!0;try{const k=(h.value??await D())?.id;if(s.length>0&&!k)throw new Error("Workspace is required to upload attachments.");const C=await te(F),$=C.id;if(s.length>0&&k){const p=await ot(k,$,s);St($,p),le()}const c=o||"Please create a lead from this screenshot.";try{await Z({path:C.to,query:{prompt:c}})}catch(p){console.error("[chat-sessions] Home navigation with prompt failed, retrying without query",p),await Z(C.to)}}catch(v){if(Ct(v))return;console.error("[chat-sessions] Home create failed",v),B.add({title:"Failed to start chat",description:at(v,"Unable to start chat with attachment."),icon:"i-lucide-alert-circle",color:"error"})}finally{l.value=!1}}rt(async()=>{Q();try{await Promise.all([ne(),K(),W()])}catch(e){console.error("[app-home] Initial load failed",e)}}),it(()=>h.value?.id,async(e,o)=>{if(!(!e||e===o)){Q();try{await Promise.all([K(),W(e)])}catch(s){console.error("[app-home] Workspace onboarding reload failed",s)}}});function he(e){pe(e)}async function _e(){const e=Ie(i.value);Pe(),await g(e)}async function ge(e){if(!l.value){if(Pt(e)&&!N.value){Y(e);return}await g(e)}}const I=w(null),{slashOpen:ve,slashActiveIndex:X,slashQuery:be,isRecordQuery:xe,menuItems:ke,loadingRecords:Ce,recordsError:ye,recordCache:we,selectSlashItem:Se,clearRecordMentions:Pe,buildMessageWithMentions:Ie,ensureRecordInfo:$e}=Qe({input:i,workspaceId:u(()=>h.value?.id),chatPromptRef:I,disabled:u(()=>l.value),savedPrompts:de});function Re(){ft(()=>{const e=I.value?.$el;if(!(e instanceof HTMLElement))return;const o=e.querySelector("textarea");if(!(o instanceof HTMLTextAreaElement))return;o.focus();const s=i.value.length;o.setSelectionRange(s,s)})}function Y(e){l.value||(i.value=e,Re())}const A=ee("onboarding-coachmark-dismissed-v2",{default:()=>({})}),b=ee("onboarding-panel-dismissed-v1",{default:()=>({})}),x=u(()=>{const e=h.value?.id,o=R.value?.id??R.value?.email;return!e||!o?null:`${e}:${o}`}),J=u(()=>{const e=x.value;return e?!!b.value[e]:!1}),O=u(()=>j.value&&!J.value),z=u(()=>G.value[0]??null),Ae=u(()=>{const e=x.value;return e?!!A.value[e]:!1}),Oe=u(()=>O.value&&!!z.value&&!Ae.value);function E(){const e=x.value;e&&(A.value={...A.value||{},[e]:!0})}function ze(){const e=x.value;e&&(b.value={...b.value||{},[e]:!0},E())}function Ee(){const e=x.value;e&&(b.value={...b.value||{},[e]:!1})}async function Fe(){const e=z.value;e&&(E(),await g(e.prompt))}async function Te(){if(!S.value){S.value=!0;try{const e=h.value??await D();if(!e)return;await se(e.id)}catch{B.add({title:"Trello is unavailable",description:"Please try again later.",color:"warning"})}finally{S.value=!1}}}function Me(){V.value?.click()}function Ue(e){const o=e.target,s=o.files?[...o.files]:[];
1s.length>0&&re(s),o.value=""}return(e,o)=>{const s=Ge,F=Xe,v=Ye,k=Je,C=tt,$=Ze,c=ct,p=ht,qe=et,Be=gt,De=_t,He=vt,We=pt,Le=bt,Ne=Ve;return m(),M(Ne,{id:"home",class:"min-h-0 flex flex-col",ui:{body:"p-0 sm:p-0 flex flex-col flex-1 min-h-0"}},{header:d(()=>[a(s)]),body:d(()=>[r("div",Ot,[a(Le,{class:"flex-1 flex flex-col justify-center gap-4 sm:gap-6 py-8"},{default:d(()=>[r("h1",zt,U(t(fe)),1),r("div",Et,[a(F,{"workspace-id":t(h)?.id,disabled:t(l),onSend:ge,onInsert:Y},null,8,["workspace-id","disabled"]),r("div",Ft,[a(v,{open:t(ve),items:t(ke),"active-index":t(X),"loading-records":t(Ce),"records-error":t(ye),query:t(be),"is-record-query":t(xe),"onUpdate:activeIndex":o[0]||(o[0]=n=>X.value=n),onSelect:t(Se)},null,8,["open","items","active-index","loading-records","records-error","query","is-record-query","onSelect"]),a(p,{text:t(P)||"",disabled:t(_)||!t(P)},{default:d(()=>[a(k,{"prompt-ref":t(I),text:t(i),"record-cache":t(we),onRequestInfo:t($e)},null,8,["prompt-ref","text","record-cache","onRequestInfo"]),a(De,{ref_key:"chatPromptRef",ref:I,modelValue:t(i),"onUpdate:modelValue":o[2]||(o[2]=n=>lt(i)?i.value=n:null),status:t(l)?"streaming":"ready",disabled:t(l),class:"[view-transition-name:chat-prompt] w-full",variant:"subtle",ui:{base:"px-1.5"},onSubmit:_e},{header:d(()=>[t(L).length?(m(),M(C,{key:0,attachments:t(L),onRemove:t(ie)},null,8,["attachments","onRemove"])):y("",!0)]),footer:d(()=>[r("div",Tt,[a($,{"workspace-id":t(h)?.id,disabled:t(l),onSelect:o[1]||(o[1]=n=>i.value=n)},null,8,["workspace-id","disabled"]),r("input",{ref_key:"fileInputRef",ref:V,type:"file",accept:"image/png,image/jpeg,image/webp",class:"hidden",multiple:"",onChange:Ue},null,544),a(p,{text:"Attach screenshot"},{default:d(()=>[a(c,{icon:"i-lucide-paperclip",color:"neutral",variant:"ghost",size:"sm","aria-label":"Attach screenshot",disabled:t(l),onClick:Me},null,8,["disabled"])]),_:1}),a(qe)]),a(p,{text:t(P)||"",disabled:t(_)||!t(P)},{default:d(()=>[a(Be,{color:"neutral",size:"sm",disabled:t(l)||!t(_)||!t(i).trim()&&!t(N)},null,8,["disabled"])]),_:1},8,["text","disabled"])]),_:1},8,["modelValue","status","disabled"])]),_:1},8,["text","disabled"])])]),r("div",Mt,[t(O)?y("",!0):(m(),f(q,{key:0},[r("div",Ut,[a(c,{icon:"i-logos-trello",label:"Integrate Trello",size:"sm",color:"neutral",variant:"outline",class:"rounded-full",loading:t(S),onClick:Te},null,8,["loading"])]),t(j)&&t(J)?(m(),f("div",qt,[a(c,{icon:"i-lucide-list-checks",label:"Show onboarding",size:"sm",color:"neutral",variant:"ghost",onClick:Ee})])):y("",!0)],64)),t(O)?(m(),f("div",Bt,[r("div",Dt,[o[3]||(o[3]=r("p",{class:"text-sm font-medium text-warning"}," Onboarding â open items ",-1)),a(He,{color:"neutral",variant:"subtle",size:"sm"},{default:d(()=>[dt(U(t(ue))+"/"+U(t(me).length),1)]),_:1}),a(p,{text:"Hide onboarding"},{default:d(()=>[a(c,{icon:"i-lucide-x",size:"xs",color:"neutral",variant:"ghost","aria-label":"Hide onboarding",onClick:ze})]),_:1})]),o[6]||(o[6]=r("p",{class:"text-sm text-muted"}," Complete these to send your first estimate PDF. You can use CRM chat now â connect advanced AI later for complex tasks. ",-1)),r("div",Ht,[(m(!0),f(q,null,ut(t(G),n=>(m(),f(q,{key:n.id},[n.id===t(z)?.id?(m(),f("div",Wt,[a(c,{icon:n.icon,label:n.label,size:"sm",color:"neutral",variant:"outline",class:"rounded-full",disabled:!t(_),onClick:T=>g(n.prompt)},null,8,["icon","label","disabled","onClick"]),t(Oe)?(m(),f("div",Lt,[o[4]||(o[4]=r("p",{class:"text-sm font-medium text-highlighted"}," Start here ",-1)),o[5]||(o[5]=r("p",{class:"mt-1 text-sm text-muted"}," Complete onboarding to unlock quotes, invoices, and a faster setup. ",-1)),r("div",Nt,[a(c,{size:"xs",color:"primary",label:"Start onboarding",onClick:Fe}),a(c,{size:"xs",color:"neutral",variant:"ghost",label:"Not now",onClick:E})])])):y("",!0)])):n.optional?(m(),f("div",Vt,[a(c,{icon:n.icon,label:n.label,size:"sm",color:"neutral",variant:"outline",class:"rounded-full pe-7",disabled:!t(_),onClick:T=>g(n.prompt)},null,8,["icon","label","disabled","onClick"]),a(p,{text:"Skip"},{default:d(()=>[r("button",{type:"button",class:"absolute -top-1.5 -right-1.5 flex size-5 items-center justify-center rounded-full border border-default bg-elevated text-muted shadow-sm transition-colors hover:bg-muted hover:text-highlighted","aria-label":"Skip",onClick:mt(T=>he(n.id),["stop"])},[a(We,{name:"i-lucide-x",class:"size-3"})],8,Gt)]),_:2},1024)])):(m(),M(c,{key:2,icon:n.icon,label:n.label,size:"sm",color:"neutral",variant:"outline",class:"rounded-full",disabled:!t(_),onClick:T=>g(n.prompt)},null,8,["icon","label","disabled","onClick"]))],64))),128))])])):y("",!0)])]),_:1})])]),_:1})}}});
1export{Ho 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.