{"version":3,"sources":["../../elements/carousel/Carousel.tsx","../../util/index.ts"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\n\nimport { cn } from \"@util/index\";\nimport { EmblaOptionsType } from \"embla-carousel\";\nimport useEmblaCarousel from \"embla-carousel-react\";\n\nimport { DirectionType } from \"@_types/commonTypes\";\n\ntype CarouselProps = {\n  items: React.ReactNode[];\n  showArrows?: boolean;\n  autoplay?: boolean;\n  autoplayInterval?: number;\n  options?: EmblaOptionsType;\n  direction?: DirectionType;\n};\ntype DotsProps = {\n  itemsLength: number;\n  selectedIndex: number;\n  direction: DirectionType;\n  onDotClick: (index: number) => void;\n};\ntype ControlsProps = {\n  canScrollPrev: boolean;\n  canScrollNext: boolean;\n  onPrev(): void;\n  onNext(): void;\n};\n\nexport const Carousel: React.FC<CarouselProps> = ({\n  items,\n  showArrows,\n  options,\n  autoplay,\n  direction = \"ltr\",\n  autoplayInterval = 3000,\n  ...props\n}) => {\n  const [emblaRef, emblaApi] = useEmblaCarousel({\n    ...options,\n    direction,\n    loop: autoplay ? true : options?.loop || false,\n  });\n  const [selectedIndex, setSelectedIndex] = useState(0);\n\n  useEffect(() => {\n    function selectHandler() {\n      const index = emblaApi?.selectedScrollSnap();\n      setSelectedIndex(index || 0);\n    }\n\n    emblaApi?.on(\"select\", selectHandler);\n    return () => {\n      emblaApi?.off(\"select\", selectHandler);\n    };\n  }, [emblaApi]);\n\n  useEffect(() => {\n    let autoplayTimer: ReturnType<typeof setTimeout>;\n    if (autoplay && emblaApi) {\n      autoplayTimer = setInterval(() => {\n        emblaApi.scrollNext();\n      }, autoplayInterval);\n    }\n\n    return () => {\n      if (autoplayTimer) clearInterval(autoplayTimer);\n    };\n  }, [emblaApi, autoplay, autoplayInterval]);\n\n  const length = React.Children.count(items);\n  const canScrollNext = !!emblaApi?.canScrollNext();\n  const canScrollPrev = !!emblaApi?.canScrollPrev();\n  return (\n    <div className=\"hawa-relative hawa-h-full\">\n      <div className=\"hawa-h-full hawa-overflow-hidden\">\n        <div className=\"hawa-h-full\" ref={emblaRef}>\n          <div className=\"hawa-flex hawa-h-full\">\n            {items?.map((item: any, i: any) => (\n              <div\n                key={i}\n                className=\"hawa-flex hawa-h-full hawa-min-w-0 hawa-flex-[0_0_100%] hawa-items-center hawa-justify-center\"\n              >\n                {item}\n              </div>\n            ))}\n          </div>\n        </div>\n      </div>\n\n      <Dots\n        direction={direction}\n        itemsLength={length}\n        selectedIndex={selectedIndex}\n        onDotClick={(index) => emblaApi?.scrollTo(index)}\n      />\n\n      {showArrows && (\n        <CarouselControls\n          canScrollNext={canScrollNext}\n          canScrollPrev={canScrollPrev}\n          onNext={() => emblaApi?.scrollNext()}\n          onPrev={() => emblaApi?.scrollPrev()}\n        />\n      )}\n    </div>\n  );\n};\n\nconst Dots = ({\n  onDotClick,\n  itemsLength,\n  selectedIndex,\n  direction,\n}: DotsProps) => {\n  const arr = new Array(itemsLength).fill(0);\n  return (\n    <div\n      dir={direction}\n      className=\"hawa-z-50 hawa-my-2 hawa-flex hawa-justify-center hawa-gap-1\"\n    >\n      {arr.map((_, index) => {\n        const selected = index === selectedIndex;\n        return (\n          <div\n            key={index}\n            onClick={() => onDotClick(index)}\n            className={cn(\n              \"hawa-h-2 hawa-rounded-full hawa-bg-primary hawa-transition-all hawa-duration-300 hover:hawa-cursor-pointer\",\n              !selected\n                ? \"hawa-w-2 hawa-opacity-50\"\n                : \"hawa-w-6 hawa-opacity-100\",\n            )}\n          ></div>\n        );\n      })}\n    </div>\n  );\n};\n\nconst CarouselControls = (props: ControlsProps) => {\n  return (\n    <div className=\"hawa-flex hawa-justify-end hawa-gap-2\">\n      <button\n        onClick={() => props.canScrollPrev && props.onPrev()}\n        disabled={!props.canScrollPrev}\n        className={cn(\n          \"hawa-absolute hawa-start-0 hawa-top-1/2 -hawa-translate-y-2 hawa-rounded-full hawa-p-2 hawa-text-white\",\n          !props.canScrollPrev && \"hawa-bg-primary/50\",\n          props.canScrollPrev && \"hawa-bg-primary\",\n        )}\n      >\n        <svg\n          aria-label=\"Chevron Right Icon\"\n          stroke=\"currentColor\"\n          fill=\"currentColor\"\n          viewBox=\"0 0 16 16\"\n          className=\"hawa-h-2 hawa-w-2 hawa-shrink-0 hawa-rotate-180 hawa-transition-transform hawa-duration-200\"\n        >\n          <path d=\"M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z\"></path>\n        </svg>\n      </button>\n      <button\n        onClick={() => props.canScrollNext && props.onNext()}\n        disabled={!props.canScrollNext}\n        className={cn(\n          \"hawa-absolute hawa-end-0 hawa-top-1/2 -hawa-translate-y-2 hawa-rounded-full hawa-p-2 hawa-text-white\",\n          !props.canScrollNext && \"hawa-bg-primary/50\",\n          props.canScrollNext && \"hawa-bg-primary\",\n        )}\n      >\n        <svg\n          aria-label=\"Chevron Right Icon\"\n          stroke=\"currentColor\"\n          fill=\"currentColor\"\n          viewBox=\"0 0 16 16\"\n          className=\"hawa-h-2 hawa-w-2 hawa-shrink-0 hawa-transition-transform hawa-duration-200\"\n        >\n          <path d=\"M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z\"></path>\n        </svg>\n      </button>\n    </div>\n  );\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n  name: string;\n  colors: {\n    [key: number]: string;\n  };\n};\ntype Rgb = {\n  r: number;\n  g: number;\n  b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n  const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n  const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n    sanitizedHex\n  );\n\n  if (!colorParts) {\n    return null;\n  }\n\n  const [, r, g, b] = colorParts;\n\n  return {\n    r: parseInt(r, 16),\n    g: parseInt(g, 16),\n    b: parseInt(b, 16)\n  } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n  const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n  return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n  const rgbColor = hexToRgb(color);\n\n  if (!rgbColor) {\n    return \"#333\";\n  }\n\n  const { r, g, b } = rgbColor;\n  const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n  return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n  const color = hexToRgb(`#${hex}`);\n\n  if (!color) {\n    return \"\";\n  }\n\n  const r = Math.round(color.r + (255 - color.r) * intensity);\n  const g = Math.round(color.g + (255 - color.g) * intensity);\n  const b = Math.round(color.b + (255 - color.b) * intensity);\n\n  return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n  const color = hexToRgb(hex);\n\n  if (!color) {\n    return \"\";\n  }\n\n  const r = Math.round(color.r * intensity);\n  const g = Math.round(color.g * intensity);\n  const b = Math.round(color.b * intensity);\n\n  return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n  if (color.startsWith(\"#\")) {\n    // Convert hex to RGB\n    let r = parseInt(color.slice(1, 3), 16);\n    let g = parseInt(color.slice(3, 5), 16);\n    let b = parseInt(color.slice(5, 7), 16);\n    return [r, g, b];\n  } else if (color.startsWith(\"rgb\")) {\n    // Extract RGB values from rgb() format\n    return color.match(/\\d+/g).map(Number);\n  }\n  // Default to white if format is unrecognized\n  return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n  const [r, g, b] = parseColor(color)?.map((c: any) => {\n    c /= 255;\n    return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n  });\n  return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n  const name = baseColor;\n\n  const response: Palette = {\n    name,\n    colors: {\n      500: `#${baseColor}`.replace(\"##\", \"#\")\n    }\n  };\n\n  const intensityMap: {\n    [key: number]: number;\n  } = {\n    50: 0.95,\n    100: 0.9,\n    200: 0.75,\n    300: 0.6,\n    400: 0.3,\n    600: 0.9,\n    700: 0.75,\n    800: 0.6,\n    900: 0.49\n  };\n\n  [50, 100, 200, 300, 400].forEach((level) => {\n    response.colors[level] = lighten(baseColor, intensityMap[level]);\n  });\n  [600, 700, 800, 900].forEach((level) => {\n    response.colors[level] = darken(baseColor, intensityMap[level]);\n  });\n\n  return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n//   let d = hex?.split(\"#\")[1];\n//   var aRgbHex = d?.match(/.{1,2}/g);\n//   var aRgb = [\n//     parseInt(aRgbHex[0], 16),\n//     parseInt(aRgbHex[1], 16),\n//     parseInt(aRgbHex[2], 16)\n//   ];\n//   return aRgb;\n// };\n// const getTextColor = (backColor) => {\n//   let rgbArray = hexToRgb(backColor);\n//   if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n//     return \"#000000\";\n//   } else {\n//     return \"#ffffff\";\n//   }\n// };\n// const replaceAt = function (string, index, replacement) {\n//   // if (replacement == \"\" || replacement == \" \") {\n//   //   return (\n//   //     string.substring(0, index) +\n//   //     string.substring(index + replacement.length )\n//   //   );\n//   // }\n//   const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n//   return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";;;AAAA,OAAO,SAAS,WAAW,gBAAgB;;;ACA3C,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADDA,OAAO,sBAAsB;AAyBtB,IAAM,WAAoC,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