/**
 * Unified Map Provider
 * Combines all map-related contexts for easy consumption
 * Provides a single import for map functionality
 */

import { ReactNode } from 'react';
import type { BackendOrganization } from '@/schemas/backend/organization';
import { MapActionsProvider } from '@/contexts/MapActionsContext.tsx';
import { MapFilterProvider } from '@/contexts/MapFilterContext.tsx';
import { MapInteractionProvider } from '@/contexts/MapInteractionContext.tsx';
import { MapUIProvider } from '@/contexts/MapUIContext.tsx';
import { MapViewportProvider } from '@/contexts/MapViewportContext.tsx';

interface MapProviderProps {
  children: ReactNode;
  organizations: BackendOrganization[];
  initialCenter?: [number, number];
  initialZoom?: number;
  defaultViewMode?: 'organizations' | 'historical';
}

/**
 * Unified Map Provider that combines all map contexts
 * Use this instead of the monolithic MapContexts
 */
export const MapProvider = ({
  children,
  organizations,
  initialCenter,
  initialZoom,
  defaultViewMode = 'organizations',
}: MapProviderProps) => {
  return (
    <MapViewportProvider initialCenter={initialCenter} initialZoom={initialZoom}>
      <MapInteractionProvider>
        <MapFilterProvider organizations={organizations}>
          <MapUIProvider defaultViewMode={defaultViewMode}>
            <MapActionsProvider>{children}</MapActionsProvider>
          </MapUIProvider>
        </MapFilterProvider>
      </MapInteractionProvider>
    </MapViewportProvider>
  );
};

// Re-export all hooks and contexts for convenience
export * from '@/contexts/MapActionsContext.tsx';
export * from '@/contexts/MapFilterContext.tsx';
export * from '@/contexts/MapInteractionContext.tsx';
export * from '@/contexts/MapUIContext.tsx';
export * from '@/contexts/MapViewportContext.tsx';

// Legacy export for backward compatibility
export { MapProvider as MapViewProvider };
