1import{cn as c,cx as p,c5 as e,q as le,ae as ie,G as P,ab as X,aH as ce,S as Z,cE as xe,J as ge,a8 as me,b1 as ue,p as he,I as fe,ah as ye,b2 as be,s as pe,R as je,y as ve}from"./index-BUmD633_.js";import{u as we}from"./useStaticPageHeader-CBvCG2GQ.js";import{F as ke}from"./ArrowDownTrayIcon-BKWex8pL.js";import{F as K}from"./HandThumbDownIcon-CKilviwO.js";import{F as Ne}from"./FunnelIcon-B_wZr4vI.js";const _e=({conversation:r,onClose:$})=>{const[j,v]=c.useState([]),[M,_]=c.useState(!0),[S,R]=c.useState(null);c.useEffect(()=>{h()},[r]);const h=async()=>{try{_(!0),R(null),r.source==="widget"?await C():await f()}catch(t){R(t.message||"Failed to load conversation messages"),console.error("Error fetching messages:",t)}finally{_(!1)}},C=async()=>{const{data:t,error:u}=await p.from("widget_conversations").select("id, content, role, created_at, reasoning_time_ms, metadata").eq("thread_id",r.conversationId).order("created_at",{ascending:!0});if(u)throw u;const s=(t||[]).map(o=>({id:o.id,role:o.role,content:o.content,timestamp:o.created_at,model:o.role==="assistant"?"AI Assistant":void 0,responseTime:o.reasoning_time_ms}));v(s)},f=async()=>{const{data:t,error:u}=await p.from("chat_messages").select("id, content, role, created_at, metadata").eq("conversation_id",r.conversationId).order("created_at",{ascending:!0});if(u)throw u;const s=(t||[]).map(o=>{var y;return{id:o.id,role:o.role,content:o.content,timestamp:o.created_at,model:((y=o.metadata)==null?void 0:y.model)||(o.role==="assistant"?"AI Assistant":void 0)}});v(s)},E=()=>{const t=j.map(u=>`[${u.role.toUpperCase()}]: ${u.content}`).join(` 2 3`);navigator.clipboard.writeText(t),alert("Conversation copied to clipboard!")},F=()=>{const t=`Conversation: ${r.conversationTitle} 4Date: ${new Date(r.feedbackDate).toLocaleString()} 5Source: ${r.source} 6`+(r.widgetName?`Widget: ${r.widgetName} 7`:"")+(r.userInfo.name?`User: ${r.userInfo.name} 8`:"")+(r.userInfo.email?`Email: ${r.userInfo.email} 9`:"")+(r.userInfo.domain?`Domain: ${r.userInfo.domain} 10`:"")+(r.userInfo.language?`Language: ${r.userInfo.language} 11`:"")+` 12${"=".repeat(60)} 13 14`+j.map(y=>`[${y.role.toUpperCase()}] ${new Date(y.timestamp).toLocaleString()} 15${y.content}`).join(` 16 17`+"-".repeat(60)+` 18 19`),u=new Blob([t],{type:"text/plain"}),s=URL.createObjectURL(u),o=document.createElement("a");o.href=s,o.download=`conversation-${r.conversationId}.txt`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s)},A=t=>new Date(t).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",second:"2-digit"});return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 mb-1",children:r.conversationTitle}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:[r.source==="widget"?"Widget Conversation":"AI Support Conversation"," ⢠",new Date(r.feedbackDate).toLocaleDateString()]})]}),e.jsx("button",{onClick:$,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx(le,{className:"w-6 h-6 text-gray-500 dark:text-gray-400"})})]}),e.jsxs("div",{className:"flex items-center space-x-2 px-6 py-3 bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600",children:[e.jsxs("button",{onClick:E,className:"flex items-center space-x-2 px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsx("span",{children:"Copy"})]}),e.jsxs("button",{onClick:F,className:"flex items-center space-x-2 px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium",children:[e.jsx(ke,{className:"w-4 h-4"}),e.jsx("span",{children:"Export"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-4 dark:bg-gray-900",children:M?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Loading messages..."})]})}):S?e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-start space-x-3",children:[e.jsx(P,{className:"w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-red-900 dark:text-red-200",children:"Error Loading Messages"}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300 mt-1",children:S})]})]}):j.length===0?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:"No messages found in this conversation."})}):j.map(t=>e.jsx("div",{className:`flex ${t.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-lg p-4 ${t.role==="user"?"bg-blue-600 text-white":t.role==="system"?"bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100"}`,children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-2",children:[t.role==="user"?e.jsx(X,{className:"w-4 h-4"}):e.jsx(ce,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs font-semibold uppercase",children:t.role}),e.jsx("span",{className:"text-xs opacity-75",children:A(t.timestamp)})]}),e.jsx("div",{className:"whitespace-pre-wrap break-words",children:t.content}),(t.model||t.responseTime)&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-current opacity-50 text-xs",children:[t.model&&e.jsxs("div",{children:["Model: ",t.model]}),t.responseTime&&e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Z,{className:"w-3 h-3"}),e.jsxs("span",{children:[t.responseTime,"ms"]})]})]})]})},t.id))}),e.jsx("div",{className:"flex items-center justify-end space-x-3 p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-700",children:e.jsx("button",{onClick:$,className:"px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors font-medium",children:"Close"})})]})})},Se=({item:r,onViewConversation:$,onRefresh:j})=>{const{user:v}=xe(),[M,_]=c.useState(!1),[S,R]=c.useState(""),[h,C]=c.useState(!1),f=s=>new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),E=async()=>
19{if(v){C(!0);try{const{data:s,error:o}=await p.rpc("mark_feedback_as_resolved",{p_feedback_type:r.source==="widget"?"widget":"chat",p_feedback_id:r.id,p_user_id:v.id,p_resolution_notes:S||null});if(o)throw o;s!=null&&s.success?(_(!1),R(""),j()):alert((s==null?void 0:s.error)||"Failed to mark as resolved")}catch(s){console.error("Error marking feedback as resolved:",s),alert(s.message||"Failed to mark as resolved")}finally{C(!1)}}},F=async()=>{if(v&&confirm("Are you sure you want to reopen this feedback?")){C(!0);try{const{data:s,error:o}=await p.rpc("mark_feedback_as_pending",{p_feedback_type:r.source==="widget"?"widget":"chat",p_feedback_id:r.id,p_user_id:v.id});if(o)throw o;s!=null&&s.success?j():alert((s==null?void 0:s.error)||"Failed to reopen feedback")}catch(s){console.error("Error reopening feedback:",s),alert(s.message||"Failed to reopen feedback")}finally{C(!1)}}},A=()=>r.source==="widget"?e.jsxs("div",{className:"flex items-center space-x-1 px-3 py-1 bg-blue-100 text-blue-700 rounded-full text-xs font-medium",children:[e.jsx(ye,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Widget"})]}):e.jsxs("div",{className:"flex items-center space-x-1 px-3 py-1 bg-purple-100 text-purple-700 rounded-full text-xs font-medium",children:[e.jsx(be,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"AI Support"})]}),t=(s,o)=>{const y=new Date(s).getTime(),q=new Date(o).getTime()-y,L=Math.floor(q/6e4),N=Math.floor(L/60),B=Math.floor(N/24);return B>0?`${B}d ${N%24}h`:N>0?`${N}h ${L%60}m`:`${L}m`},u=()=>r.resolutionStatus==="resolved"?e.jsxs("div",{className:"flex items-center space-x-1 px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs font-medium",children:[e.jsx(pe,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Resolved"})]}):e.jsxs("div",{className:"flex items-center space-x-1 px-3 py-1 bg-orange-100 text-orange-700 rounded-full text-xs font-medium",children:[e.jsx(P,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Pending"})]});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-2 flex-wrap gap-2",children:[A(),u(),r.widgetName&&e.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["⢠",r.widgetName]})]}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:r.conversationTitle})]}),e.jsxs("button",{onClick:()=>$(r),className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-sm font-medium",children:[e.jsx(ge,{className:"w-4 h-4"}),e.jsx("span",{children:"View"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(me,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Feedback Received"}),e.jsx("span",{children:f(r.feedbackDate)})]})]}),e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(Z,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Duration"}),e.jsx("span",{children:t(r.conversationStarted,r.feedbackDate)})]})]}),r.messageCount!==void 0&&e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(ue,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Messages"}),e.jsxs("span",{children:[r.messageCount," messages"]})]})]}),r.userInfo.language&&e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(he,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Language"}),e.jsx("span",{children:r.userInfo.language.toUpperCase()})]})]}),r.userInfo.domain&&e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(fe,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Domain"}),e.jsx("span",{className:"truncate max-w-[200px]",title:r.userInfo.domain,children:r.userInfo.domain})]})]}),(r.userInfo.name||r.userInfo.email)&&e.jsxs("div",{className:"flex items-center text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(X,{className:"w-4 h-4 mr-2 text-gray-400 dark:text-gray-500"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"User"}),e.jsx("span",{className:"truncate max-w-[200px]",title:r.userInfo.name||r.userInfo.email,children:r.userInfo.name||r.userInfo.email})]})]})]}),r.resolutionStatus==="resolved"&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:"Resolved by:"})," ",r.resolverName||"Unknown"]}),r.resolvedAt&&e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:[e.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:"Resolved on:"})," ",f(r.resolvedAt)]}),r.resolutionNotes&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:"Resolution Notes:"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:r.resolutionNotes})]})]}),e.jsx("button",{onClick:F,disabled:h,className:"ml-4 px-3 py-1 text-sm text-orange-600 dar
19k:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300 hover:bg-orange-50 dark:hover:bg-orange-900/30 rounded transition-colors disabled:opacity-50",children:h?"Reopening...":"Reopen"})]})}),r.resolutionStatus==="pending"&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200 dark:border-gray-700",children:e.jsx("button",{onClick:()=>_(!0),disabled:h,className:"w-full px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm font-medium disabled:opacity-50",children:"Mark as Resolved"})})]}),M&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full",children:[e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4",children:"Mark Feedback as Resolved"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:"You can optionally add notes about how this issue was resolved:"}),e.jsx("textarea",{value:S,onChange:s=>R(s.target.value),placeholder:"Resolution notes (optional)...",rows:4,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700 px-6 py-4 flex justify-end space-x-3 rounded-b-lg",children:[e.jsx("button",{onClick:()=>{_(!1),R("")},disabled:h,className:"px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 rounded-lg transition-colors disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:E,disabled:h,className:"px-4 py-2 text-sm font-medium text-white bg-green-600 hover:bg-green-700 rounded-lg transition-colors disabled:opacity-50",children:h?"Marking Resolved...":"Mark as Resolved"})]})]})})]})},De=()=>{we("Chat Replies");const[r,$]=c.useState(!0),[j,v]=c.useState(null),[M,_]=c.useState([]),[S,R]=c.useState([]),[h,C]=c.useState("30d"),[f,E]=c.useState("all"),[F,A]=c.useState("pending"),[t,u]=c.useState(""),[s,o]=c.useState("date-desc"),[y,W]=c.useState(null),[q,L]=c.useState(!1),[N,B]=c.useState({total:0,pending:0,resolved:0,widget:0,chat:0,resolutionRate:0});c.useEffect(()=>{V()},[h]),c.useEffect(()=>{te()},[M,f,F,t,s]);const V=async()=>{try{$(!0),v(null);const a=ee(h),[n,l]=await Promise.all([re(a),ae(a)]),x=[...n,...l];_(x);const b=x.filter(k=>k.resolutionStatus==="pending").length,w=x.filter(k=>k.resolutionStatus==="resolved").length,m=x.length>0?Math.round(w/x.length*100):0;B({total:x.length,pending:b,resolved:w,widget:n.length,chat:l.length,resolutionRate:m})}catch(a){v(a.message||"Failed to load feedback data"),console.error("Error fetching feedback:",a)}finally{$(!1)}},ee=a=>{if(a==="all")return null;const n=a==="7d"?7:a==="30d"?30:90,l=new Date;return l.setDate(l.getDate()-n),l.toISOString()},re=async a=>{var J,Q,Y;let n=p.from("widget_conversation_feedback").select("id, thread_id, rated_at, resolution_status, resolved_at, resolved_by, resolution_notes").eq("was_helpful",!1).order("rated_at",{ascending:!1});a&&(n=n.gte("rated_at",a));const{data:l,error:x}=await n;if(x)throw x;if(!l||l.length===0)return[];const b=l.map(d=>d.thread_id),w=[...new Set(l.map(d=>d.resolved_by).filter(Boolean))],{data:m,error:k}=await p.from("widget_conversation_threads").select("id, title, created_at, message_count, session_id, widget_id").in("id",b);if(k)throw k;const U=new Map((m==null?void 0:m.map(d=>[d.id,d]))||[]),i=[...new Set((m==null?void 0:m.map(d=>d.session_id).filter(Boolean))||[])],I=[...new Set((m==null?void 0:m.map(d=>d.widget_id).filter(Boolean))||[])],[D,z,H]=await Promise.all([p.from("widget_sessions").select("id, user_language, domain").in("id",i),p.from("widget_configurations").select("id, widget_name").in("id",I),w.length>0?p.from("profiles").select("id, full_name").in("id",w):Promise.resolve({data:[],error:null})]);if(D.error)throw D.error;if(z.error)throw z.error;if(H.error)throw H.error;const de=new Map(((J=D.data)==null?void 0:J.map(d=>
19[d.id,d]))||[]),oe=new Map(((Q=z.data)==null?void 0:Q.map(d=>[d.id,d]))||[]),ne=new Map(((Y=H.data)==null?void 0:Y.map(d=>[d.id,d]))||[]);return l.map(d=>{const g=U.get(d.thread_id),T=g!=null&&g.session_id?de.get(g.session_id):null,O=g!=null&&g.widget_id?oe.get(g.widget_id):null,G=d.resolved_by?ne.get(d.resolved_by):null;return{id:d.id,source:"widget",conversationId:d.thread_id,conversationTitle:(g==null?void 0:g.title)||"Untitled Conversation",feedbackDate:d.rated_at,messageCount:g==null?void 0:g.message_count,userInfo:{language:T==null?void 0:T.user_language,domain:T==null?void 0:T.domain},conversationStarted:(g==null?void 0:g.created_at)||d.rated_at,widgetName:O==null?void 0:O.widget_name,resolutionStatus:d.resolution_status,resolvedAt:d.resolved_at,resolvedBy:d.resolved_by,resolverName:G==null?void 0:G.full_name,resolutionNotes:d.resolution_notes}})},ae=async a=>{let n=p.from("conversation_feedback").select(` 20 id, 21 conversation_id, 22 closed_at, 23 resolution_status, 24 resolved_at, 25 resolved_by, 26 resolution_notes, 27 chat_conversations!inner ( 28 id, 29 title, 30 created_at, 31 user_id 32 ) 33 `).eq("was_helpful",!1).order("closed_at",{ascending:!1});a&&(n=n.gte("closed_at",a));const{data:l,error:x}=await n;if(x)throw x;const b=[...new Set((l||[]).map(i=>i.chat_conversations.user_id))],w=[...new Set((l||[]).map(i=>i.resolved_by).filter(Boolean))],m=[...new Set([...b,...w])],{data:k}=await p.from("profiles").select("id, full_name, email").in("id",m),U=new Map((k==null?void 0:k.map(i=>[i.id,i]))||[]);return(l||[]).map(i=>{const I=U.get(i.chat_conversations.user_id),D=i.resolved_by?U.get(i.resolved_by):null;return{id:i.id,source:"chat",conversationId:i.conversation_id,conversationTitle:i.chat_conversations.title||"Untitled Conversation",feedbackDate:i.closed_at,userInfo:{name:I==null?void 0:I.full_name,email:I==null?void 0:I.email},conversationStarted:i.chat_conversations.created_at,resolutionStatus:i.resolution_status,resolvedAt:i.resolved_at,resolvedBy:i.resolved_by,resolverName:D==null?void 0:D.full_name,resolutionNotes:i.resolution_notes}})},te=()=>{let a=[...M];if(f!=="all"&&(a=a.filter(n=>n.source===f)),F!=="all"&&(a=a.filter(n=>n.resolutionStatus===F)),t){const n=t.toLowerCase();a=a.filter(l=>{var x,b,w,m;return l.conversationTitle.toLowerCase().includes(n)||((x=l.widgetName)==null?void 0:x.toLowerCase().includes(n))||((b=l.userInfo.name)==null?void 0:b.toLowerCase().includes(n))||((w=l.userInfo.email)==null?void 0:w.toLowerCase().includes(n))||((m=l.userInfo.domain)==null?void 0:m.toLowerCase().includes(n))})}a.sort((n,l)=>{const x=new Date(n.feedbackDate).getTime(),b=new Date(l.feedbackDate).getTime();return s==="date-desc"?b-x:x-b}),R(a)},se=a=>{W(a),L(!0)};return r?e.jsx("div",{className:"flex items-center justify-center h-full min-h-screen",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Loading feedback data..."})]})}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-6 max-w-7xl mx-auto bg-gray-50 dark:bg-gray-900 min-h-screen",children:[e.jsx("div",{className:"mb-6",children:e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Track and review conversations that received negative feedback to identify improvement opportunities"})}),j&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-start space-x-3",children:[e.jsx(P,{className:"w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-red-900 dark:text-red-200",children:"Error Loading Feedback"}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300 mt-1",children:j})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-1",children:"Pending Issues"}
33),e.jsx("p",{className:"text-3xl font-bold text-orange-600 dark:text-orange-400",children:N.pending})]}),e.jsx("div",{className:"w-12 h-12 bg-orange-100 dark:bg-orange-900/40 rounded-lg flex items-center justify-center",children:e.jsx(P,{className:"w-6 h-6 text-orange-600 dark:text-orange-400"})})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-1",children:"Resolved Issues"}),e.jsx("p",{className:"text-3xl font-bold text-green-600 dark:text-green-400",children:N.resolved})]}),e.jsx("div",{className:"w-12 h-12 bg-green-100 dark:bg-green-900/40 rounded-lg flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-green-600 dark:text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-1",children:"Resolution Rate"}),e.jsxs("p",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100",children:[N.resolutionRate,"%"]})]}),e.jsx("div",{className:"w-12 h-12 bg-blue-100 dark:bg-blue-900/40 rounded-lg flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-1",children:"Total Feedback"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100",children:N.total})]}),e.jsx("div",{className:"w-12 h-12 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center",children:e.jsx(K,{className:"w-6 h-6 text-gray-600 dark:text-gray-400"})})]})})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center lg:justify-between space-y-4 lg:space-y-0 mb-6",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ne,{className:"w-5 h-5 text-gray-600 dark:text-gray-400"}),e.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"Filters"})]}),e.jsxs("button",{onClick:V,className:"flex items-center space-x-2 px-4 py-2 text-sm bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded-lg hover:bg-blue-100 dark:hover:bg-blue-900/50 transition-colors",children:[e.jsx(je,{className:"w-4 h-4"}),e.jsx("span",{children:"Refresh"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Date Range"}),e.jsxs("select",{value:h,onChange:a=>C(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"7d",children:"Last 7 days"}),e.jsx("option",{value:"30d",children:"Last 30 days"}),e.jsx("option",{value:"90d",children:"Last 90 days"}),e.jsx("option",{value:"all",children:"All time"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Resolution Status"}),e.jsxs("select",{value:F,onChange:a=>A(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"resolved",children:"Resolved"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Source"}),e.jsxs("select",{value:f,onChange:a=>E(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"all",children:"All Sources"}),e.jsx("option",{value:"widget",children:"Widget (Chatmigo)"}),e.jsx("option",{value:"chat",children:"AI Support"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Sort By"}),e.jsxs("select",{value:s,onChange:a=>o(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"date-desc",children:"Newest First"}),e.jsx("option",{value:"date-asc",children:"Oldest First"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Search"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:t,onChange:a=>u(a.target.value),placeholder:"Search conversations...",className:"w-full pl-10 pr-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx(ve,{className:"w-5 h-5 text-gray-400 dark:text-gray-500 absolute left-3 top-1/2 transform -translate-y-1/2"})]})]})]})]}),e.jsx("div",{className:"space-y-4",children:S.length===0?e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-12",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-center max-w-md mx-auto",children:[e.jsx("div",{className:"w-16 h-16 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center mb-4",children:e.jsx(K,{className:"w-8 h-8 text-gray-400 dark:text-gray-500"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-2",children:t||f!=="all"?"No Results Found":"No Negative Feedback"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:t||f!=="all"?"Try adjusting your filters or search criteria":"Great news! No conversations have received negative feedback in this period."})]})}):S.map(a=>e.jsx(Se,{item:a,onViewConversation:se,onRefresh:V},a.id))}),q&&y&&e.jsx(_e,{conversation:y,onClose:()=>{L(!1),W(null)}})]})};export{De 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.