import { useState, useCallback } from 'react';
import { SharedFilterContext } from './sharedFilterState';

export { SharedFilterContext } from './sharedFilterState';
export type { SharedFilterState } from './sharedFilterState';

export function SharedFilterProvider({ children }: { children: React.ReactNode }) {
  const [hiddenAcCategories, setHiddenAcCategories] = useState<Set<string>>(new Set());
  const [hiddenShipCategories, setHiddenShipCategories] = useState<Set<string>>(new Set());

  const toggleAcCategory = useCallback((cat: string) => {
    setHiddenAcCategories(prev => {
      const next = new Set(prev);
      if (next.has(cat)) next.delete(cat); else next.add(cat);
      return next;
    });
  }, []);

  const toggleShipCategory = useCallback((cat: string) => {
    setHiddenShipCategories(prev => {
      const next = new Set(prev);
      if (next.has(cat)) next.delete(cat); else next.add(cat);
      return next;
    });
  }, []);

  return (
    <SharedFilterContext.Provider value={{ hiddenAcCategories, hiddenShipCategories, toggleAcCategory, toggleShipCategory }}>
      {children}
    </SharedFilterContext.Provider>
  );
}
