/**
 * Client-only wrapper component - COOP-CA AMIFOND
 *
 * Ensures components only render on the client side to prevent SSR hydration mismatches
 */

"use client";

import { useEffect, useState, type ReactNode } from "react";

interface ClientOnlyProps {
  readonly children: ReactNode;
  readonly fallback?: ReactNode;
}

export function ClientOnly({ children, fallback = null }: ClientOnlyProps) {
  const [hasMounted, setHasMounted] = useState(false);

  useEffect(() => {
    setHasMounted(true);
  }, []);

  if (!hasMounted) {
    return <>{fallback}</>;
  }

  return <>{children}</>;
}
