1import{o as f,S as d,s as U,d as M,e as k,k as H,r as l,ay as h,j as e,y as O,bC as q,U as K,b6 as B,aA as $,aB as Q}from"./vendor-Dmz4Yv-S.js";import{p as W,a as Y}from"./message_POST.schema-BtS1diAt.js";import{B as p,e as V}from"./index-CUHoaRWT.js";import{S as v}from"./Skeleton-BzPcdrtf.js";import{D as J,a as X,b as Z,c as ee}from"./Dialog-DkFCoaqR.js";import{F as te}from"./FeatureGate-Bam0xw9x.js";import"./useFeatureGate-BYMYCt5a.js";f({});const se=async a=>{const o=await fetch("/_api/admin/chatbot/docs/list",{method:"GET",...a,headers:{"Content-Type":"application/json"},credentials:"include"});if(!o.ok){const n=d.parse(await o.text());throw new Error(n.error||"Failed to fetch chatbot documents")}return d.parse(await o.text())};f({});const ae=async(a,o)=>{const n=new FormData;n.append("file",a);const c=await fetch("/_api/admin/chatbot/docs/upload",{method:"POST",body:n,...o,credentials:"include"});if(!c.ok){const r=d.parse(await c.text());throw new Error(r.error||"Failed to upload document")}return d.parse(await c.text())},oe=f({doc_id:U()}),ne=async(a,o)=>{const n=oe.parse(a),c=await fetch("/_api/admin/chatbot/docs/delete",{method:"POST",body:d.stringify(n),...o,headers:{"Content-Type":"application/json",...o?.headers??{}},credentials:"include"});if(!c.ok){const r=d.parse(await c.text());throw new Error(r.error||"Failed to delete document")}return d.parse(await c.text())};f({});const ce=async a=>{const o=await fetch("/_api/admin/chatbot/preview-context",{method:"GET",...a,headers:{"Content-Type":"application/json"},credentials:"include"});if(!o.ok){const n=d.parse(await o.text());throw new Error(n.error||"Failed to fetch preview context")}return d.parse(await o.text())};function ie(){const a=M(),o=k({queryKey:["admin","chatbot","docs"],queryFn:()=>se()}),n=k({queryKey:["admin","chatbot","preview"],queryFn:()=>ce()}),c=H({mutationFn:ae,onSuccess:()=>{a.invalidateQueries({queryKey:["admin","chatbot","docs"]}),a.invalidateQueries({queryKey:["admin","chatbot","preview"]})}}),r=H({mutationFn:ne,onSuccess:()=>{a.invalidateQueries({queryKey:["admin","chatbot","docs"]}),a.invalidateQueries({queryKey:["admin","chatbot","preview"]})}});return{docsList:o,previewContext:n,uploadDoc:c,deleteDoc:r}}const le="_page_1ac3o_1",re="_card_1ac3o_13",de="_greenCard_1ac3o_23",ue="_statusHeader_1ac3o_27",me="_statusIcon_1ac3o_33",he="_statusHeading_1ac3o_38",pe="_statusDesc_1ac3o_46",_e="_collapsibleHeader_1ac3o_54",xe="_cardHeading_1ac3o_68",be="_cardSubtext_1ac3o_76",je="_toggleBtn_1ac3o_82",ge="_collapsibleContent_1ac3o_95",ve="_grid2Col_1ac3o_107",fe="_infoGroup_1ac3o_119",ye="_label_1ac3o_125",Ne="_value_1ac3o_133",we="_updateNote_1ac3o_139",Ce="_errorState_1ac3o_146",De="_cardHeaderArea_1ac3o_152",Be="_docListArea_1ac3o_159",Ie="_tableLoading_1ac3o_163",Te="_skeletonRow_1ac3o_169",Se="_tableContainer_1ac3o_175",Fe="_table_1ac3o_163",Ae="_docIcon_1ac3o_208",ke="_filenameCell_1ac3o_213",He="_typePill_1ac3o_222",Re="_dateCell_1ac3o_233",Pe="_deleteBtn_1ac3o_239",Ee="_emptyDashedBox_1ac3o_248",Le="_emptyIcon_1ac3o_261",ze="_uploadDashedBox_1ac3o_265",Ge="_hiddenInput_1ac3o_272",Ue="_uploadPrompt_1
1ac3o_276",Me="_uploadIcon_1ac3o_284",Oe="_outlineBtn_1ac3o_289",qe="_uploadHint_1ac3o_299",Ke="_selectedFileArea_1ac3o_305",$e="_fileDetails_1ac3o_317",Qe="_fileIcon_1ac3o_323",We="_selectedFilename_1ac3o_327",Ye="_uploadActions_1ac3o_334",Ve="_cancelBtn_1ac3o_340",Je="_uploadBtn_1ac3o_348",Xe="_testBtn_1ac3o_359",Ze="_chatModalContent_1ac3o_371",et="_chatPreviewWindow_1ac3o_379",tt="_messagesArea_1ac3o_390",st="_messageRow_1ac3o_400",at="_userRow_1ac3o_406",ot="_botRow_1ac3o_411",nt="_userBubble_1ac3o_416",ct="_botBubble_1ac3o_416",it="_typingBubble_1ac3o_416",lt="_bubbleText_1ac3o_433",rt="_timestamp_1ac3o_442",dt="_typingDots_1ac3o_449",ut="_typingDot_1ac3o_449",mt="_inputBar_1ac3o_473",ht="_chatInput_1ac3o_481",pt="_sendButton_1ac3o_498",_t="_disabledInput_1ac3o_514",xt="_disabledButton_1ac3o_519",t={page:le,card:re,greenCard:de,statusHeader:ue,statusIcon:me,statusHeading:he,statusDesc:pe,collapsibleHeader:_e,cardHeading:xe,cardSubtext:be,toggleBtn:je,collapsibleContent:ge,grid2Col:ve,infoGroup:fe,label:ye,value:Ne,updateNote:we,errorState:Ce,cardHeaderArea:De,docListArea:Be,tableLoading:Ie,skeletonRow:Te,tableContainer:Se,table:Fe,docIcon:Ae,filenameCell:ke,typePill:He,dateCell:Re,deleteBtn:Pe,emptyDashedBox:Ee,emptyIcon:Le,uploadDashedBox:ze,hiddenInput:Ge,uploadPrompt:Ue,uploadIcon:Me,outlineBtn:Oe,uploadHint:qe,selectedFileArea:Ke,fileDetails:$e,fileIcon:Qe,selectedFilename:We,uploadActions:Ye,cancelBtn:Ve,uploadBtn:Je,testBtn:Xe,chatModalContent:Ze,chatPreviewWindow:et,messagesArea:tt,messageRow:st,userRow:at,botRow:ot,userBubble:nt,botBubble:ct,typingBubble:it,bubbleText:lt,timestamp:rt,typingDots:dt,typingDot:ut,inputBar:mt,chatInput:ht,sendButton:pt,disabledInput:_t,disabledButton:xt};function wt(){const{previewContext:a,docsList:o,uploadDoc:n,deleteDoc:c}=ie(),[r,I]=l.useState(!1),m=l.useRef(null),[x,y]=l.useState(null),[N,T]=l.useState(!1),[b,S]=l.useState(null),[F,_]=l.useState([]),[j,w]=l.useState(""),[u,C]=l.useState(!1),g=l.useRef(null);l.useEffect(()=>{g.current&&g.current.scrollTo({top:g.current.scrollHeight,behavior:"smooth"})},[F,u]),l.useEffect(()=>{N?(_([{role:"bot",content:"Hi! This is a test of your chatbot. Ask me anything your customers might ask.",timestamp:new Date}]),w(""),C(!1),W().then(s=>{"error"in s?h.error("Failed to initialize test chat session."):S(s.session_token)}).catch(()=>h.error("Failed to initialize test chat session."))):(S(null),_([]))},[N]);const R=s=>{s.target.files&&s.target.files.length>0&&y(s.target.files[0])},P=()=>{x&&n.mutate(x,{onSuccess:()=>{h.success("Document uploaded successfully."),y(null),m.current&&(m.current.value="")},onError:s=>{h.error(s instanceof Error?s.message:"Upload failed.")}})},E=s=>{window.confirm("Remove this document? Your chatbot will no longer use it.")&&c.mutate({doc_id:s},{onSuccess:()=>h.success("Document removed."),onError:i=>h.error(i instanceof Error?i.message:"Failed to remove document.")})},A=async()=>{const s=j.trim();if(!(!s||!b||u)){w(""),_(i=>[...i,{role:"user",content:s,timestamp:new Date}]),C(!0);try{const i=await Y({session_token:b,message:s,test_mode:!0});i&&i.reply&&_(D=>[...D,{role:"bot",content:i.reply,timestamp:new Date}])}catch{_(D=>[...D,{role:"bot",content:"Sorry, I ran into a problem.",timestamp:new Date}])}finally{C(!1)}}},L=s=>{s.key==="Enter"&&(s.preventDefault(),A())},z=s=>new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(s)),G=s=>new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).format(s);return e.jsx(te,{featureName:"featureChatbot",tier:"growth",label:"AI Chatbot",benefitCopy:"A 24/7 AI assistant that answers customer questions and captures leads while you sleep.",children:e.jsxs("div",{className:t.page,children:[e.jsxs("div",{className:`${t.card} ${t.greenCard}`,children:[e.jsxs("div",{className:t.statusHeader,children:[e.jsx(O,{className:t.statusIcon,size:24}),e.jsx("h2",{className:t.statusHeading,children:"Your chatbot is active"})]}),e.jsx("p",{className:t.statusDesc,children:"It's live on your website and already knows your business basics. You can teach it more below."})]}),e.jsxs("div",{className:t.card,children:[e.jsxs("div",{className:t.collapsibleHeader,onClick:()=>I(!r),role:"button",tabIndex:0,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&I(!r)}
1,children:[e.jsx("h2",{className:t.cardHeading,children:"What Your Chatbot Already Knows"}),e.jsx(p,{variant:"ghost",size:"sm",className:t.toggleBtn,children:r?e.jsxs(e.Fragment,{children:[e.jsx(q,{size:16})," Hide details"]}):e.jsxs(e.Fragment,{children:[e.jsx(K,{size:16})," Show details"]})})]}),r&&e.jsx("div",{className:t.collapsibleContent,children:a.isPending?e.jsx("div",{className:t.grid2Col,children:[1,2,3,4,5,6].map(s=>e.jsxs("div",{className:t.infoGroup,children:[e.jsx(v,{style:{width:"80px",height:"14px",marginBottom:"8px"}}),e.jsx(v,{style:{width:"100%",height:"20px"}})]},s))}):a.data?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.grid2Col,children:[e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Business"}),e.jsx("div",{className:t.value,children:a.data.businessName||"â"})]}),e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Phone"}),e.jsx("div",{className:t.value,children:a.data.phone||"â"})]}),e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Email"}),e.jsx("div",{className:t.value,children:a.data.email||"â"})]}),e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Tagline"}),e.jsx("div",{className:t.value,children:a.data.tagline||"â"})]}),e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Services"}),e.jsx("div",{className:t.value,children:a.data.differentiators?.join(", ")||"â"})]}),e.jsxs("div",{className:t.infoGroup,children:[e.jsx("div",{className:t.label,children:"Cities served"}),e.jsx("div",{className:t.value,children:a.data.serviceAreaCities?.join(", ")||"â"})]})]}),e.jsx("div",{className:t.updateNote,children:"To update these, use the Site Editor (âï¸ button) or contact your account manager."})]}):e.jsx("div",{className:t.errorState,children:"Failed to load context."})})]}),e.jsxs("div",{className:t.card,children:[e.jsxs("div",{className:t.cardHeaderArea,children:[e.jsx("h2",{className:t.cardHeading,children:"Training Documents"}),e.jsx("p",{className:t.cardSubtext,children:"Upload FAQs, pricing sheets, or service details to make your chatbot smarter."})]}),e.jsx("div",{className:t.docListArea,children:o.isPending?e.jsxs("div",{className:t.tableLoading,children:[e.jsx(v,{className:t.skeletonRow}),e.jsx(v,{className:t.skeletonRow})]}):o.data?.docs&&o.data.docs.length>0?e.jsx("div",{className:t.tableContainer,children:e.jsxs("table",{className:t.table,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{width:"40px"}}),e.jsx("th",{children:"Filename"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Uploaded"}),e.jsx("th",{style:{width:"60px",textAlign:"right"}})]})}),e.jsx("tbody",{children:o.data.docs.map(s=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx(B,{size:18,className:t.docIcon})}),e.jsx("td",{className:t.filenameCell,children:s.filename}),e.jsx("td",{children:e.jsx("span",{className:t.typePill,children:s.fileType.toUpperCase()})}),e.jsx("td",{className:t.dateCell,children:z(s.createdAt)}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx(p,{variant:"ghost",size:"icon-sm",onClick:()=>E(s.id),className:t.deleteBtn,disabled:c.isPending,title:"Remove document",children:e.jsx($,{size:16})})})]},s.id))})]})}):e.jsxs("div",{className:t.emptyDashedBox,children:[e.jsx(B,{size:32,className:t.emptyIcon}),e.jsx("p",{children:"No training documents yet. Upload a file to get started."})]})}),e.jsxs("div",{className:t.uploadDashedBox,children:[e.jsx("input",{type:"file",accept:".txt,.pdf,.md",ref:m,onChange:R,className:t.hiddenInput}),x?e.jsxs("div",{className:t.selectedFileArea,children:[e.jsxs("div",{className:t.fileDetails,children:[e.jsx(B,{size:20,className:t.fileIcon}),e.jsx("span",{className:t.selectedFilename,children:x.name})]}),e.jsxs("div",{className:t.uploadActions,children:[e.jsx(p,{variant:"ghost",onClick:()=>{y(null),m.current&&(m.current.value="")},className:t.cancelBtn,disabled:n.isPending,children:"Cancel"}),e.jsx(p,{onClick:P,disabled:n.isPending,className:t.uploadBtn,children:n.isPending?e.jsxs(e.Fragment,{children:[e.jsx(V,{size:"sm"})," Uploading..."]}):"Upload"})]})]}):e.jsxs("div",{className:t.uploadPrompt,children:[e.jsx(Q,{size:24,className:t.uploadIcon}),e.jsx(p,{variant:"outline",onClick:()=>m.current?.click(),className:t.outlineBtn,children:"Choose File"}),e.jsx("span",{className:t.uploadHint,children:"Supported formats: PDF, TXT, MD"})]})]})]}),e.jsxs("div",{className:t.card,children:[e.jsxs("div",{className:t.cardHeaderArea,children:[e.jsx("h2",{className:t.cardHeading,children:"Test Your Chatbot"}),e.jsx("p",{className:t.cardSubtext,children:"Send messages here to see exactly how your chatbot will respond."})]}),e.jsx("div",{children:e.jsx(p,{className:t.testBtn,onClick:()=>T(!0),children:"Open Test Chat"})})]}),e.jsx(J,{open:N,onOpenChange:T,children:e.jsxs(X,{className:t.chatModalContent,children:[e.jsx(Z,{children:e.jsx(ee,{children:"Test Chatbot"})}),e.jsxs("div",{className:t.chatPreviewWindow,children:[e.jsxs("div",{className:t.messagesArea,ref:g,children:[F.map((s,i)=>e.jsxs("div",{className:`${t.messageRow} ${s.role==="user"?t.userRow:t.botRow}`,children:[e.jsx("div",{className:s.role==="user"?t.userBubble:t.botBubble,children:e.jsx("p",{className:t.bubbleText,children:s.content})}),e.jsx("span",{className:t.timestamp,children:G(s.timestamp)})]},i)),u&&e.jsx("div",{className:`${t.messageRow} ${t.botRow}`,children:e.jsx("div",{className:t.typingBubble,children:e.jsxs("div",{className:t.typingDots,children:[e.jsx("div",{className:t.typingDot}),e.jsx("div",{className:t.typingDot}),e.jsx("div",{className:t.typingDot})]})})})]}),e.jsxs("div",{className:t.inputBar,children:[e.jsx("input",{type:"text",className:`${t.chatInput}
1 ${u?t.disabledInput:""}`,value:j,onChange:s=>w(s.target.value),onKeyDown:L,placeholder:"Type a message...",maxLength:500,disabled:u||!b}),e.jsx("button",{className:`${t.sendButton} ${u||!j.trim()?t.disabledButton:""}`,onClick:A,disabled:u||!b||!j.trim(),children:"Send"})]})]})]})})]})})}export{wt 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.