"use client"

import { useMemo } from "react"

import useScrollShadows from "@/hooks/useScrollShadows"

import styles from "./scrollWrapper.module.css"

import type { ScrollWrapperProps } from "./scrollWrapper"

export default function ScrollWrapper({
  className,
  children,
}: ScrollWrapperProps) {
  const { containerRef, showLeftShadow, showRightShadow } =
    useScrollShadows<HTMLDivElement>()

  const classNames = useMemo(() => {
    const cls = [styles.scrollWrapper, className]
    if (showLeftShadow) {
      cls.push(styles.leftShadow)
    }
    if (showRightShadow) {
      cls.push(styles.rightShadow)
    }
    return cls.join(" ")
  }, [showLeftShadow, showRightShadow, className])

  return (
    <div className={classNames}>
      <div className={styles.content} ref={containerRef}>
        {children}
      </div>
    </div>
  )
}
