1import{r as e,j as t,C as s,Z as a}from"./mui-7de4f23d.js";import{d as r}from"./SupportAgent-f49d6400.js";import{d as l}from"./Search-a443ec17.js";import{c as n,a as i}from"./react-vendor-60cd4be3.js";import{d}from"./ChatBubbleOutline-5c9ea136.js";import{r as o,i as c}from"./createSvgIcon-e6c3e379.js";import{M as x}from"./ChatComponent-f93d92e1.js";import{u as m}from"./useApi-e64add70.js";import{d as g}from"./AutoFixHigh-4a00b049.js";import{d as u}from"./BarChart-a44a88b0.js";import"./CloseRounded-8a13cc3e.js";import"./KeyboardArrowDown-ba12602f.js";import"./index-2b7856a0.js";import"./axiosInstance-9d8a485a.js";import"./axios-c6845f15.js";import"./index-2ba3c2ef.js";function h({threads:a=[],loading:i,search:d="",onSearchChange:o,onLoadMore:c,hasMore:x,filteredTotal:m=0}){const{thread_id:g}=n(),u=e.useRef(null),h=e.useCallback(()=>{const e=u.current;if(!e||i||!x)return;const{scrollTop:t,scrollHeight:s,clientHeight:a}=e;s-t-a<200&&c?.()},[i,x,c]);return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center space-x-2 px-4 py-3 border-b border-gray-100",children:[t.jsx(r,{className:"!text-indigo-600",sx:{fontSize:20}}),t.jsxs("h2",{className:"text-sm font-bold text-gray-800",children:["Threads"," ",t.jsxs("span",{className:"text-gray-400 font-normal",children:["(",m,")"]})]})]}),t.jsx("div",{className:"px-3 py-2 border-b border-gray-100",children:t.jsxs("div",{className:"relative",children:[t.jsx(l,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 !text-gray-400",sx:{fontSize:16}}),t.jsx("input",{type:"text",placeholder:"Search by name, email, or ID...",value:d,onChange:e=>o?.(e.target.value),className:"w-full pl-8 pr-3 py-1.5 text-xs rounded-lg border border-gray-200 focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-transparent bg-gray-50"})]})}),i&&0===a.length?t.jsx("div",{className:"flex-1 flex justify-center items-center",children:t.jsx(s,{size:28})}):t.jsxs("div",{ref:u,onScroll:h,className:"flex-1 overflow-y-auto px-2 py-1",children:[0===a.length&&!i&&t.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-gray-400",children:"No threads found"}),a.map(e=>t.jsx(f,{thread:e,activeThread:g},e.id)),i&&a.length>0&&t.jsx("div",{className:"flex justify-center py-3",children:t.jsx(s,{size:20})}),x&&!i&&t.jsx("button",{onClick:c,className:"w-full py-2 text-xs text-indigo-600 hover:text-indigo-800 font-medium",children:"Load more threads..."})]})]})}const f=({thread:e,activeThread:s})=>{const r=i(),l=e.thread_id===s,n=e.category?C[e.category]||C["General Questions"]:null;return t.jsx("div",{onClick:()=>r(`/chat-threads/${e.thread_id}`),className:"px-3 py-2.5 rounded-xl cursor-pointer transition-all mb-0.5 "+(l?"bg-indigo-50 border border-indigo-200":"hover:bg-gray-50 border border-transparent"),children:t.jsxs("div",{className:"flex items-center space-x-2.5",children:[t.jsx(a,{sx:{width:32,height:32,fontSize:13,bgcolor:l?"#4F46E5":"#94A3B8"},children:e.firstName?.charAt(0)?.toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h3",{className:"text-sm font-semibold text-gray-800 truncate",children:[e.firstName," ",e.lastName]}),t.jsx("span",{className:"ml-1 bg-gray-200 text-gray-600 text-[10px] font-medium rounded-full w-5 h-5 flex items-center justify-center flex-shrink-0",children:e.id})]}),t.jsx("p",{className:"text-[11px] text-gray-500 truncate",children:e.email}),e.category&&n&&t.jsx("span",{className:`inline-block mt-1 px-2 py-0.5 rounded-full text-[10px] font-semibold ${n.bg} ${n.text}`,children:e.category})]})]})})};var b={},p=c;Object.defineProperty(b,"__esModule",{value:!0});var j=b.default=void 0,y=p(o()),v=t,N=(0,y.default)((0,v.jsx)("path",{d:"M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z"}),"Forum");function w(){const{thread_id:a}=n(),{apiCall:r,loading:l,response:i}=m("get"),[o,c]=e.useState([]);return e.useEffect(()=>{(a||"").includes("thread")?(c([]),r(`/api/chatbot/messages/${a}`)):c([])},[a]),e.useEffect(()=>{const e=i?.data?.messages?.map(e=>({id:e.id,created_at:e.created_at,message:e?.msg?.text?.value,role:e.role}));c(e||[])},[i]),t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center space-x-2 px-4 py-3 border-b border-gray-100",children:[t.jsx(d,{className:"!text-indigo-600",sx:{fontSize:20}}),t.jsx("h2",{className:"text-sm font-bold text-gray-800",children:"Messages"}),o.length>0&&t.jsxs("span",{className:"text-xs text-gray-400",children:[o.length," messages"]})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[l&&t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[t.jsx(s,{size:28}),t.jsx("span",{className:"text-sm text-gray-500",children:"Loading messages..."})]})}),!a&&!l&&t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsxs("div",{className:"text-center space-y-2",children:[t.jsx(j,{sx:{fontSize:48,color:"#CBD5E1"}}),t.jsx("p",{className:"text-sm text-gray-400",children:"Select a thread to read the conversation"})]})}),a&&0===o.length&&!l&&t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsx("p",{className:"text-sm text-gray-400",children:"No messages in this thread"})}),o.map(e=>t.jsx(x,{role:e.role,message:e},e.id))]})]})}j=b.default=N;const C={"Pricing & Plans":{bg:"bg-emerald-100",text:"text-emerald-700",bar:"bg-emerald-500"},"Content Creation":{bg:"bg-blue-100",text:"text-blue-700",bar:"bg-blue-500"},"Technical Issues":{bg:"bg-red-100",text:"text-red-700",bar:"bg-red-500"},"Token System":{bg:"bg-amber-100",text:"text-amber-700",bar:"bg-
1amber-500"},"Account & Billing":{bg:"bg-purple-100",text:"text-purple-700",bar:"bg-purple-500"},Publishing:{bg:"bg-cyan-100",text:"text-cyan-700",bar:"bg-cyan-500"},"Cover Design":{bg:"bg-pink-100",text:"text-pink-700",bar:"bg-pink-500"},"Feature Requests":{bg:"bg-indigo-100",text:"text-indigo-700",bar:"bg-indigo-500"},"Lifetime Deal":{bg:"bg-orange-100",text:"text-orange-700",bar:"bg-orange-500"},"General Questions":{bg:"bg-gray-100",text:"text-gray-700",bar:"bg-gray-400"}};function S(){const{apiCall:a,loading:r,response:l}=m("get"),{apiCall:n,loading:i}=m("post");m("get");const[d,o]=e.useState("All"),[c,x]=e.useState(!1),[f,b]=e.useState(!1),[p,j]=e.useState(null),y=e.useRef(null),v=e.useRef(0),[N,S]=e.useState(1),[$,z]=e.useState([]),[k,A]=e.useState(""),[T,M]=e.useState(""),_=e.useRef(null),E=e.useRef({append:!1,page:1});e.useEffect(()=>(_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{M(k)},400),()=>{_.current&&clearTimeout(_.current)}),[k]);const I=e.useCallback((e=1,t=!1)=>{const s=new URLSearchParams;s.set("page",e),s.set("limit",50),d&&"All"!==d&&s.set("category",d),T.trim()&&s.set("search",T.trim()),E.current={append:t,page:e},a(`/api/chatbot/thread-list?${s.toString()}`)},[d,T]);e.useEffect(()=>{if(!l?.data?.threads)return;const{append:e,page:t}=E.current;z(e?e=>[...e,...l.data.threads]:l.data.threads),S(t)},[l]),e.useEffect(()=>(z([]),S(1),I(1,!1),()=>{y.current&&clearInterval(y.current)}),[d,T]);const R=l?.data?.totalThreads||0,H=l?.data?.categoryStats||[],L=l?.data?.uncategorized||0,P=l?.data?.filteredTotal||0,B=N<(l?.data?.totalPages||1),D=e.useCallback(()=>{!r&&B&&I(N+1,!0)},[r,B,N,I]);e.useEffect(()=>{f&&0===L&&R>0?(y.current&&clearInterval(y.current),b(!1),j(null)):f&&j(L)},[L,f,R]);const F=f&&v.current>0&&null!==p?Math.round((v.current-p)/v.current*100):null;return t.jsxs("div",{className:"m-2 space-y-3",children:[t.jsxs("div",{className:"bg-white rounded-2xl border shadow-sm p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx(u,{className:"!text-indigo-600"}),t.jsx("h2",{className:"text-lg font-bold text-gray-800",children:"Chat Analytics"}),t.jsxs("span",{className:"text-sm text-gray-500",children:[R," total threads"]})]}),t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("button",{onClick:()=>x(e=>!e),className:"px-3 py-1.5 rounded-lg text-sm font-medium transition-all "+(c?"bg-indigo-100 text-indigo-700":"bg-gray-100 text-gray-600 hover:bg-gray-200"),children:c?"Hide Stats":"Show Stats"}),(L>0||f)&&t.jsxs("button",{onClick:async()=>{b(!0),v.current=L,j(L),await n("/api/chatbot/classify-threads"),y.current=setInterval(async()=>{try{I(1,!1)}catch{}},5e3),setTimeout(()=>{clearInterval(y.current),b(!1),j(null),I(1,!1)},6e5)},disabled:f||i,className:"flex items-center space-x-1.5 px-3 py-1.5 rounded-lg text-sm font-medium bg-indigo-600 text-white hover:bg-indigo-700 disabled:opacity-60 disabled:cursor-not-allowed transition-all",children:[f?t.jsx(s,{size:14,sx:{color:"white"}}):t.jsx(g,{sx:{fontSize:16}}),t.jsx("span",{children:f?`Classifying... ${p??""}${null!==F?` (${F}%)`:""}`:`Classify All ${L} Thread${1!==L?"s":""}`})]})]})]}),f&&null!==F&&t.jsxs("div",{className:"mb-3",children:[t.jsxs("div",{className:"flex justify-between text-xs text-gray-500 mb-1",children:[t.jsx("span",{children:"Classifying in background..."}),t.jsxs("span",{children:[v.current-(p||0)," / ",v.current," done"]})]}),t.jsx("div",{className:"h-2 bg-gray-200 rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-indigo-500 rounded-full transition-all duration-500",style:{width:`${F}%`}})})]}),c&&H.length>0&&t.jsx("div",{className:"mt-3 pt-3 border-t",children:t.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-2",children:H.map(e=>{const s=C[e.name]||C["General Questions"],a=R>0?(e.count/R*100).toFixed(1):0;return t.jsxs("button",{onClick:()=>o(t=>t===e.name?"All":e.name),className:`relative overflow-hidden rounded-xl p-3 text-left transition-all border-2 ${d===e.name?"border-indigo-500 shadow-md":"border-transparent hover:border-gray-200"} ${s.bg}`,children:[t.jsx("div",{className:`text-xs font-semibold ${s.text} truncate`,children:e.name}),t.jsxs("div",{className:"flex items-end justify-between mt-1",children:[t.jsx("span",{className:`text-xl font-bold ${s.text}`,children:e.count}),t.jsxs("span",{className:`text-xs ${s.text} opacity-70`,children:[a,"%"]})]}),t.jsx("div",{className:"mt-1.5 h-1 bg-white/60 rounded-full overflow-hidden",children:t.jsx("div",{className:`h-full rounded-full ${s.bar}`,style:{width:`${a}%`}})})]},e.name)})})}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:["All",...H.map(e=>e.name),...L>0?["Uncategorized"]:[]].map(e=>{const s=d===e,a="All"===e||"Uncategorized"===e?{bg:"bg-gray-100",text:"text-gray-700"}:C[e]||C["General Questions"];return t.jsxs("button",{onClick:()=>o(e),className:"px-2.5 py-1 rounded-full text-xs font-medium transition-all "+(s?`${a.bg} ${a.text} ring-2 ring-offset-1 ring-indigo-400`:`${a.bg} ${a.text} opacity-70 hover:opacity-100`),children:[e,"All"===e&&` (${R})`,"Uncategorized"===e&&` (${L})`]},e)})})]}),t.jsxs("div",{className:"flex border rounded-2xl bg-white shadow-sm overflow-hidden",style:{height:"72vh"},children:[t.jsx("div",{className:"w-4/12 border-r border-gray-100 overflow-hidden",children:t.jsx(h,{threads:$,loading:r,search:k,onSearchChange:A,onLoadMore:D,hasMore:B,filteredTotal:P})}),t.jsx("div",{className:"w-8/12 overflow-hidden",children:t.jsx(w,{})})]})]})}export{C as CATEGORY_COLORS,S 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.