1import{r as B}from"./rolldown-runtime-CXHxssQy.js";import{a as E,c as $,f as _,l as O,t as N}from"./vendor-core-DLV7unHF.js";import{b as D,n as I,r as R}from"./vendor-data-gP-SiX90.js";import{r as M}from"./i18n-BHBA6a-T.js";import{r as z}from"./tracker-B3eq4qtf.js";import{Pt as L,Rn as S,Yt as q,Zn as T,Zt as y,ar as Q,on as P,wt as k}from"./vendor-ui-HbZeGnVr.js";import{t as C}from"./button-BpBAlEZu.js";import{t as U}from"./api-CRGwQGva.js";import{t as H}from"./events-api-CvO6EJ1p.js";import{n as w}from"./slugify-COPcHoH5.js";import{i as V}from"./RecommendationRow-DKG5T0mM.js";import{t as F}from"./Price-DofhS5ms.js";import{n as G,t as K}from"./search-events-BUJQcmsl.js";import{t as Z}from"./Layout-C37Fdnqj.js";import{t as X}from"./Breadcrumb-B6tkjLCO.js";import{t as A}from"./input-C-oqphw0.js";import{t as v}from"./label-rmk_lUq_.js";import{a as Y,i as J,n as W,r as ee,t as f}from"./select-CkGTehtz.js";import{t as se}from"./switch-DaRePIGG.js";import{t as te}from"./SEO-w_hz1TEB.js";import{n as ae,t as re}from"./applyRanking-DFQzvcZS.js";var m=B(_(),1);function ie(){const[r,a]=(0,m.useState)("all"),[s,i]=(0,m.useState)(!1),[l,c]=(0,m.useState)(""),[x,p]=(0,m.useState)(""),[g,t]=(0,m.useState)(!1),[n,d]=(0,m.useState)("relevance");return{selectedCategory:r,setSelectedCategory:a,showFilters:s,setShowFilters:i,minPrice:l,setMinPrice:c,maxPrice:x,setMaxPrice:p,inStockOnly:g,setInStockOnly:t,sortBy:n,setSortBy:d,hasActiveFilters:!!(l||x||g||n!=="relevance"),clearFilters:()=>{c(""),p(""),t(!1),d("relevance"),a("all")}}}function le(r,a){return R({queryKey:["/api/products/search",r,a],queryFn:async()=>{const s=new URLSearchParams;r&&s.append("search",r),a!=="all"&&s.append("category",a),s.append("fields","lite"),s.append("limit","50");const i=await fetch(`/api/products?${s.toString()}`);if(!i.ok)return[];const l=await i.json();return Array.isArray(l)?l:l.products||[]},enabled:r.length>0})}function ce(r,a){return(0,m.useMemo)(()=>{let s=[...r];if(a.selectedCategory!=="all"&&(s=s.filter(i=>i.category?.toLowerCase().includes(a.selectedCategory.toLowerCase()))),a.minPrice){const i=parseFloat(a.minPrice);isNaN(i)||(s=s.filter(l=>parseFloat(l.price)>=i))}if(a.maxPrice){const i=parseFloat(a.maxPrice);isNaN(i)||(s=s.filter(l=>parseFloat(l.price)<=i))}switch(a.inStockOnly&&(s=s.filter(i=>(i.stock??1)>0)),a.sortBy){case"price_asc":s.sort((i,l)=>parseFloat(i.price)-parseFloat(l.price));break;case"price_desc":s.sort((i,l)=>parseFloat(l.price)-parseFloat(i.price));break;case"name_asc":s.sort((i,l)=>i.name.localeCompare(l.name));break;case"name_desc":s.sort((i,l)=>l.name.localeCompare(i.name));break;case"newest":s.sort((i,l)=>{const c=i.createdAt?new Date(i.createdAt).getTime():0;return(l.createdAt?new Date(l.createdAt).getTime():0)-c})}return s},[r,a.selectedCategory,a.minPrice,a.maxPrice,a.inStockOnly,a.sortBy])}function ne(){const r=$();return new URLSearchParams(r).get("q")||""}function oe({query:r,isLoading:a,resultCount:s,filtered:i}){const l=(0,m.useRef)("");(0,m.useEffect)(()=>{const c=K(r);if(!c){l.current="";return}a||l.current===c||(l.current=c,G(c,s,i))},[r,a,s,i])}var e=O();function de({showFilters:r,setShowFilters:a,sortBy:s,setSortBy:i,minPrice:l,setMinPrice:c,maxPrice:x,setMaxPrice:p,inStockOnly:g,setInStockOnly:t,selectedCategory:n,setSelectedCategory:d,categoryFilters:o,hasActiveFilters:j,clearFilters:b,t:h}){return(0,e.jsx)("aside",{className:`md:w-64 flex-shrink-0 ${r?"block":"hidden md:block"}`,children:(0,e.jsxs)("div",{className:"bg-white rounded-xl p-4 shadow-sm space-y-6",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("h3",{className:"font-semibold text-gray-800 flex items-center gap-2",children:[(0,e.jsx)(q,{className:"w-4 h-4"}),h.category.filters]}),(0,e.jsx)("button",{onClick:()=>a(!1),className:"md:hidden",children:(0,e.jsx)(k,{className:"w-5 h-5 text-gray-400"})})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(v,{className:"text-sm font-medium text-gray-700",children:h.search.sortBy}),(0,e.jsxs)(ee,{value:s,onValueChange:u=>i(u),children:[(0,e.jsx)(J,{className:"w-full","data-testid":"select-sort",children:(0,e.jsx)(Y,{})}),(0,e.jsxs)(W,{children:[(0,e.jsx)(f,{value:"relevance",children:h.search.sortRelevance}),(0,e.jsx)(f,{value:"price_asc",children:h.search.sortPriceAsc}),(0,e.jsx)(f,{value:"price_desc",children:h.search.sortPriceDesc}
1),(0,e.jsx)(f,{value:"name_asc",children:h.search.sortNameAsc}),(0,e.jsx)(f,{value:"name_desc",children:h.search.sortNameDesc}),(0,e.jsx)(f,{value:"newest",children:h.search.sortNewest})]})]})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(v,{className:"text-sm font-medium text-gray-700",children:h.search.priceRange}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("div",{className:"flex-1",children:(0,e.jsx)(A,{type:"number",placeholder:h.search.minPrice,value:l,onChange:u=>c(u.target.value),className:"text-sm",min:"0","data-testid":"input-min-price"})}),(0,e.jsx)("span",{className:"text-gray-400",children:"-"}),(0,e.jsx)("div",{className:"flex-1",children:(0,e.jsx)(A,{type:"number",placeholder:h.search.maxPrice,value:x,onChange:u=>p(u.target.value),className:"text-sm",min:"0","data-testid":"input-max-price"})})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-between py-2",children:[(0,e.jsx)(v,{htmlFor:"in-stock",className:"text-sm font-medium text-gray-700 cursor-pointer",children:h.search.inStockOnly}),(0,e.jsx)(se,{id:"in-stock",checked:g,onCheckedChange:t,"data-testid":"switch-in-stock"})]}),(0,e.jsxs)("div",{className:"border-t pt-4",children:[(0,e.jsx)(v,{className:"text-sm font-medium text-gray-700 mb-3 block",children:h.home.categories}),(0,e.jsx)("div",{className:"space-y-1",children:o.map(u=>(0,e.jsx)("button",{onClick:()=>d(u.slug),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${n===u.slug?"bg-[#E85A8B] text-white":"hover:bg-gray-100 text-gray-600"}`,"data-testid":`filter-category-${u.slug}`,children:(0,e.jsxs)("span",{className:"flex items-center gap-2",children:[u.color&&(0,e.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:u.color}}),u.name]})},u.slug))})]}),j&&(0,e.jsxs)(C,{variant:"outline",size:"sm",onClick:b,className:"w-full","data-testid":"button-clear-filters",children:[(0,e.jsx)(k,{className:"w-4 h-4 mr-2"}),h.search.clearFilters]})]})})}function me({products:r,t:a,rankedIds:s=[]}){const i=re(r.slice(0,24),s).concat(r.slice(24)),l=D(),[c,x]=(0,m.useState)(null),p=ae(i.map(t=>t.id)),g=I({mutationFn:t=>U(t,1),retry:!1,onMutate:t=>x(t),onSuccess:()=>{l.invalidateQueries({queryKey:["cart"]})},onSettled:()=>x(null)});return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"sm:hidden flex flex-col gap-3","data-testid":"search-grid-mobile",children:i.map(t=>{const n=t.stock!==void 0&&t.stock<=0,d=c===t.id,o=p[t.id],j=o?.kind==="urgent"?"text-red-600 font-semibold":o?.kind==="novelty"?"text-[#E85A8B] font-semibold":"text-gray-600";return(0,e.jsxs)("div",{className:"relative","data-testid":`search-list-${t.id}`,children:[(0,e.jsxs)(N,{href:w(t.id,t.name),className:"block bg-white rounded-xl border border-gray-100 shadow-sm hover:shadow-md p-3",children:[(0,e.jsxs)("div",{className:"flex gap-3",children:[(0,e.jsxs)("div",{className:"relative flex-shrink-0 w-24 h-24 rounded-lg overflow-hidden bg-gray-50",children:[n&&(0,e.jsx)("span",{className:"absolute top-1 left-1 bg-gray-600 text-white text-[8px] font-bold px-1.5 py-0.5 rounded-full uppercase z-10",children:"Sin stock"}),t.image?(0,e.jsx)("img",{src:t.image,alt:t.name,width:200,height:200,loading:"lazy",className:`w-full h-full object-contain p-2 ${n?"opacity-50 grayscale":""}`}):(0,e.jsx)("div",{className:"w-full h-full flex items-center justify-center",children:(0,e.jsx)(y,{className:"w-8 h-8 text-gray-300"})})]}),(0,e.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-[10px] text-[#E85A8B] uppercase tracking-wider font-bold mb-1 truncate",children:t.category}),(0,e.jsx)("h3",{className:"text-sm font-medium text-gray-900 leading-tight line-clamp-2 mb-1.5",children:t.name}),o?.label&&(0,e.jsx)("p",{className:`text-xs mb-1.5 ${j}`,children:o.label})]}),(0,e.jsx)(F,{value:t.price,regularPrice:t.originalPrice??void 0,size:"lg",className:"text-gray-900"})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-gray-600 mt-3",children:[(0,e.jsx)(L,{className:"w-3.5 h-3.5"}),(0,e.jsx)("span",{children:"EnvÃo discreto 2-3 dÃas · Gratis +60â¬"})]})]}),(0,e.jsxs)("button",{onClick:b=>{b.preventDefault(),b.stopPropagation(),n||g.mutate(t.id)},disabled:d||n,className:`mt-2 w-full flex items-center justify-center gap-2 py-2.5 rounded-lg font-medium text-sm ${n?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-[#E85A8B] text-white hover:bg-[#D14A7B] disabled:opacity-60"}`,children:[d?(0,e.jsx)(S,{className:"w-4 h-4 animate-spin"}):(0,e.jsx)(y,{className:"w-4 h-4"}),n?"Agotado":d?"Añadiendoâ¦":"Añadir al carrito"]})]},t.id)})}),(0,e.jsx)("div",{className:"hidden sm:grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 ga
1p-4","data-testid":"search-grid-desktop",children:i.map(t=>{const n=t.stock!==void 0&&t.stock<=0,d=c===t.id;return(0,e.jsxs)("div",{className:"group relative bg-white rounded-xl overflow-hidden shadow-sm hover:shadow-lg transition-all",children:[(0,e.jsxs)("div",{className:"aspect-square relative overflow-hidden bg-gray-50",children:[t.image?(0,e.jsx)("img",{src:t.image,alt:t.name,width:400,height:400,loading:"lazy",decoding:"async",className:"w-full h-full object-contain group-hover:scale-105 transition-transform duration-300"}):(0,e.jsx)("div",{className:"w-full h-full flex items-center justify-center",children:(0,e.jsx)(y,{className:"w-12 h-12 text-gray-300"})}),n&&(0,e.jsx)("span",{className:"absolute top-2 left-2 bg-gray-500 text-white text-[9px] font-bold px-2 py-0.5 rounded-full uppercase tracking-wider z-10 shadow-sm","data-testid":`out-of-stock-badge-${t.id}`,children:"Sin stock"}),(0,e.jsx)(N,{href:w(t.id,t.name),className:"absolute inset-0 z-0","aria-label":t.name,"data-testid":`search-product-${t.id}`}),(0,e.jsx)("button",{onClick:o=>{o.preventDefault(),o.stopPropagation()},className:"absolute top-2 right-2 w-8 h-8 bg-white/90 rounded-full flex items-center justify-center shadow-sm hover:bg-[#E85A8B] hover:text-white transition-colors z-20","data-testid":`wishlist-${t.id}`,children:(0,e.jsx)(T,{className:"w-4 h-4"})}),(0,e.jsx)("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/40 to-transparent p-3 transform transition-all duration-300 translate-y-0 opacity-100 z-20 md:from-black/60 md:opacity-0 md:group-hover:opacity-100",children:(0,e.jsxs)("button",{className:`w-full text-xs font-medium py-2 rounded-lg flex items-center justify-center gap-1.5 transition-colors ${n?"bg-gray-300 text-gray-500 cursor-not-allowed":"bg-white text-gray-900 hover:bg-[#E85A8B] hover:text-white"} disabled:opacity-50`,onClick:o=>{o.preventDefault(),o.stopPropagation(),n||g.mutate(t.id)},disabled:d||n,"data-testid":`quick-add-${t.id}`,children:[d?(0,e.jsx)(S,{className:"w-3.5 h-3.5 animate-spin"}):(0,e.jsx)(y,{className:"w-3.5 h-3.5"}),n?"Agotado":d?a.common.loading:"Añadir"]})})]}),(0,e.jsxs)(N,{href:w(t.id,t.name),className:"block p-3",tabIndex:-1,children:[(0,e.jsx)("p",{className:"text-xs text-[#E85A8B] mb-1",children:t.category}),(0,e.jsx)("h3",{className:"font-medium text-gray-800 text-sm line-clamp-2 group-hover:text-[#E85A8B] transition-colors",children:t.name}),(0,e.jsx)("div",{className:"mt-2 flex items-center gap-2",children:(0,e.jsx)(F,{value:t.price,regularPrice:t.originalPrice??void 0,size:"lg",className:"text-[#E85A8B]"})})]})]},t.id)})})]})}function he(){return(0,e.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[1,2,3,4,5,6,7,8].map(r=>(0,e.jsxs)("div",{className:"bg-white rounded-xl overflow-hidden animate-pulse",children:[(0,e.jsx)("div",{className:"aspect-square bg-gray-200"}),(0,e.jsxs)("div",{className:"p-3",children:[(0,e.jsx)("div",{className:"h-4 bg-gray-200 rounded w-3/4 mb-2"}),(0,e.jsx)("div",{className:"h-4 bg-gray-200 rounded w-1/2"})]})]},r))})}function xe({query:r,hasActiveFilters:a,clearFilters:s,t:i}){return(0,e.jsxs)("div",{className:"text-center py-16",children:[(0,e.jsx)("div",{className:"w-20 h-20 mx-auto mb-4 bg-[#E85A8B]/10 rounded-full flex items-center justify-center",children:(0,e.jsx)(P,{className:"w-10 h-10 text-[#E85A8B]"})}),(0,e.jsx)("h2",{className:"text-xl font-serif text-gray-800 mb-2",children:i.search.noResults}),(0,e.jsxs)("p",{className:"text-gray-500 mb-6",children:[i.search.noProductsMatch,' "',r,'"']}),a&&(0,e.jsxs)(C,{variant:"outline",onClick:s,className:"mb-4","data-testid":"button-clear-filters-empty",children:[(0,e.jsx)(k,{className:"w-4 h-4 mr-2"}),i.search.clearFilters]}),(0,e.jsxs)(N,{href:"/categories",className:"inline-flex items-center gap-2 px-6 py-3 bg-[#E85A8B] text-white rounded-full hover:bg-[#D14A7B] transition-colors","data-testid":"link-browse-categories",children:[(0,e.jsx)(y,{className:"w-5 h-5"}),i.search.exploreCategories]})]})}function ue({query:r,resultCount:a,showFilters:s,setShowFilters:i,t:l}){const[c,x]=(0,m.useState)(r),[,p]=E();(0,m.useEffect)(()=>{x(r)},[r]);const g=t=>{t.preventDefault();const n=c.trim();n.length>=2&&p(`/search?q=${encodeURIComponent(n)}`)};return(0,e.jsxs)("div",{className:"mb-6 space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-xl md:text-2xl font-serif text-[#E85A8B]","data-testid":"search-results-title",children:l.search.title}),(0,e.jsx)("p",{className:"text-sm text-gray-500 mt-1",children:r&&(0,e.jsxs)(e.Fragment,{children:[l.search.showingResults,' "',(0,e.jsx)("span",{className:"font-medium text-gray-700",children:r}),'"',a>0&&(0,e.jsxs)("span",{className:"ml-1",children:["(",a," ",l.search.products,")"]})]})})]}),(0,e.jsxs)("button",{onClick:()=>i(!s),className:"flex items-center gap-2 px-4 py-2 bg-white rounded-full shadow-sm hover:shadow-md transition-shadow md:hidden","data-testid":"button-toggle-filters",children:[(0,e.jsx)(Q,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"text-sm",children:l.category.filters})]})]}),(0,e.jsxs)("form",{onSubmit:g,className:"relative max-w-xl",children:[(0,e.jsx)(P,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500"}),(0,e.jsx)("input",{type:"text",value:c,onChange:t=>x(t.target.value),placeholder:"Buscar productos...","aria-label":"Refinar búsqueda de productos",className:"w-full pl-9 pr-4 py-3 rounded-full border border-gray-300 shadow-sm focus:border-[#
1E85A8B] focus:ring-2 focus:ring-[#E85A8B]/20 outline-none transition-all text-sm bg-gray-50 text-gray-900","data-testid":"input-search-refine"})]})]})}function ge(r){return[{slug:"all",name:r.categories.all},{slug:"para-ella",name:r.categories.forHer,color:"#EA4B7D"},{slug:"para-el",name:r.categories.forHim,color:"#22677F"},{slug:"pareja",name:r.categories.couples,color:"#DD0B47"},{slug:"lenceria",name:r.categories.lingerie,color:"#CA8CEA"},{slug:"bdsm",name:r.categories.bdsm,color:"#3B4044"},{slug:"salud",name:r.categories.health,color:"#31B59B"},{slug:"sexo-anal",name:r.categories.anal,color:"#662480"}]}function Re(){const{t:r}=M(),a=ne(),s=ie(),{data:i=[],isLoading:l}=le(a,s.selectedCategory),c=ce(i,{selectedCategory:s.selectedCategory,minPrice:s.minPrice,maxPrice:s.maxPrice,inStockOnly:s.inStockOnly,sortBy:s.sortBy}),{data:x}=V("search_results",{k:24,enabled:!!a&&!l}),p=(0,m.useMemo)(()=>x?.products.map(o=>o.product_id)??[],[x]),g=(0,m.useRef)("");(0,m.useEffect)(()=>{if(l||!a)return;const o=`${a}::${c.length}::${s.hasActiveFilters?"1":"0"}`;if(g.current!==o){g.current=o;try{H.search(a,c.length,s.hasActiveFilters)}catch{}try{z("internal_search",{query:a.slice(0,200),result_count:c.length,filtered:s.hasActiveFilters})}catch{}}},[l,a,c.length,s.hasActiveFilters]),oe({query:a,isLoading:l,resultCount:c.length,filtered:s.hasActiveFilters||s.selectedCategory!=="all"});const t=ge(r),n=`/search${a?`?q=${encodeURIComponent(a)}`:""}`,d=[{name:"Inicio",url:"/"},{name:a?`Búsqueda: ${a}`:"Buscar",url:n}];return(0,e.jsxs)(Z,{children:[(0,e.jsx)(te,{title:a?`Búsqueda: ${a}`:"Buscar Productos",description:a?`Ignis Love muestra resultados para "${a}": productos de bienestar Ãntimo con envÃo discreto y gratuito desde 60â¬.`:"Ignis Love te permite buscar entre más de 500 productos de bienestar Ãntimo con envÃo discreto en toda España.",url:n,type:"website",noindex:!l&&c.length===0,breadcrumbs:d}),(0,e.jsx)("div",{className:"min-h-screen bg-[#FDF8FA]",children:(0,e.jsxs)("div",{className:"container mx-auto px-4 py-6",children:[(0,e.jsx)(X,{items:d,className:"mb-4"}),(0,e.jsx)(ue,{query:a,resultCount:c.length,showFilters:s.showFilters,setShowFilters:s.setShowFilters,t:r}),(0,e.jsxs)("div",{className:"flex flex-col md:flex-row gap-6",children:[(0,e.jsx)(de,{showFilters:s.showFilters,setShowFilters:s.setShowFilters,sortBy:s.sortBy,setSortBy:s.setSortBy,minPrice:s.minPrice,setMinPrice:s.setMinPrice,maxPrice:s.maxPrice,setMaxPrice:s.setMaxPrice,inStockOnly:s.inStockOnly,setInStockOnly:s.setInStockOnly,selectedCategory:s.selectedCategory,setSelectedCategory:s.setSelectedCategory,categoryFilters:t,hasActiveFilters:s.hasActiveFilters,clearFilters:s.clearFilters,t:r}),(0,e.jsx)("main",{className:"flex-1",children:l?(0,e.jsx)(he,{}):c.length===0?(0,e.jsx)(xe,{query:a,hasActiveFilters:s.hasActiveFilters,clearFilters:s.clearFilters,t:r}):(0,e.jsx)(me,{products:c,t:r,rankedIds:p})})]})]})})]})}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.