1import{c as le,r as d,i as de,j as e,k as ie,l as ce,m as pe,b as ge,f as me,s as Y,n as F,D as ue,R as xe,C as he,g as be,h as ye,A as fe,d as _e,e as ke}from"./index-CrdJh3GE.js";/** 2 * @license lucide-react v1.34.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const je=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ne=le("loader-circle",je),Z={new:{dot:"bg-amber-500",trigger:"bg-amber-50 text-amber-900 border-amber-200/80 hover:bg-amber-100 dark:bg-amber-950/50 dark:text-amber-200 dark:border-amber-800/60 dark:hover:bg-amber-900/40",optionActive:"bg-amber-50 dark:bg-amber-950/40"},treated:{dot:"bg-blue-500",trigger:"bg-blue-50 text-blue-900 border-blue-200/80 hover:bg-blue-100 dark:bg-blue-950/50 dark:text-blue-200 dark:border-blue-800/60 dark:hover:bg-blue-900/40",optionActive:"bg-blue-50 dark:bg-blue-950/40"},declined:{dot:"bg-red-500",trigger:"bg-red-50 text-red-900 border-red-200/80 hover:bg-red-100 dark:bg-red-950/50 dark:text-red-200 dark:border-red-800/60 dark:hover:bg-red-900/40",optionActive:"bg-red-50 dark:bg-red-950/40"},solved:{dot:"bg-emerald-500",trigger:"bg-emerald-50 text-emerald-900 border-emerald-200/80 hover:bg-emerald-100 dark:bg-emerald-950/50 dark:text-emerald-200 dark:border-emerald-800/60 dark:hover:bg-emerald-900/40",optionActive:"bg-emerald-50 dark:bg-emerald-950/40"}},ve=({value:t,disabled:u=!1,isSaving:i=!1,onChange:l,getStatusLabel:x,ariaLabel:O})=>{const[p,D]=d.useState(!1),[y,C]=d.useState(null),S=d.useRef(null),f=d.useRef(null),N=d.useCallback(()=>{D(!1),C(null)},[]),E=d.useCallback(()=>{if(u||i||!S.current)return;const o=S.current.getBoundingClientRect(),h=176,g=8,m=Math.min(Math.max(g,o.left),window.innerWidth-h-g);C({top:o.bottom+6,left:m,width:h}),D(!0)},[u,i]),v=o=>{if(o.stopPropagation(),p){N();return}E()},P=o=>{N(),o!==t&&l(o)};d.useEffect(()=>{if(!p)return;const o=m=>{var R,A;const b=m.target;(R=S.current)!=null&&R.contains(b)||(A=f.current)!=null&&A.contains(b)||N()},h=m=>{m.key==="Escape"&&N()},g=()=>N();return document.addEventListener("mousedown",o),document.addEventListener("keydown",h),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",h),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[N,p]);const k=Z[t],M=p&&y&&typeof document<"u"?de.createPortal(e.jsx("div",{ref:f,role:"listbox","aria-label":O,className:"fixed z-[10001] animate-fade-in overflow-hidden rounded-xl border border-gray-200/90 bg-white p-1.5 shadow-xl dark:border-gray-700 dark:bg-gray-900",style:{to
6p:y.top,left:y.left,width:y.width},onClick:o=>o.stopPropagation(),onKeyDown:o=>o.stopPropagation(),children:ie.map(o=>{const h=o===t,g=Z[o];return e.jsxs("button",{type:"button",role:"option","aria-selected":h,onClick:()=>P(o),className:`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-xs font-medium transition-colors ${h?`${g.optionActive} text-gray-900 dark:text-white`:"text-gray-700 hover:bg-gray-50 dark:text-gray-200 dark:hover:bg-gray-800/80"}`,children:[e.jsx("span",{className:`h-2 w-2 flex-shrink-0 rounded-full ${g.dot}`,"aria-hidden":!0}),e.jsx("span",{className:"flex-1 truncate",children:x(o)}),h&&e.jsx(ce,{className:"h-3.5 w-3.5 flex-shrink-0 text-gray-500 dark:text-gray-400",strokeWidth:2.5})]},o)})}),document.body):null;return e.jsxs(e.Fragment,{children:[M,e.jsxs("button",{ref:S,type:"button",disabled:u||i,"aria-label":O,"aria-haspopup":"listbox","aria-expanded":p,onClick:v,className:`inline-flex min-w-[132px] items-center gap-2 rounded-full border px-3 py-1.5 text-xs font-semibold shadow-sm transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 disabled:cursor-not-allowed disabled:opacity-60 ${k.trigger}`,children:[e.jsx("span",{className:`h-2 w-2 flex-shrink-0 rounded-full ${k.dot}`,"aria-hidden":!0}),e.jsx("span",{className:"flex-1 truncate text-left",children:x(t)}),i?e.jsx(Ne,{className:"h-3.5 w-3.5 flex-shrink-0 animate-spin opacity-70"}):e.jsx(pe,{className:`h-3.5 w-3.5 flex-shrink-0 opacity-60 transition-transform ${p?"rotate-180":""}`,strokeWidth:2.5})]})]})},L=25,j="cursor-pointer select-none hover:text-gray-700 dark:hover:text-gray-200 transition-colors",Q=(t,u,i)=>{const l=i==="asc",x=!1;switch(u){case"date":return t.order("created_at",{ascending:l});case"reporter":return t.order("reporter_name",{ascending:l,nullsFirst:x});case"role":return t.order("user_role",{ascending:l,nullsFirst:x});case"outputType":return t.order("output_type",{ascending:l});case"category":return t.order("report_category",{ascending:l});case"comment":return t.order("report_comment_text",{ascending:l});case"status":return t.order("report_status",{ascending:l});case"adminNote":return t.order("admin_note",{ascending:l,nullsFirst:x});case"language":return t.order("language",{ascending:l,nullsFirst:x});default:return t.order("created_at",{ascending:!1})}},q="report_id, created_at, user_id, reporter_name, reporter_email, user_role, session_id, output_type, output_id, report_category, report_comment_text, report_status, admin_note, language",ee=["created_at","reporter_name","reporter_email","user_role","output_type","report_category","report_category_label","report_comment_text","status","status_label","notes","language","session_id","session_results_url","report_id","user_id","output_id"],we=t=>t==null?"":(typeof t=="object"?JSON.stringify(t):String(t)).replace(/"/g,'""'),Ce=t=>`"${we(t)}"`,te=t=>{if(!t)return"â";const u=new Date(t),i=u.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit",year:"2-digit"}),l=u.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});return`${i} ${l}`},Se=(t,u,i,l)=>({created_at:te(t.created_at),reporter_name:t.reporter_name,reporter_email:t.reporter_email,user_role:t.user_role,output_type:t.output_type,report_category:t.report_category,report_category_label:i(t.report_category),report_comment_text:t.report_comment_text,status:t.report_status??"",status_label:l(t.report_status??""),notes:t.admin_note??"",language:t.language,session_id:t.session_id,session_results_url:t.session_id?`${u}/results?sessionId=${t.session_id}`:"",report_id:t.report_id,user_id:t.user_id,output_id:t.output_id}),Re=()=>{const{t}=ge(),u=me(),[i,l]=d.useState([]),[x,O]=d.useState(0),[p,D]=d.useState(1),[y,C]=d.useState(!1),[S,f]=d.useState(null),[N,E]=d.useState(null),[v,P]=d.useState({}),[k,M]=d.useState("date"),[o,h]=d.useState("desc"),g=Math.ceil(x/L),m=r=>{k===r?h(s=>s==="asc"?"desc":"asc"):(M(r),h("asc")),D(1)},b=r=>k!==r?e.jsx(fe,{className:"h-3.5 w-3.5 inline opacity-50 shrink-0"}):o==="asc"?e.jsx(_e,{className:"h-3.5 w-3.5 inline shrink-0"}):e.jsx(ke,{className:"h-3.5 w-3.5 inline shrink-0"}),R=d.useCallback(async r=>{C(!0),f(null);try{const s=(r-1)*L,a=s+L-1;let n=Y.from("report_issues").select(q,{count:"exact"});n=Q(n,k,o);const{data:c,error:w,count:$}=await n.range(s,a);if(w)throw w;const V=c||[];l(V),P(Object.fromEntries(V.map(I=>
6[I.report_id,I.admin_note??""]))),O($??0)}catch(s){console.error("Error fetching reports:",s),f(s instanceof Error?s.message:t("common.error"))}finally{C(!1)}},[k,o,t]);d.useEffect(()=>{R(p)},[R,p]);const A=r=>{r<1||r>g||D(r)},re=async(r,s)=>{E(r),f(null);try{const{error:a}=await F(r,{report_status:s});if(a)throw a;l(n=>n.map(c=>c.report_id===r?{...c,report_status:s}:c))}catch(a){console.error("Error updating report status:",a),f(a instanceof Error?a.message:t("common.error"))}finally{E(null)}},ae=async r=>{const s=i.find(c=>c.report_id===r);if(!s)return;const a=v[r]??"",n=s.admin_note??"";if(a!==n){E(r),f(null);try{const{error:c}=await F(r,{admin_note:a.trim()||null});if(c)throw c;l(w=>w.map($=>$.report_id===r?{...$,admin_note:a.trim()||null}:$))}catch(c){console.error("Error updating report note:",c),f(c instanceof Error?c.message:t("common.error")),P(w=>({...w,[r]:n}))}finally{E(null)}}},U=r=>{r.stopPropagation()},K=d.useCallback(async()=>{const r=i.filter(s=>{const a=v[s.report_id]??"",n=s.admin_note??"";return a!==n});if(r.length!==0){for(const s of r){const a=v[s.report_id]??"",{error:n}=await F(s.report_id,{admin_note:a.trim()||null});if(n)throw n}l(s=>s.map(a=>{const n=v[a.report_id];return n===void 0||n===(a.admin_note??"")?a:{...a,admin_note:n.trim()||null}}))}},[v,i]),se=d.useCallback(async()=>{if(x!==0){C(!0),f(null);try{await K();const r=[];let s=1,a=!0;for(;a;){const _=(s-1)*L,B=_+L-1;let T=Y.from("report_issues").select(q);T=Q(T,k,o);const{data:ne,error:J}=await T.range(_,B);if(J)throw J;const X=ne||[];r.push(...X),a=X.length===L,s++}const n=typeof window<"u"?window.location.origin:"",c=_=>t(`reportIssue.options.${_}`)||_,w=_=>t(`reports.status.${_}`)||_,V=[ee.join(","),...r.map(_=>{const B=Se(_,n,c,w);return ee.map(T=>Ce(B[T])).join(",")})].join(` 7`),I=new Blob(["\uFEFF"+V],{type:"text/csv;charset=utf-8"}),G=URL.createObjectURL(I),z=document.createElement("a");z.href=G,z.download=`reports-export-${new Date().toISOString().slice(0,10)}.csv`,z.click(),URL.revokeObjectURL(G)}catch(r){console.error("Error exporting reports:",r),f(r instanceof Error?r.message:t("common.error"))}finally{C(!1)}}},[K,k,o,t,x]),W=r=>t(`reportIssue.options.${r}`)||r,oe=r=>t(`reports.status.${r}`)||r,H=9;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:[t("reports.totalRecords"),": ",e.jsx("strong",{children:x.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:se,className:"flex items-center gap-2 h-10 px-4 bg-[#036CB4] hover:bg-[#035C99] text-white rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:x===0||y,title:t("buttons.exportCSV")||"Export CSV",children:[e.jsx(ue,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:t("buttons.exportCSV")||"Export CSV"})]}),e.jsxs("button",{type:"button",onClick:()=>R(p),disabled:y,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-medium text-gray-600 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50",children:[e.jsx(xe,{className:`h-4 w-4 ${y?"animate-spin":""}`}),t("reports.reload")||"Reload"]})]})]}),S&&e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl text-red-700 dark:text-red-400",children:[e.jsx(he,{className:"h-5 w-5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:S})]}),e.jsx("div",{className:"bg-white dark:bg-background-dark rounded-xl border border-gray-200 dark:border-gray-800 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50",children:[e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("date"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.date"),b("date")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("reporter"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.reporter"),b("reporter")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("role"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.role"),b("role")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("outputType"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.outputType"),b("outputType")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("category"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.category"),b("category")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("comment"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.comment"),b("comment")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("status"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.status"),b("status")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 min-w-[180px] ${j}`,onClick:()=>m("adminNote"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.adminNote"),b("adminNote")]})}),e.jsx("th",{className:`px-4 py-3 text-left font-semibold text-gray-500 dark:text-gray-400 ${j}`,onClick:()=>m("language"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t("reports.col.language"),b("language")]})})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100 dark:divide-gray-800",children:y&&i.length===0?Array.from({length:5}).map((r,s)=>e.jsx("tr",{children:Array.from({length:H}).map((a,n)=>e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"h-3 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"})},n))}
7,s)):i.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:H,className:"px-4 py-12 text-center text-gray-400 dark:text-gray-600",children:t("reports.empty")})}):i.map(r=>{const s=N===r.report_id;return e.jsxs("tr",{role:"button",tabIndex:0,onClick:()=>r.session_id&&u(`/results?sessionId=${r.session_id}`),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&r.session_id&&(a.preventDefault(),u(`/results?sessionId=${r.session_id}`))},className:`transition-colors ${r.session_id?"hover:bg-gray-50 dark:hover:bg-gray-800/40 cursor-pointer":""}`,children:[e.jsx("td",{className:"px-4 py-3 text-gray-500 dark:text-gray-400 whitespace-nowrap",children:te(r.created_at)}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:r.reporter_name||r.reporter_email||"â"}),r.reporter_email&&r.reporter_name&&e.jsx("p",{className:"text-xs text-gray-400 truncate max-w-[180px]",children:r.reporter_email})]})}),e.jsx("td",{className:"px-4 py-3 text-gray-500 dark:text-gray-400",children:r.user_role||"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"inline-block px-2 py-0.5 rounded text-xs font-medium bg-primary/10 text-primary",children:r.output_type})}),e.jsx("td",{className:"px-4 py-3 text-gray-700 dark:text-gray-300 max-w-[140px]",children:e.jsx("span",{className:"truncate block",title:W(r.report_category),children:W(r.report_category)})}),e.jsx("td",{className:"px-4 py-3 text-gray-600 dark:text-gray-400 max-w-[200px]",children:e.jsx("span",{className:"line-clamp-2 block text-xs",title:r.report_comment_text,children:r.report_comment_text})}),e.jsx("td",{className:"px-4 py-3",onClick:U,onKeyDown:U,children:e.jsx(ve,{value:r.report_status,disabled:s,isSaving:s,onChange:a=>re(r.report_id,a),getStatusLabel:a=>oe(a),ariaLabel:t("reports.col.status")})}),e.jsx("td",{className:"px-4 py-3 min-w-[180px]",onClick:U,onKeyDown:U,children:e.jsx("textarea",{value:v[r.report_id]??"",disabled:s,onChange:a=>P(n=>({...n,[r.report_id]:a.target.value})),onBlur:()=>ae(r.report_id),rows:2,placeholder:t("reports.adminNotePlaceholder"),className:"w-full min-w-[160px] rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-2 py-1.5 text-xs text-gray-700 dark:text-gray-200 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-primary/40 disabled:opacity-60 resize-y","aria-label":t("reports.col.adminNote")})}),e.jsx("td",{className:"px-4 py-3 text-gray-500 dark:text-gray-400",children:r.language||"â"})]},r.report_id)})})]})})}),g>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:[t("usage.page")||"Page"," ",p," / ",g]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>A(p-1),disabled:p===1||y,className:"p-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(be,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>A(p+1),disabled:p===g||y,className:"p-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ye,{className:"h-4 w-4"})})]})]})]})};export{Re 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.