1import{r as n,j as e,y as z,z as k,D as M,E as R,G as i,R as p,C as g,e as v,c as D,d as A,g as H,ak as q,f as B,b as u,s as x,H as h,ah as I}from"./index-Dtqe_piS.js";import{L as N}from"./lightbulb-CAwgz7BV.js";import{C as y}from"./circle-check-big-BzOe8M8z.js";import{C}from"./circle-x-Bfq04crG.js";import{C as L}from"./clock-CnPXUHAt.js";const w={pending:{label:"Pendiente",color:"bg-amber-500/10 text-amber-600 border-amber-500/20",icon:L},approved:{label:"Aprobada",color:"bg-green-500/10 text-green-600 border-green-500/20",icon:y},rejected:{label:"Rechazada",color:"bg-red-500/10 text-red-600 border-red-500/20",icon:C},in_progress:{label:"En Desarrollo",color:"bg-blue-500/10 text-blue-600 border-blue-500/20",icon:p}},U=()=>{const[j,f]=n.useState([]),[_,b]=n.useState(!0),[o,S]=n.useState("all"),E=async()=>{b(!0);try{let s=x.from("metric_suggestions").select("*").order("created_at",{ascending:!1});o!=="all"&&(s=s.eq("status",o));const{data:a,error:r}=await s;if(r)throw r;const l=[...new Set((a==null?void 0:a.map(c=>c.user_id))||[])],{data:t}=await x.from("profiles").select("user_id, email").in("user_id",l),m=new Map((t==null?void 0:t.map(c=>[c.user_id,c.email]))||[]);f((a==null?void 0:a.map(c=>({...c,user_email:m.get(c.user_id)||"Usuario desconocido"})))||[])}catch(s){console.error("Error fetching suggestions:",s),h.error("Error al cargar las sugerencias")}finally{b(!1)}};n.useEffect(()=>{E()},[o]);const d=async(s,a)=>{try{const{error:r}=await x.from("metric_suggestions").update({status:a}).eq("id",s);if(r)throw r;f(l=>l.map(t=>t.id===s?{...t,status:a}:t)),h.success("Estado actualizado")}catch(r){console.error("Error updating status:",r),h.error("Error al actualizar el estado")}};return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Sugerencias de Automatizaciones"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Revisa las sugerencias enviadas por los usuarios"})]}),e.jsxs(z,{value:o,onValueChange:S,children:[e.jsx(k,{className:"w-[180px]",children:e.jsx(M,{placeholder:"Filtrar por estado"})}),e.jsxs(R,{children:[e.jsx(i,{value:"all",children:"Todas"}),e.jsx(i,{value:"pending",children:"Pendientes"}),e.jsx(i,{value:"approved",children:"Aprobadas"}),e.jsx(i,{value:"in_progress",children:"En Desarrollo"}),e.jsx(i,{value:"rejected",children:"Rechazadas"})]})]})]}),_?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(p,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):j.length===0?e.jsx(g,{children:e.jsxs(v,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(N,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsxs("p",{className:"text-muted-foreground",children:["No hay sugerencias ",o!=="all"?"con este estado":""]})]})}):e.jsx("div",{className:"grid gap-4",children:j.map(s=>{const a=w[s.status]||w.pending,r=a.icon;return e.jsxs(g,{children:[e.jsx(D,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(N,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(A,{className:"text-base",children:s.user_email}),e.jsx(H,{children:q(new Date(s.created_at),"d 'de' MMMM, yyyy 'a las' HH:mm",{locale:I})})]})]}),e.jsxs(B,{className:a.color,children:[e.jsx(r,{className:"h-3 w-3 mr-1"}),a.label]})]})}),e.jsxs(v,{className:"space-y-4",children:[e.jsx("p",{className:"text-foreground bg-muted/50 p-3 rounded-lg",children:s.suggestion}),s.attachments&&s.attachments.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:s.attachments.map((l,t)=>{const m=/\.(mp4|mov|webm)$/i.test(l);return e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"block w-24 h-24 rounded-lg overflow-hidden border border-border hover:opacity-80 transition-opacity",children:m?e.jsx("video",{src:l,className:"w-full h-full object-cover"}):e.jsx("img",{src:l,alt:"",className:"w-full h-full object-cover"})},t)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>d(s.id,"approved"),disabled:s.status==="approved",children:[e.jsx(y,{className:"h-4 w-4 mr-1"}),"Aprobar"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>d(s.id,"in_progress"),disabled:s.status==="in_progress",children:[e.jsx(p,{className:"h-4 w-4 mr-1"}),"En Desarrollo"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>d(s.id,"rejected"),disabled:s.status==="rejected",children:[e.jsx(C,{className:"h-4 w-4 mr-1"}),"Rechazar"]})]})]})]},s.id)})})]})};export{U 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.