import { create } from 'zustand';
import { locations as initialLocations } from '@/data/locations';

const useLocationStore = create((set) => ({
  locations: initialLocations,
  addLocation: (newLocation) =>
    set((state) => ({
      locations: [newLocation, ...state.locations],
    })),
    updateLocation: (id, updatedData) =>
        set((state) => ({
          locations: state.locations.map((loc) =>
            loc.id == id ? { ...loc, ...updatedData } : loc
          ),
        })),
    deleteLocation: (id) =>
        set((state) => ({
        locations: state.locations.filter((loc) => loc.id != id),
    })),
}));

export default useLocationStore;