'use client'
import { useEffect, useRef } from 'react'

// Dynamic imports to avoid SSR issues
let gsap: any
let ScrollTrigger: any

if (typeof window !== 'undefined') {
  gsap = require('gsap').gsap
  ScrollTrigger = require('gsap/ScrollTrigger').ScrollTrigger
  gsap.registerPlugin(ScrollTrigger)
}

export function ScrollProvider({ children }: { children: React.ReactNode }) {
  useEffect(() => {
    // Check if GSAP is available
    if (!gsap || !ScrollTrigger) return

    // Just refresh ScrollTrigger on resize - no smooth scrolling
    const handleResize = () => {
      ScrollTrigger.refresh()
    }

    window.addEventListener('resize', handleResize)

    return () => {
      window.removeEventListener('resize', handleResize)
      ScrollTrigger.killAll()
    }
  }, [])

  return <>{children}</>
}