import{N as j,r as a,u as f,af as g,e,B as p,aq as y,aR as A,S as E,eu as v,T as u,L}from"./index-_6SmYgWK.js";import{i as I}from"./index-D_D57pxa.js";const R=()=>{const n=document.location.pathname.toString().split("/"),x=n[n.length-1]==="chatbot"?"":n[n.length-1],c=j(),[l,m]=a.useState(null),[C,h]=a.useState({}),[w,b]=a.useState(!0),[S,d]=a.useState({}),o=f(g.getSpecificChatflowFromPublicEndpoint),i=f(g.getSpecificChatflow);return a.useEffect(()=>{o.request(x)},[]),a.useEffect(()=>{if(o.data||i.data){const s=o.data||i.data;m(s);const r=s.type;if(s.chatbotConfig){let t={};(r==="MULTIAGENT"||r==="AGENTFLOW")&&(t.showAgentMessages=!0);try{t={...t,...JSON.parse(s.chatbotConfig)},h(t),t.overrideConfig&&d(t.overrideConfig),t.generateNewSession&&localStorage.removeItem(`${s.id}_EXTERNAL`)}catch(T){console.error(T),h(t),d({})}}else(r==="MULTIAGENT"||r==="AGENTFLOW")&&h({showAgentMessages:!0})}},[o.data,i.data]),a.useEffect(()=>{b(o.loading||i.loading)},[o.loading,i.loading]),e.jsx(e.Fragment,{children:w?null:e.jsx(e.Fragment,{children:!l||l.apikeyid?e.jsx(p,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80vh"},children:e.jsx(p,{sx:{maxWidth:"500px",width:"100%"},children:e.jsx(y,{variant:"outlined",sx:{border:`1px solid ${c.palette.error.main}`,borderRadius:2,padding:"20px",boxShadow:`0 4px 8px ${A(c.palette.error.main,.15)}`},children:e.jsxs(E,{spacing:2,alignItems:"center",children:[e.jsx(v,{size:50,color:c.palette.error.main}),e.jsx(u,{variant:"h3",color:"error.main",align:"center",children:"Invalid Chatbot"}),e.jsx(u,{variant:"body1",color:"text.secondary",align:"center",children:"The chatbot you're looking for doesn't exist or requires API key authentication."})]})})})}):e.jsx(I,{chatflowid:l.id,apiHost:L,chatflowConfig:S,theme:{chatWindow:C}})})})};export{R as default};
