import{r,j as t,L as C}from"./vendor-react-DgEFbQIi.js";import{u as G,t as B}from"./useHoverRipple-CBPqdLxA.js";import{L as D}from"./ListingCard-Cw2aMm7U.js";import{g as P}from"./listing-utils-CICni2H8.js";import{A as _,C as $,j as z}from"./index-DFVuS8SP.js";function A(a){var o,m;const n=P(a)??a.draftData??{};return((o=n.serviceData)==null?void 0:o.coverImage)??((m=n.media)==null?void 0:m.coverImage)??void 0}const V=16,q=({href:a,images:n})=>{const o=n.filter(Boolean).slice(0,3);return t.jsx(C,{to:a,className:"block h-full",children:t.jsxs("div",{className:"rounded-2xl bg-gray-50 h-full flex flex-col items-center justify-center gap-5 p-6 min-h-[220px] hover:bg-gray-100 transition-colors",children:[t.jsxs("div",{className:"relative h-28 w-28 flex-shrink-0",children:[o[2]&&t.jsx("img",{src:o[2],alt:"",className:"absolute top-4 right-0 h-20 w-20 rounded-xl object-cover shadow-sm rotate-[7deg]"}),o[1]&&t.jsx("img",{src:o[1],alt:"",className:"absolute top-2 left-2 h-20 w-20 rounded-xl object-cover shadow-sm -rotate-[3deg]"}),o[0]&&t.jsx("img",{src:o[0],alt:"",className:"absolute inset-0 h-20 w-20 rounded-xl object-cover shadow-md"})]}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:"See all"})]})})},J=({services:a,heading:n,subtitle:o,searchQuery:m,viewAllHref:f,dense:j=!1})=>{const d=r.useRef(null),[x,L]=r.useState(!1),[p,k]=r.useState(!1),[i,R]=r.useState(2),h=12,w=i*2,E=r.useMemo(()=>a.slice(0,w),[a,w]),{onItemHover:y,getStyle:I}=G(),b=r.useCallback(()=>{const s=d.current;if(!s)return;const e=s.clientWidth-V*2;let l=2;j?e>=1240?l=7:e>=1060?l=6:e>=880?l=5:e>=640?l=4:e>=460&&(l=3):e>=1400?l=6:e>=1200?l=5:e>=700?l=4:e>=480&&(l=3),R(l)},[j]),c=r.useCallback(()=>{const s=d.current;if(!s)return;const{scrollLeft:e,scrollWidth:l,clientWidth:u}=s;L(e>4),k(e+u<l-4)},[]);r.useEffect(()=>{const s=d.current;if(!s)return;const e=()=>{b(),c()};return b(),c(),s.addEventListener("scroll",c,{passive:!0}),window.addEventListener("resize",e),()=>{s.removeEventListener("scroll",c),window.removeEventListener("resize",e)}},[b,c]),r.useEffect(()=>{const s=d.current;if(!s)return;const e=s.querySelector("[data-card]");if(!e)return;const l=parseFloat(getComputedStyle(s).columnGap||`${h}`),u=e.getBoundingClientRect().width+l,g=s.scrollWidth-s.clientWidth,v=Math.min(Math.round(s.scrollLeft/u)*u,g);s.scrollTo({left:v,behavior:"auto"}),c()},[i,c]);const N=r.useCallback(s=>{const e=d.current;if(!e)return;const l=e.querySelector("[data-card]");if(!l)return;const u=parseFloat(getComputedStyle(e).columnGap||`${h}`),g=l.getBoundingClientRect().width+u,v=e.scrollWidth-e.clientWidth,W=s==="left"?Math.max(0,e.scrollLeft-g):Math.min(v,e.scrollLeft+g);e.scrollTo({left:W,behavior:"smooth"})},[]),M=r.useMemo(()=>i<=1?"100%":i===2?`calc((100% - ${h*2}px) / 2.4)`:`calc((100% - ${(i-1)*h}px) / ${i})`,[i]),S=r.useMemo(()=>a.map(s=>A(s)??"").filter(Boolean),[a]);return t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[f?t.jsxs(C,{to:f,className:"group inline-flex items-center gap-1.5 hover:underline underline-offset-2",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:n}),t.jsx(_,{className:"h-4 w-4 text-gray-900 transition-transform group-hover:translate-x-0.5"})]}):t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:n}),t.jsx("p",{className:"text-[11px] text-muted-foreground",children:o})]}),t.jsxs("div",{className:"hidden lg:flex items-center gap-2 flex-shrink-0 mt-0.5",children:[t.jsx("button",{type:"button",onClick:()=>N("left"),disabled:!x,"aria-label":"Scroll left",className:"h-9 w-9 rounded-full border border-gray-200 glass glass-surface flex items-center justify-center text-gray-700 disabled:opacity-30 disabled:cursor-not-allowed",children:t.jsx($,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>N("right"),disabled:!p,"aria-label":"Scroll right",className:"h-9 w-9 rounded-full border border-gray-200 glass glass-surface flex items-center justify-center text-gray-700 disabled:opacity-30 disabled:cursor-not-allowed",children:t.jsx(z,{className:"h-4 w-4"})})]})]}),t.jsxs("div",{className:"relative -mr-4 md:mr-0",children:[t.jsxs("div",{ref:d,className:"grid grid-flow-col gap-3 overflow-x-auto pt-5 pb-5 px-4 -mt-5 -mb-2 -mx-4 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",style:{gridAutoColumns:M},onMouseLeave:()=>y(null),children:[E.map((s,e)=>t.jsx("div",{"data-card":!0,className:"h-full transition-[transform,box-shadow] duration-300 ease-out will-change-transform",style:I(e),onMouseEnter:()=>y(e),onClickCapture:l=>B({listingId:s.listingId,category:"service",position:e+1,source:"carousel_home",searchQuery:m},l),children:t.jsx(D,{kind:"service",service:s,className:"h-full",searchQuery:m,hideOverlays:!0})},s.listingId)),f&&S.length>=2&&t.jsx(q,{href:f,images:S})]}),!x&&p&&t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 w-12 bg-gradient-to-l from-white/50 via-white/40 to-transparent hidden md:block"}),x&&t.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 w-10 bg-gradient-to-r from-white/50 via-white/40 to-transparent"}),t.jsx("div",{className:"sr-only","aria-live":"polite",children:p?"More services available. Swipe horizontally to view.":"End of spotlight services."})]})]})};export{J as S};