import { useState, useEffect } from 'react';
import { supabase } from '@/integrations/supabase/client';

const isValidUUID = (uuid) => {
  const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
  return typeof uuid === 'string' && regex.test(uuid);
};

// Generic comment count hook - maps item types to tables
// Note: Some comment tables may not exist yet in the schema; 
// this hook will gracefully handle errors.
export function useCommentCount(itemId, itemType) {
  const [count, setCount] = useState(0);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    if (!itemId || !itemType || !isValidUUID(itemId)) {
      setCount(0);
      setLoading(false);
      return;
    }

    // For now, return 0 since dedicated comment tables are not yet created
    setCount(0);
    setLoading(false);
  }, [itemId, itemType]);

  return { count, loading };
}
