1import{i as ae,k as te,r as n,j as e,s as p}from"./index-C3d5HdaJ.js";import{T as re,a as ne,b as F,c as f,d as le,e as d}from"./table-iBAu4hKv.js";import{B as o}from"./badge-6cKDxAgi.js";import{B as g}from"./button-CyyIW425.js";import{I as ie}from"./input-C_x6iAPK.js";import{S as D,a as B,b as L,c as I,d as l}from"./select-D7eq6FpX.js";import{C as q,d as M}from"./card-Bxkn8Tc5.js";import{S as ce}from"./skeleton-DVNKZid6.js";import{S as de,a as oe,b as me,c as xe}from"./sheet-B6RQ-NMd.js";import{T as pe}from"./textarea-CWeufW0t.js";import{u as ue}from"./use-toast-6nnrf216.js";import{r as he}from"./auth-middleware-BBUDSQGR.js";import{E as je}from"./external-link-C1X65lYd.js";import{C as fe}from"./circle-check-big-CMvmJZSL.js";import{T as ge}from"./triangle-alert-CtkPBXk2.js";import{S as X}from"./star-xe0d2NBm.js";import{S as Ne}from"./search-ANSmqA0E.js";import"./utils-DMHpy-pb.js";import"./index-BpWUEdEw.js";import"./index-BdQq_4o_.js";import"./index-CQwetq_Z.js";import"./index-DUj637Is.js";import"./index-DHNTDpsy.js";import"./index-DgrXjUvP.js";import"./index-DF9_By1x.js";import"./index-2w3FiVC_.js";import"./index-CLwbTm7n.js";import"./index-BSiFVAWu.js";import"./index-D59xewy7.js";import"./chevron-down-BrdqvOiA.js";import"./createLucideIcon-DjlMPdEJ.js";import"./check-VuMYuLTB.js";import"./chevron-up-CPsGuAQ-.js";import"./index-Cop17EXO.js";import"./index-BBQhHgVz.js";import"./x-DWZd_TJ9.js";const _e=ae({method:"POST"}).middleware([he]).handler(te("eb0800faebf0d9324db3a7a4c38cefddf53deb20d137e95a172e7dafefd0cad0"));function R({rating:s,max:i=5}){return s==null?e.jsx("span",{className:"text-muted-foreground text-sm",children:"â"}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"flex gap-0.5",children:Array.from({length:i},(P,m)=>e.jsx(X,{className:`h-4 w-4 ${m<Math.round(s)?"fill-yellow-400 text-yellow-400":"text-gray-300"}`},m))}),e.jsxs("span",{className:"text-sm font-medium",children:[s," / ",i]})]})}function ve(s){return s?s.toUpperCase().replace(/./g,i=>String.fromCodePoint(127462+i.charCodeAt(0)-65)):""}function be({review:s,open:i,onOpenChange:P,onUpdated:m,isAdmin:O=!0}){const{toast:N}=ue(),[V,_]=n.useState(!1),[S,u]=n.useState(""),[c,h]=n.useState(!1);if(!s)return null;const x=async r=>{const{data:y}=await p.from("reviews").select("rating_overall").eq("software_id",r).eq("status","approved");if(y&&y.length>0){const C=y.reduce((T,z)=>T+z.rating_overall,0)/y.length;await p.from("softwares").update({avg_rating:Math.round(C*10)/10,review_count:y.length}).eq("id",r)}else await p.from("softwares").update({avg_rating:null,review_count:0}).eq("id",r)},$=async()=>{h(!0),await p.from("reviews").update({status:"approved",updated_at:new Date().toISOString()}).eq("id",s.id),await x(s.software_id),N({title:"Reseña aprobada â",description:"Traduciendo al otro idiomaâ¦"});try{const r=await _e({data:{reviewId:s.id}});N({title:`Traducción lista (${r.translated} campos â ${r.target})`})}catch(r){N({title:"Reseña aprobada, pero falló la traducción",description:r?.message??"",variant:"destructive"})}h(!1),m()},v=async()=>{S.trim()&&(h(!0),await p.from("reviews").update({status:"rejected",rejection_reason:S,updated_at:new Date().toISOString()}).eq("id",s.id),await x(s.software_id),N({title:"Reseña rechazada"}),h(!1),_(!1),u(""),m())},H=async()=>{h(!0),await p.from("reviews").update({status:"pending",updated_at:new Date().toISOString()}).eq("id",s.id),await x(s.software_id),N({title:"Aprobación cancelada"}),h(!1),m()},b=s.review_type==="partner_implementation"?e.jsx(o,{className:"bg-purple-100 text-purple-600 rounded-full text-xs",children:"Partner"}):e.jsx(o,{className:"bg-blue-100 text-[hsl(var(--primary))] rounded-full text-xs",children:"Software"}),U=s.status==="approved"?e.jsx(o,{className:"bg-green-100 text-green-700 rounded-full text-xs",children:"Aprobada"}):s.status==="rejected"?e.jsx(o,{className:"bg-red-100 text-red-600 rounded-full text-xs",children:"Rechazada"}):e.jsx(o,{className:"bg-yellow-100 text-yellow-700 rounded-full text-xs",children:"Pendiente"});return e.jsx(de,{open:i,onOpenChange:r=>{r||(_(!1),u("")),P(r)},children:e.jsxs(oe,{className:"sm:min-w-[720px] overflow-y-auto",children:[e.jsxs(me,{children:[e.jsxs(xe,{className:"flex items-center gap-2 flex-wrap",children:[s.reviewer_name,b,U]}),(s.reviewer_company||s.reviewer_role)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:[s.reviewer_role,s.reviewer_company].filter(
1Boolean).join(" en ")})]}),e.jsxs("div",{className:"mt-6 space-y-6",children:[O&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[s.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx(g,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:$,disabled:c,children:"Aprobar"}),e.jsx(g,{size:"sm",variant:"destructive",onClick:()=>_(!0),disabled:c,children:"Rechazar"})]}),s.status==="approved"&&e.jsx(g,{size:"sm",variant:"outline",onClick:H,disabled:c,children:"Cancelar aprobación"})]}),V&&e.jsxs("div",{className:"space-y-2 p-3 border rounded-lg bg-red-50 border-red-200",children:[e.jsx("p",{className:"text-sm font-medium text-red-700",children:"Motivo del rechazo (obligatorio)"}),e.jsx(pe,{value:S,onChange:r=>u(r.target.value),rows:3}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{size:"sm",variant:"destructive",onClick:v,disabled:!S.trim()||c,children:"Confirmar rechazo"}),e.jsx(g,{size:"sm",variant:"outline",onClick:()=>{_(!1),u("")},children:"Cancelar"})]})]}),s.status==="rejected"&&s.rejection_reason&&e.jsxs("div",{className:"p-3 border rounded-lg bg-red-50 border-red-200",children:[e.jsx("p",{className:"text-sm font-medium text-red-700 mb-1",children:"Motivo del rechazo"}),e.jsx("p",{className:"text-sm text-red-600",children:s.rejection_reason})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Software"}),e.jsxs("div",{className:"flex items-center gap-3",children:[s.softwares?.logo_url&&e.jsx("img",{src:s.softwares.logo_url,alt:"",className:"h-10 w-10 rounded object-contain border"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.softwares?.name??"â"}),s.softwares?.slug&&e.jsxs("a",{href:`/${s.softwares.slug}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary flex items-center gap-1",children:["Ver perfil ",e.jsx(je,{className:"h-3 w-3"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Reviewer"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Nombre:"})," ",s.reviewer_name]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"})," ",s.reviewer_email]}),s.reviewer_company&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Empresa:"})," ",s.reviewer_company]}),s.reviewer_role&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Cargo:"})," ",s.reviewer_role]}),s.company_size&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tamaño empresa:"})," ",s.company_size]}),s.industry&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Industria:"})," ",s.industry]}),s.domains&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"PaÃs:"})," ",ve(s.domains.country_code)," ",s.domains.country_name]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Fecha:"})," ",new Date(s.created_at).toLocaleDateString("es-ES",{day:"numeric",month:"short",year:"numeric"})]})]})]}),e.jsx("div",{className:"flex items-center gap-2 text-sm",children:s.is_verified?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4 text-green-600"}),e.jsx("span",{className:"text-green-700",children:"Email verificado"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"h-4 w-4 text-yellow-600"}),e.jsx("span",{className:"text-yellow-700",children:"Email no verificado"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Calificaciones"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"General"}),e.jsx(R,{rating:s.rating_overall})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Facilidad de uso"}),e.jsx(R,{rating:s.rating_ease_of_use})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Funcionalidades"}),e.jsx(R,{rating:s.rating_features})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Soporte técnico"}),e.jsx(R,{rating:s.rating_support})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Relación calidad-precio"}),e.jsx(R,{rating:s.rating_value})]}),s.review_type==="partner_implementation"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Implementación"}),e.jsx(R,{rating:s.rating_implementation})]})]})]}),s.pros&&e.jsxs("div",{className:"p-3 rounded-lg bg-green-50 border border-green-200",children:[e.jsx("h4",{className:"text-sm font-semibold text-green-800 mb-1",children:"Pros"}),e.jsx("p",{className:"text-sm text-green-700 whitespace-pre-line",children:s.pros})]}),s.cons&&e.jsxs("div",{className:"p-3 rounded-lg bg-red-50 border border-red-200",children:[e.jsx("h4",{className:"text-sm font-semibold text-red-800 mb
1-1",children:"Contras"}),e.jsx("p",{className:"text-sm text-red-700 whitespace-pre-line",children:s.cons})]}),s.description&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Descripción"}),e.jsx("p",{className:"text-sm whitespace-pre-line",children:s.description})]}),s.usage_duration&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Tiempo de uso"}),e.jsx("p",{className:"text-sm",children:s.usage_duration})]})]})]})})}const ye="id, software_id, domain_id, partner_id, reviewer_name, reviewer_company, reviewer_role, company_size, industry, usage_duration, rating_overall, rating_ease_of_use, rating_features, rating_value, rating_support, rating_implementation, description, pros, cons, review_type, source_language, status, is_verified, verified_at, rejection_reason, created_at, updated_at";function Q(s){return s?s.toUpperCase().replace(/./g,i=>String.fromCodePoint(127462+i.charCodeAt(0)-65)):""}const W=20;function ls(){const[s,i]=n.useState([]),[P,m]=n.useState(!0),[O,N]=n.useState([]),[V,_]=n.useState(null),[S,u]=n.useState(!1),[c,h]=n.useState(""),[x,$]=n.useState("all"),[v,H]=n.useState("pending"),[b,U]=n.useState("all"),[r,y]=n.useState("all"),[C,T]=n.useState(0),z=async()=>{m(!0);const[a,t]=await Promise.all([p.from("reviews").select(`${ye}, softwares(id, name, slug, logo_url), domains(country_name, country_code)`).order("created_at",{ascending:!1}),p.from("domains").select("id, country_name, country_code").eq("is_active",!0).order("country_name")]),j=a.data??[],A=new Map;for(let w=0;w<j.length;w+=500){const ee=j.slice(w,w+500).map(E=>E.id),{data:se}=await p.rpc("review_private_fields",{_ids:ee});for(const E of se??[])A.set(E.id,E.reviewer_email??"")}i(j.map(w=>({...w,reviewer_email:A.get(w.id)??""}))),N(t.data??[]),m(!1)};n.useEffect(()=>{z()},[]);const G=n.useMemo(()=>{let a=s;if(x!=="all"&&(a=a.filter(t=>t.review_type===x)),v!=="all"&&(a=a.filter(t=>t.status===v)),b!=="all"&&(a=a.filter(t=>t.domains?.country_code===b)),r==="5"?a=a.filter(t=>t.rating_overall===5):r==="4+"?a=a.filter(t=>t.rating_overall>=4):r==="3+"?a=a.filter(t=>t.rating_overall>=3):r==="<3"&&(a=a.filter(t=>t.rating_overall<3)),c.trim()){const t=c.toLowerCase();a=a.filter(j=>j.reviewer_name.toLowerCase().includes(t)||j.reviewer_email.toLowerCase().includes(t)||(j.reviewer_company??"").toLowerCase().includes(t))}return a},[s,x,v,b,r,c]),Z=Math.ceil(G.length/W),J=G.slice(C*W,(C+1)*W);n.useEffect(()=>{T(0)},[x,v,b,r,c]);const k=n.useMemo(()=>({total:s.length,pending:s.filter(a=>a.status==="pending").length,approved:s.filter(a=>a.status==="approved").length,rejected:s.filter(a=>a.status==="rejected").length}),[s]),K=a=>{_(a),u(!0)},Y=()=>{u(!1),_(null),z()};return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Reseñas"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-6",children:[e.jsx(q,{children:e.jsxs(M,{className:"pt-4 pb-3 px-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total"}),e.jsx("p",{className:"text-2xl font-bold",children:k.total})]})}),e.jsx(q,{children:e.jsxs(M,{className:"pt-4 pb-3 px-4",children:[e.jsx("p",{className:"text-sm text-yellow-700",children:"Pendientes"}),e.jsx("p",{className:"text-2xl font-bold text-yellow-700",children:k.pending})]})}),e.jsx(q,{children:e.jsxs(M,{className:"pt-4 pb-3 px-4",children:[e.jsx("p",{className:"text-sm text-green-700",children:"Aprobadas"}),e.jsx("p",{className:"text-2xl font-bold text-green-700",children:k.approved})]})}),e.jsx(q,{children:e.jsxs(M,{className:"pt-4 pb-3 px-4",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Rechazadas"}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:k.rejected})]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Ne,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"Buscar por nombre, email o empresa...",value:c,onChange:a=>h(a.target.value),className:"pl-9"})]}),e.jsxs(D,{value:x,onValueChange:$,children:[e.jsx(B,{className:"w-[150px]",children:e.jsx(L,{placeholder:"Tipo"})}),e.jsxs(I,{children:[e.jsx(l,{value:"all",children:"Todas"}),e.jsx(l,{value:"software",children:"Software"}),e.jsx(l,{value:"partner_implementation",children:"Partner"})]})]}),e.jsxs(D,{value:v,onValueChange:H,children:[e.jsx(B,{className:"w-[150px]",children:e.jsx(L,{placeholder:"Estado"})}),e.jsxs(I,{children:[e.jsx(l,{value:"all",children:"Todas"}),e.jsx(l,{value:"pending",children:"Pendientes"}),e.jsx(l,{value:"approved",children:"Aprobadas"}),e.jsx(l,{value:"rejected",children:"Rechazadas"})]})]}),e.jsxs(D,{value:b,onValueChange:U,children:[e.jsx(B,{className:"w-[180px]",children:e.jsx(L,{placeholder:"PaÃs"})}),e.jsxs(I,{children:[e.jsx(l,{value:"all",children:"Todos los paÃses"}),O.map(a=>e.jsxs(l,{value:a.country_code,children:[Q(a.country_code)," ",a.country_name]},a.id))]})]}),e.jsxs(D,{value:r,onValueChange:y,children:[e.jsx(B,{className:"w-[140px]",children:e.jsx(L,{placeholder:"Rating"})}),e.jsxs(I,{children:[e.jsx(l,{value:"all",children:"Todos"}),e.jsx(l,{value:"5",children:"5 estrellas"}),e.jsx(l,{value:"4+",children:"4+"}),e.jsx(l,{value:"3+",children:"3+"}),e.jsx(l,{value:"<3",children:"Menor a 3"})]})]})]}),e.jsx("div",{className:"border rounded-lg",children:e.jsxs(re,{children:[e.jsx(ne,{children:e.jsxs(F,{children:[e.jsx(f,{children:"Tipo"}),e.jsx(f,{children:"Software"}),e.jsx(f,{children:"Reviewer"}),e.jsx(f,{children:"Rating"}),e.jsx(f,{children:"PaÃs"}),e.jsx(f,{children:"Estado"}),e.jsx(f,{children:"Fecha"}),e.jsx(f,{children:"Acciones"})]})}),e.jsx(le,{children:P?Array.from({length:5}).map((a,t)=>e.jsx(F,{children:Array.from({length:8}).map((j,A)=>e.jsx(d,{children:e.jsx(ce,{className:"h-4 w-full"})},A))},t)):J.length===0?e.jsx(F,{children:e.jsx(d,{colSpan:8,className:"text-center text-muted-foreground py-8",children:"Sin reseñas"})}):J.map(a=>e.jsxs(F,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>K(a),children:[e.jsx(d,{children:a.review_type==="partner_implementation"?e.jsx(o,{variant:"secondary",className:"text-xs",children:"Partner"}):e.jsx(o,{className:"text-xs",children:"Software"})}),e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[a.softw
1ares?.logo_url&&e.jsx("img",{src:a.softwares.logo_url,alt:"",className:"h-6 w-6 rounded object-contain"}),e.jsx("span",{className:"text-sm",children:a.softwares?.name??"â"})]})}),e.jsxs(d,{children:[e.jsx("p",{className:"text-sm font-medium",children:a.reviewer_name}),a.reviewer_company&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.reviewer_company})]}),e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(X,{className:"h-3.5 w-3.5 fill-yellow-400 text-yellow-400"}),e.jsx("span",{className:"text-sm",children:a.rating_overall})]})}),e.jsx(d,{className:"text-sm",children:a.domains?`${Q(a.domains.country_code)} ${a.domains.country_name}`:"â"}),e.jsx(d,{children:a.status==="approved"?e.jsx(o,{className:"bg-green-600 hover:bg-green-700 text-xs",children:"Aprobada"}):a.status==="rejected"?e.jsx(o,{variant:"destructive",className:"text-xs",children:"Rechazada"}):e.jsx(o,{variant:"outline",className:"text-xs",children:"Pendiente"})}),e.jsx(d,{className:"text-sm text-muted-foreground",children:new Date(a.created_at).toLocaleDateString("es-ES",{day:"numeric",month:"short",year:"numeric"})}),e.jsx(d,{children:e.jsx(g,{size:"sm",variant:"outline",onClick:t=>{t.stopPropagation(),K(a)},children:"Ver"})})]},a.id))})]})}),Z>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[G.length," reseñas"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(g,{size:"sm",variant:"outline",disabled:C===0,onClick:()=>T(a=>a-1),children:"Anterior"}),e.jsx(g,{size:"sm",variant:"outline",disabled:C>=Z-1,onClick:()=>T(a=>a+1),children:"Siguiente"})]})]}),e.jsx(be,{review:V,open:S,onOpenChange:u,onUpdated:Y})]})}
1export{ls as component};
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.