import { useState, useEffect } from 'react';
import { ConsentManager } from './ConsentManager';

export function useConsent() {
  const [consent, setConsent] = useState(null);
  const [hasDecided, setHasDecided] = useState(false);

  useEffect(() => {
    setConsent(ConsentManager.getConsent());
    setHasDecided(ConsentManager.hasUserDecided());
  }, []);

  const acceptConsent = () => {
    ConsentManager.setConsent(true);
    setConsent(ConsentManager.getConsent());
    setHasDecided(true);
  };

  const rejectConsent = () => {
    ConsentManager.setConsent(false);
    setConsent(ConsentManager.getConsent());
    setHasDecided(true);
  };

  const hasConsent = ConsentManager.hasConsent();

  return {
    consent,
    hasConsent,
    hasDecided,
    acceptConsent,
    rejectConsent,
  };
}
