1import{a as Y,u as g,b as Z,j as e}from"./vendor-query-skQMsM6X.js";import{r as x}from"./vendor-react-DyYvSSk1.js";import{b as d,aJ as ee,r as T,v as E,x as k,y as F,z as o,at as z,ax as P,ab as i,aR as se,p as c,am as ae,an as te,ao as re,ap as ie,aq as h,c as _}from"./index-BGwtrXIa.js";import{T as ne}from"./textarea-ChvLdc2s.js";import{bG as le,bt as oe,br as de,bg as ce,i as ue,X as Q,af as me,o as xe,a as he,C as pe,v as je}from"./vendor-ui-CCmu0bzQ.js";import{p as ge}from"./pt-BR-0bEujIJO.js";import"./vendor-supabase-BfoV2C50.js";const D={pending:{label:"Pendente",color:"bg-amber-500/20 text-amber-600 border-amber-500/30",icon:xe},in_review:{label:"Em análise",color:"bg-blue-500/20 text-blue-500 border-blue-500/30",icon:he},resolved:{label:"Resolvido",color:"bg-emerald-500/20 text-emerald-600 border-emerald-500/30",icon:pe},dismissed:{label:"Descartado",color:"bg-muted text-muted-foreground border-border",icon:je}},O={gabarito_incorreto:"Gabarito incorreto",erro_portugues:"Erro de português",enunciado_incompleto:"Enunciado incompleto",discordancia_resposta:"Discordância",imagem_ausente:"Imagem ausente",outro:"Outro"},A=20;function qe(){const L=Y(),[f,W]=x.useState("all"),[v,G]=x.useState("all"),[u,b]=x.useState(0),[s,y]=x.useState(null),[I,N]=x.useState(""),[K,w]=x.useState(""),{data:m,isLoading:H}=g({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["question-reports",f,v,u],queryFn:async()=>{let a=d.from("question_reports").select("*",{count:"exact"}).order("created_at",{ascending:!1}).range(u*A,(u+1)*A-1);f!=="all"&&(a=a.eq("status",f)),v!=="all"&&(a=a.eq("report_type",v));const{data:t,error:r,count:l}=await a;if(r)throw r;return{reports:t,total:l||0}}}),M=(m==null?void 0:m.reports)||[],R=(m==null?void 0:m.total)||0,q=Math.ceil(R/A),{data:p}=g({queryKey:["question-reports-counters"],queryFn:async()=>{const{data:a,error:t}=await d.from("question_reports").select("status");if(t)throw t;const r=a;return{total:r.length,pending:r.filter(l=>l.status==="pending").length,in_review:r.filter(l=>l.status==="in_review").length,resolved:r.filter(l=>l.status==="resolved").length}},staleTime:3e4}),{data:$}=g({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["reporter-profile",s==null?void 0:s.user_id],queryFn:async()=>{if(!(s!=null&&s.user_id))return null;const{data:a}
1=await d.from("profiles").select("full_name").eq("id",s.user_id).maybeSingle();return a},enabled:!!(s!=null&&s.user_id)}),{data:n}=g({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["report-card",s==null?void 0:s.card_id],queryFn:async()=>{if(!(s!=null&&s.card_id))return null;const{data:a}=await d.from("frases_modelo").select("id, titulo, codigo, categoria, modalidade_codigo").eq("id",s.card_id).maybeSingle();return a},enabled:!!(s!=null&&s.card_id)}),{data:j}=g({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["report-question",s==null?void 0:s.question_id],queryFn:async()=>{if(!(s!=null&&s.question_id))return null;const{data:a}=await d.from("cbr_exam_questions").select("id, exam_year, question_number, enunciado").eq("id",s.question_id).maybeSingle();return a},enabled:!!(s!=null&&s.question_id)}),S=async(a,t)=>{try{await navigator.clipboard.writeText(a),_.success(`${t} copiado`)}catch{_.error("Falha ao copiar")}},C=Z({mutationFn:async({id:a,status:t,response:r})=>{var U;const{data:{user:l}}=await d.auth.getUser(),{error:B}=await d.from("question_reports").update({status:t,admin_response:r||null,resolved_by:l==null?void 0:l.id,resolved_at:new Date().toISOString(),updated_at:new Date().toISOString()}).eq("id",a);if(B)throw B;if(s!=null&&s.user_id){const V=s.question_number?`Q${s.question_number}`:"questão",X=((U=D[t])==null?void 0:U.label)||t,J=r.trim()?`Seu reporte sobre ${V} foi analisado: ${r.slice(0,200)}`:`Seu reporte sobre ${V} foi atualizado para: ${X}`;await d.from("user_notifications").insert({user_id:s.user_id,type:"question_report",title:"Reporte atualizado",message:J})}},onSuccess:()=>{_.success("Reporte atualizado e usuário notificado!"),L.invalidateQueries({queryKey:["question-reports"]}),L.invalidateQueries({queryKey:["question-reports-counters"]}),y(null),N(""),w("")},onError:()=>_.error("Erro ao atualizar reporte.")});return e.jsxs(ee,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{className:"h-6 w-6 text-amber-500"}),e.jsx("h1",{className:"text-2xl font-bold font-mono",children:"Reportes de Questões"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(T,{value:v,onValueChange:a=>{G(a),b(0)},children:[e.jsx(E,{className:"w-full sm:w-44",children:e.jsx(k,{placeholder:"Tipo"})}),e.jsxs(F,{children:[e.jsx(o,{value:"all",children:"Todos os tipos"}),Object.entries(O).map(([a,t])=>e.jsx(o,{value:a,children:t},a))]})]}),e.jsxs(T,{value:f,onValueChange:a=>{W(a),b(0)},children:[e.jsx(E,{className:"w-full sm:w-40",children:e.jsx(k,{})}),e.jsxs(F,{children:[e.jsx(o,{value:"all",children:"Todos"}),e.jsx(o,{value:"pending",children:"Pendentes"}),e.jsx(o,{value:"in_review",children:"Em análise"}),e.jsx(o,{value:"resolved",children:"Resolvidos"}),e.jsx(o,{value:"dismissed",children:"Descartados"})]})]})]})]}),p&&e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[{label:"Total",value:p.total,color:"text-foreground"},{label:"Pendentes",value:p.pending,color:"text-amber-500"},{label:"Em análise",value:p.in_review,color:"text-blue-500"},{label:"Resolvidos",value:p.resolved,color:"text-emerald-500"}].map(a=>e.jsx(z,{children:e.jsxs(P,{className:"p-4 text-center",children:[e.jsx("p",{className:`text-2xl font-bold ${a.color}`,children:a.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.label})]})},a.label))}),H?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Carregando..."}):M.length===0?e.jsx(z,{children:e.jsx(P,{className:"py-12 text-center text-muted-foreground",children:"Nenhum reporte encontrado."})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-3",children:M.map(a=>{const t=D[a.status]||D.pending,r=t.icon;return e.jsx(z,{className:"hover:border-muted-foreground/30 transition-colors cursor-pointer",onClick:()=>{y(a),N(a.admin_response||""),w(a.status)},children:e.jsx(P,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsxs(i,{className:t.color,children:[e.jsx(r,{className:"h-3 w-3 mr-1"}),t.label]}),e.jsx(i,{variant:"outline",className:"text-xs",children:O[a.report_type]||a.report_type}),a.exam_year&&e.jsx(i,{variant:"outline",className:"text-xs",children:a.exam_year}),a.question_number&&e.jsxs(i,{variant:"outline",className:"text-xs",children:["Q",a.question_number]})]}),e.jsx("p",{className:"text-sm line-clamp-2 mt-1",children:a.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:se(new Date(a.created_at),"dd/MM/yyyy HH:mm",{locale:ge})})]}),a.admin_response&&e.jsx(oe,{className:"h-4 w-4 text-muted-foreground flex-shrink-0 mt-1"})]})})},a.id)})}),q>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 pt-2",children:[e.jsx(c,{variant:"outline",size:"sm",disabled:u===0,onClick:()=>b(a=>a-1),children:e.jsx(de,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[u+1," de ",q]}),e.jsx(c,{variant:"outline",size:"sm",disabled:u>=q-1,onClick:()=>b(a=>a+1),children:e.jsx(ce,{className:"h-4 w-4"})})]})]})]}),e.jsx(ae,{open:!!s,onOpenChange:a=>!a&&y(null),children:e.jsxs(te,{className:"sm:max-w-xl max-h-[90vh] overflow-y-auto",children:[e.jsx(re,{children:e.jsx(ie,{children:"Detalhes do Reporte"})}),s&&(()=>{const a=!!(s.card_id||s.question_id);return e.jsxs("div",{className:"space-y-4",children:[$&&e.jsx("div",{className:"text-sm text-muted-foreground bg-muted/30 rounded p-2",children:e.jsx("span",{className:"font-medium text-foreground",children:$.full_name||"Usuário"})}),e.jsxs("div",{className:"rounded border border-border bg-muted/20 p-3 space-y-2",children:[e.jsx(h,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Localização no banco"}),!a&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-amber-600 bg-amber-500/10 border border-amber-500/30 rounded p-2",children:[e.jsx(ue,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}
1),e.jsx("span",{children:"Reporte sem contexto capturado (versão antiga do app). Use o trecho abaixo para localizar manualmente."})]}),n&&e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:n.titulo}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.codigo&&e.jsx(i,{variant:"secondary",children:n.codigo}),n.categoria&&e.jsx(i,{variant:"outline",children:n.categoria}),n.modalidade_codigo&&e.jsx(i,{variant:"outline",children:n.modalidade_codigo})]})]}),j&&e.jsx("div",{className:"space-y-1 text-sm",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[j.exam_year&&e.jsxs(i,{variant:"secondary",children:["CBR ",j.exam_year]}),j.question_number&&e.jsxs(i,{variant:"outline",children:["Q",j.question_number]})]})}),s.card_id&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"card_id:"}),e.jsx("code",{className:"bg-background px-1.5 py-0.5 rounded text-[10px] break-all",children:s.card_id}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-6 px-1.5",onClick:()=>S(s.card_id,"card_id"),children:e.jsx(Q,{className:"h-3 w-3"})})]}),s.question_id&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"question_id:"}),e.jsx("code",{className:"bg-background px-1.5 py-0.5 rounded text-[10px] break-all",children:s.question_id}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-6 px-1.5",onClick:()=>S(s.question_id,"question_id"),children:e.jsx(Q,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:"/admin/frases",target:"_blank",rel:"noreferrer",children:[e.jsx(me,{className:"h-3 w-3 mr-1"})," Abrir Frases"]})}),s.question_preview&&e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>S(s.question_preview,"Trecho"),children:[e.jsx(Q,{className:"h-3 w-3 mr-1"})," Copiar trecho"]})]}),(s.exam_type||s.exam_year||s.question_number)&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 pt-1",children:[s.exam_type&&e.jsx(i,{variant:"outline",children:s.exam_type}),s.exam_year&&e.jsx(i,{variant:"outline",children:s.exam_year}),s.question_number&&e.jsxs(i,{variant:"outline",children:["Q",s.question_number]}),s.categoria&&!(n!=null&&n.categoria)&&e.jsx(i,{variant:"outline",children:s.categoria})]})]}),s.question_preview&&e.jsxs("div",{children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:"Trecho da questão"}),e.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 mt-1 whitespace-pre-wrap font-sans max-h-40 overflow-y-auto",children:s.question_preview})]}),e.jsxs("div",{children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:"Tipo"}),e.jsx("p",{className:"text-sm font-medium",children:O[s.report_type]||s.report_type})]}),e.jsxs("div",{children:[e.jsx(h,{className:"text-xs text-muted-foreground",children:"Descrição do usuário"}),e.jsx("p",{className:"text-sm bg-muted/30 rounded p-3 mt-1",children:s.description})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Status"}),e.jsxs(T,{value:K,onValueChange:w,children:[e.jsx(E,{children:e.jsx(k,{})}),e.jsxs(F,{children:[e.jsx(o,{value:"pending",children:"Pendente"}),e.jsx(o,{value:"in_review",children:"Em análise"}),e.jsx(o,{value:"resolved",children:"Resolvido"}),e.jsx(o,{value:"dismissed",children:"Descartado"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Resposta ao usuário (opcional)"}),e.jsx(ne,{value:I,onChange:t=>N(t.target.value),placeholder:"Escreva a resposta que será enviada como notificação...",rows:3})]}),e.jsx(c,{onClick:()=>C.mutate({id:s.id,status:K,response:I}),disabled:C.isPending,className:"w-full",children:C.isPending?"Salvando...":"Atualizar e Notificar"})]})})()]})})]})}export{qe 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.