'use client';
import { useState, useEffect } from 'react';

export const useVariant = () => {
  const [variant, setVariant] = useState<string | null>(null);
  const [mounted, setMounted] = useState(false);
  
  useEffect(() => {
    setMounted(true);
    const u = new URL(window.location.href);
    setVariant(u.searchParams.get('ab') ?? 'control');
  }, []);
  
  return { variant: variant || 'control', mounted };
};

// Legacy function for backward compatibility
export const variant = () => {
  if (typeof window === 'undefined') return 'control';
  const u = new URL(window.location.href);
  return u.searchParams.get('ab') ?? 'control';
};
