1import{j as t,r as E}from"./vendor-react-laEpRAYK.js";import{u as M}from"./vendor-query-DcdIi559.js";import{L as p}from"./vendor-router-DYxBvg43.js";import{a as I,b as C,bu as O,c as A,bG as F,H,b2 as T,F as W,_ as G,s as N}from"./index-CdVT36Rl.js";import{B as J}from"./BreadcrumbJsonLd-Dsh7wOt9.js";import{D as w}from"./hubs.config-CRVov-TF.js";import{m as k}from"./vendor-motion-aCppnIeO.js";import{_ as f,a4 as R,a5 as $,a6 as _,G as Q,a7 as V,a8 as z,y as K,W as U,j as Y}from"./vendor-icons-BrcIIWvK.js";import"./vendor-pdf-Dvu_SL5_.js";import"./vendor-radix-CCEge6f_.js";import"./utils-B8VeSWBZ.js";import"./vendor-supabase-BoBgOU0W.js";import"./vendor-dates-Di6Qw362.js";import"./vendor-carousel-UBN6M1Fg.js";import"./vendor-forms-jNas-3k8.js";import"./vendor-charts-BSAJ30E_.js";function b(i,r){if(i.startsWith("http://")||i.startsWith("https://")||!r)return i;const d=r.replace(/\/+$/,""),m=i.startsWith("/")?i:`/${i}`;return`${d}${m}`}function X({listName:i,listDescription:r,items:d,itemType:m="ListItem",baseUrl:c}){if(!d||d.length===0)return null;const u={"@context":"https://schema.org","@type":"ItemList",name:i,...r&&{description:r},numberOfItems:d.length,itemListElement:d.map((o,g)=>({"@type":"ListItem",position:o.position??g+1,...m==="ListItem"?{url:b(o.url,c),name:o.name,...o.image&&{image:o.image}}:{item:{"@type":m,"@id":b(o.url,c),name:o.name,url:b(o.url,c),...o.image&&{image:o.image},...o.description&&{description:o.description}}}}))};return t.jsx(I,{children:t.jsx("script",{type:"application/ld+json",children:JSON.stringify(u)})})}const S={bestsellers:Y,"most-visited":U,"top-rated":K,"new-arrivals":z,"on-sale":V,gifts:Q,"under-30":_,"under-50":_,beginners:$,trending:R};function x(i){const r=Number(i?.price??0);return Number.isFinite(r)?r:0}function Z(i){const r=Number(i?.originalPrice??i?.original_price??0),d=x(i);return r>d&&d>0}function ee(i){const r=i?.createdAt??i?.created_at??i?.published_at,d=r?new Date(r).getTime():0;return Number.isFinite(d)?d:0}function fe({kind:i}){const r=w.find(s=>s.kind===i),{brandId:d,brand:m}=C(),c=m?.name||d,u=G(d),{data:o=[],isLoading:g}=O(),y=i==="most-visited"||i==="trending",j=i==="top-rated",{data:l}=M({queryKey:["discovery-hub-ranking",u,i],enabled:y||j,queryFn:async()=>{if(y){const{data:s}=await N.from("product_analytics").select("product_id, views").eq("brand_id",u).order("views",{ascending:!1}).limit(80);return new Map((s??[]).map(e=>[e.product_id,e.views??0]))}if(j){const{data:s}=await N.from("product_reviews").select("product_id, rating").eq("brand_id",u).eq("status","approved"),e=new Map;return(s??[]).forEach(a=>{const n=e.get(a.product_id)??{sum:0,n:0};n.sum+=Number(a.rating||0),n.n+=1,e.set(a.product_id,n)}),e}return null},staleTime:5*60*1e3}),h=E.useMemo(()=>{if(!o.length)return[];const s=[...o];switch(i){case"bestsellers":return s.map(e=>{const a=(e.tags||[]).join(" ").toLowerCase(),n=(e.isBestSeller?5:0)+(/bestseller|vendido|top|estrella/.test(a)?3:0)+(x(e)>0?1:0);return{p:e,score:n}}).sort((e,a)=>a.score-e.score||e.p.name.localeCompare(a.p.name)).slice(0,24).map(e=>e.p);case"most-visited":if(l instanceof Map)return s.map(e=>({p:e,views:l.get(e.id)??0})).sort((e,a)=>a.views-e.views).slice(0,24).map(e=>e.p);break;case"top-rated":if(l instanceof Map){const e=l;return s.map(a=>{const n=e.get(a.id),P=n&&n.n>=3?n.sum/n.n:0;return{p:a,avg:P,n:n?.n??0}}).filter(a=>a.avg>=4.5).sort((a,n)=>n.avg-a.avg||n.n-a.n).slice(0,24).map(a=>a.p)}break;case"new-arrivals":return s.map(e=>({p:e,t:ee(e)})).sort((e,a)=>a.t-e.t).slice(0,24).map(e=>e.p);case"on-sale":return s.filter(Z).slice(0,24);case"gifts":{const e=/(regalo|kit|set|pack|edici[oó]n|gift)/i;return s.filter(a=>e.test((a.tags||[]).join(" ")+" "+a.name)).slice(0,24)}case"under-30":return s.filter(e=>x(e)>0&&x(e)<30).slice(0,30);case"under-50":return s.filter(e=>x(e)>0&&x(e)<50).slice(0,30);case"beginners":{const e=/(iniciac|principiante|b[aá]sico|esencial|starter|imprescind)/i;return s.filter(n=>e.test((n.tags||[]).join(" ")+" "+n.name)||n.isBestSeller).slice(0,18)}case"trending":if(l instanceof Map)return s.map(e=>({p:e,views:l.get(e.id)??0})).filter(e=>e.views>0).sort((e,a)=>a.views-e.views).slice(0,20).map(e=>e.p);break}return s.sort((e,a)=>(a.isBestSeller?1:0)-(e.isBestSeller?1:0)||e.name.localeCompare(a.name)).slice(0,24)},[o,i,l]);
1A({type:"list",brandName:c,title:r.title,description:r.description,pathname:r.path});const L=S[i],q=[{name:c,url:"/"},{name:"Descubre",url:"/descubre"},{name:r.heading,url:r.path}],B=h.slice(0,20).map((s,e)=>({name:s.name,url:F(s),image:s.image,position:e+1,description:s.shortDescription||s.description?.slice(0,140)})),D={"@context":"https://schema.org","@type":"FAQPage",mainEntity:r.faq.map(s=>({"@type":"Question",name:s.q,acceptedAnswer:{"@type":"Answer",text:s.a}}))},v=w.filter(s=>s.kind!==i);return t.jsxs("div",{className:"min-h-dvh flex flex-col bg-background",children:[t.jsx(H,{}),t.jsx(J,{items:q}),t.jsx(X,{listName:r.heading,listDescription:r.description,items:B,itemType:"Product"}),t.jsx(I,{children:t.jsx("script",{type:"application/ld+json",children:JSON.stringify(D)})}),t.jsxs("main",{id:"main-content",className:"flex-1",children:[t.jsx("section",{className:"border-b border-border/60",children:t.jsx("div",{className:"container max-w-5xl mx-auto px-4 py-14 md:py-20",children:t.jsxs(k.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.5},children:[t.jsxs("nav",{"aria-label":"Breadcrumb",className:"text-xs text-muted-foreground mb-5 flex items-center gap-1.5 flex-wrap",children:[t.jsx(p,{to:"/",className:"hover:text-foreground",children:c}),t.jsx(f,{className:"h-3 w-3"}),t.jsx(p,{to:"/descubre",className:"hover:text-foreground",children:"Descubre"}),t.jsx(f,{className:"h-3 w-3"}),t.jsx("span",{className:"text-foreground",children:r.heading})]}),t.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 rounded-full bg-primary/10 text-primary text-xs font-semibold uppercase tracking-wider mb-4",children:[t.jsx(L,{className:"h-3.5 w-3.5"}),r.eyebrow]}),t.jsx("h1",{className:"font-display text-4xl md:text-6xl font-medium text-foreground leading-tight tracking-tight",children:r.heading}),t.jsx("p",{className:"mt-5 text-lg text-muted-foreground max-w-2xl leading-relaxed",children:r.intro}),t.jsxs("div",{className:"mt-7 flex flex-wrap gap-2",children:[v.slice(0,5).map(s=>t.jsxs(p,{to:s.path,className:"inline-flex items-center gap-1.5 px-3.5 py-1.5 rounded-full border border-border hover:border-primary/50 text-sm text-foreground hover:bg-primary/5 transition-colors",children:[s.heading,t.jsx(f,{className:"h-3.5 w-3.5"})]},s.kind)),t.jsx(p,{to:"/descubre",className:"inline-flex items-center gap-1.5 px-3.5 py-1.5 rounded-full bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors",children:"Ver todos los rankings"})]})]})})}),t.jsx("section",{className:"container max-w-5xl mx-auto px-4 py-10 md:py-14",children:g?t.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:Array.from({length:8}).map((s,e)=>t.jsx("div",{className:"aspect-[3/4] rounded-2xl bg-muted/40 animate-pulse"},e))}):h.length===0?t.jsxs("div",{className:"text-center py-20 text-muted-foreground",children:[t.jsx("p",{className:"mb-4",children:"Aún no hay suficientes datos para este ranking."}),t.jsx(p,{to:"/productos",className:"text-primary hover:underline font-medium",children:"Ver todo el catálogo â"})]}):t.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 md:gap-5",children:h.map((s,e)=>t.jsxs(k.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:Math.min(e*.02,.3)},className:"relative",children:[e<3&&t.jsx("span",{className:"absolute -top-2 -left-2 z-10 inline-flex items-center justify-center w-8 h-8 rounded-full bg-primary text-primary-foreground text-sm font-semibold shadow-lg",children:e+1}),t.jsx(T,{product:s})]},s.id))})}),r.editorial.length>0&&t.jsx("section",{className:"border-t border-border/60 bg-muted/20",children:t.jsxs("div",{className:"container max-w-3xl mx-auto px-4 py-14 md:py-20",children:[t.jsx("h2",{className:"font-display text-3xl md:text-4xl text-foreground mb-8",children:"Sobre este ranking"}),t.jsx("div",{className:"space-y-8",children:r.editorial.map(s=>t.jsxs("div",{children:[t.jsx("h3",{className:"font-display text-xl md:text-2xl text-foreground mb-3",children:s.heading}),t.jsx("p",{className:"text-base text-muted-foreground leading-relaxed",children:s.body})]},s.heading))})]})}),r.faq.length>0&&t.jsx("section",{className:"border-t border-border/60",children:t.jsxs("div",{className:"container max-w-3xl mx-auto px-4 py-14 md:py-20",children:[t.jsx("h2",{className:"font-display text-3xl md:text-4xl text-foreground mb-8",children:"Preguntas frecuentes"}),t.jsx("div",{className:"space-y-3",children:r.faq.map(s=>t.jsxs("details",{className:"group border border-border rounded-xl p-5 bg-background hover:border-primary/40 transition-colors",children:[t.jsxs("summary",{className:"cursor-pointer font-medium text-foreground flex justify-between items-center gap-4 list-none",children:[t.jsx("span",{children:s.q}),t.jsx("span",{className:"text-primary text-2xl leading-none group-open:rotate-45 transition-transform",children:"+"})]}),t.jsx("p",{className:"mt-3 text-muted-foreground leading-relaxed",children:s.a})]},s.q))})]})}),t.jsx("section",{className:"border-t border-border/60 bg-muted/20",children:t.jsxs("div",{className:"container max-w-5xl mx-auto px-4 py-14 md:py-20",children:[t.jsx("h2",{className:"font-display text-3xl md:text-4xl text-foreground mb-3",children:"Más formas de descubrir"}),t.jsx("p",{className:"text-muted-foreground mb-8",children:"Explora todos los rankings y listados curados del catálogo."}),t.jsx("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-3",children:v.map(s=>{const e=S[s.kind];return t.jsxs(p,{to:s.path,className:"group flex items-start gap-3 p-5 rounded-xl border border-border hover:border-primary/50 hover:bg-background transition-colors",children:[t.jsx(e,{className:"h-5 w-5 text-primary mt-0.5 shrink-0"}),t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-foreground group-hover:text-primary",children:s.heading}),t.jsx("div",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:r.kind===s.kind?"":s.intro})]})]},s.kind)})})]})})]}),t.jsx(W,{})]})}
1export{fe as DiscoveryHub};
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.