import { useEffect, useState, useCallback } from "react";

export const useZonesExpansion = (zones: any[]) => {
  const [expandedZones, setExpandedZones] = useState<Record<string, boolean>>({});

  useEffect(() => {
    const expanded: Record<string, boolean> = { "unassigned-zone": true };
    zones.forEach((zone) => {
      expanded[zone.zoneUuid] = true;
    });
    setExpandedZones(expanded);
  }, [zones, zones.length]);

  const toggleZoneExpansion = useCallback((zoneUuid: string) => {
    setExpandedZones((prev) => ({
      ...prev,
      [zoneUuid]: !prev[zoneUuid],
    }));
  }, []);

  return { expandedZones, toggleZoneExpansion };
};
