"use client";
import AutoScroll from 'embla-carousel-auto-scroll';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { Img } from '@page-speed/img';
import * as React from 'react';
import useEmblaCarousel from 'embla-carousel-react';
import { jsxs, jsx } from 'react/jsx-runtime';

// components/blocks/logos/logos-carousel-heading.tsx
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var CarouselContext = React.createContext(null);
function useCarousel() {
  const context = React.useContext(CarouselContext);
  if (!context) {
    throw new Error("useCarousel must be used within a <Carousel />");
  }
  return context;
}
function Carousel({
  orientation = "horizontal",
  opts,
  setApi,
  plugins,
  className,
  children,
  ...props
}) {
  const [carouselRef, api] = useEmblaCarousel(
    {
      ...opts,
      axis: orientation === "horizontal" ? "x" : "y"
    },
    plugins
  );
  const [canScrollPrev, setCanScrollPrev] = React.useState(false);
  const [canScrollNext, setCanScrollNext] = React.useState(false);
  const onSelect = React.useCallback((api2) => {
    if (!api2) return;
    setCanScrollPrev(api2.canScrollPrev());
    setCanScrollNext(api2.canScrollNext());
  }, []);
  const scrollPrev = React.useCallback(() => {
    api?.scrollPrev();
  }, [api]);
  const scrollNext = React.useCallback(() => {
    api?.scrollNext();
  }, [api]);
  const handleKeyDown = React.useCallback(
    (event) => {
      if (event.key === "ArrowLeft") {
        event.preventDefault();
        scrollPrev();
      } else if (event.key === "ArrowRight") {
        event.preventDefault();
        scrollNext();
      }
    },
    [scrollPrev, scrollNext]
  );
  React.useEffect(() => {
    if (!api || !setApi) return;
    setApi(api);
  }, [api, setApi]);
  React.useEffect(() => {
    if (!api) return;
    onSelect(api);
    api.on("reInit", onSelect);
    api.on("select", onSelect);
    return () => {
      api?.off("select", onSelect);
    };
  }, [api, onSelect]);
  return /* @__PURE__ */ jsx(
    CarouselContext.Provider,
    {
      value: {
        carouselRef,
        api,
        opts,
        orientation: orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
        scrollPrev,
        scrollNext,
        canScrollPrev,
        canScrollNext
      },
      children: /* @__PURE__ */ jsx(
        "div",
        {
          onKeyDownCapture: handleKeyDown,
          className: cn("relative", className),
          role: "region",
          "aria-roledescription": "carousel",
          "data-slot": "carousel",
          ...props,
          children
        }
      )
    }
  );
}
function CarouselContent({ className, ...props }) {
  const { carouselRef, orientation } = useCarousel();
  return /* @__PURE__ */ jsx(
    "div",
    {
      ref: carouselRef,
      className: "overflow-hidden",
      "data-slot": "carousel-content",
      children: /* @__PURE__ */ jsx(
        "div",
        {
          className: cn(
            "flex",
            orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
            className
          ),
          ...props
        }
      )
    }
  );
}
function CarouselItem({ className, ...props }) {
  const { orientation } = useCarousel();
  return /* @__PURE__ */ jsx(
    "div",
    {
      role: "group",
      "aria-roledescription": "slide",
      "data-slot": "carousel-item",
      className: cn(
        "min-w-0 shrink-0 grow-0 basis-full",
        orientation === "horizontal" ? "pl-4" : "pt-4",
        className
      ),
      ...props
    }
  );
}
var defaultLogos = [
  {
    id: "logo-1",
    description: "Logo 1",
    image: "https://cdn.ing/assets/files/record/286222/4w39lhwei0pa97up2wjnay3j96gh",
    className: "h-7 w-auto"
  },
  {
    id: "logo-2",
    description: "Logo 2",
    image: "https://cdn.ing/assets/files/record/286215/6wwi6yh2ax2nuo2vqa5gn9vozrgq",
    className: "h-7 w-auto"
  },
  {
    id: "logo-3",
    description: "Logo 3",
    image: "https://cdn.ing/assets/files/record/286249/ff7m4wdw0zefj7d96v4ajmljuifc",
    className: "h-7 w-auto"
  },
  {
    id: "logo-4",
    description: "Logo 4",
    image: "https://cdn.ing/assets/files/record/286216/bw4zypgflisdtapxy0n4nbmsmtum",
    className: "h-7 w-auto"
  },
  {
    id: "logo-5",
    description: "Logo 5",
    image: "https://cdn.ing/assets/files/record/286220/t34kymqu5g9xr85o89cji3kfuypb",
    className: "h-7 w-auto"
  },
  {
    id: "logo-6",
    description: "Logo 6",
    image: "https://cdn.ing/assets/files/record/286284/cz20wf2l2tjokrxu563pcml7pkmu",
    className: "h-7 w-auto"
  },
  {
    id: "logo-7",
    description: "Logo 7",
    image: "https://cdn.ing/assets/files/record/286251/c64yb2c255uig6vpe4gdlnten7rv",
    className: "h-4 w-auto"
  },
  {
    id: "logo-8",
    description: "Logo 8",
    image: "https://cdn.ing/assets/files/record/286252/xd7hyzbpkjwsauxm5j9yn9v44min",
    className: "h-7 w-auto"
  }
];
function LogosCarouselHeading({
  className,
  heading = "Trusted by these companies",
  logos = defaultLogos,
  optixFlowConfig
}) {
  return /* @__PURE__ */ jsxs("section", { className: cn("py-64", className), children: [
    /* @__PURE__ */ jsx("div", { className: "container flex flex-col items-center text-center", children: /* @__PURE__ */ jsx("h1", { className: "my-6 text-2xl font-bold text-pretty lg:text-4xl", children: heading }) }),
    /* @__PURE__ */ jsx("div", { className: "pt-10 md:pt-16 lg:pt-20", children: /* @__PURE__ */ jsxs("div", { className: "relative mx-auto flex items-center justify-center lg:max-w-5xl", children: [
      /* @__PURE__ */ jsx(
        Carousel,
        {
          opts: { loop: true },
          plugins: [AutoScroll({ playOnInit: true })],
          children: /* @__PURE__ */ jsx(CarouselContent, { className: "ml-0", children: logos.map((logo) => /* @__PURE__ */ jsx(
            CarouselItem,
            {
              className: "flex basis-1/3 justify-center pl-0 sm:basis-1/4 md:basis-1/5 lg:basis-1/6",
              children: /* @__PURE__ */ jsx("div", { className: "mx-10 flex shrink-0 items-center justify-center", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
                Img,
                {
                  src: logo.image,
                  alt: logo.description,
                  className: logo.className,
                  optixFlowConfig
                }
              ) }) })
            },
            logo.id
          )) })
        }
      ),
      /* @__PURE__ */ jsx("div", { className: "absolute inset-y-0 left-0 w-12 bg-linear-to-r from-background to-transparent" }),
      /* @__PURE__ */ jsx("div", { className: "absolute inset-y-0 right-0 w-12 bg-linear-to-l from-background to-transparent" })
    ] }) })
  ] });
}

export { LogosCarouselHeading };
//# sourceMappingURL=logos-carousel-heading.js.map
//# sourceMappingURL=logos-carousel-heading.js.map