import { useState, useCallback } from 'react';

/**
 * Hook personnalisé pour gérer l'état des accordéons
 * Remplace la logique dans App.tsx et simplifie la gestion d'état
 */
export const useAccordion = (initialState: string | null = null) => {
  const [openAccordion, setOpenAccordion] = useState<string | null>(initialState);

  const toggleAccordion = useCallback((title: string) => {
    setOpenAccordion(prev => prev === title ? null : title);
  }, []);

  const openSpecificAccordion = useCallback((title: string) => {
    setOpenAccordion(title);
  }, []);

  const closeAccordion = useCallback(() => {
    setOpenAccordion(null);
  }, []);

  const isOpen = useCallback((title: string) => {
    return openAccordion === title;
  }, [openAccordion]);

  return {
    openAccordion,
    toggleAccordion,
    openSpecificAccordion,
    closeAccordion,
    isOpen,
  };
};
