import { useEffect, useCallback } from 'react';
import { useTravelHandler } from './actionHandler/useTravelHandler';

export function useVehicleActions() {
    const { handleTravel } = useTravelHandler();

    const handleTravelAction = useCallback((action: VehicleAction, materialId: string) => {
        handleTravel(action, materialId);
    }, [handleTravel]);

    const handleVehicleAction = useCallback((action: VehicleAction, materialId: string) => {
        if (!action) return;

        switch (action.actionType) {
            case 'travel':
                handleTravelAction(action, materialId);
                break;
            default:
                console.warn(`Unknown vehicle action type: ${action.actionType}`);
        }
    }, [handleTravelAction]);

    const cleanup = useCallback(() => {
    }, []);

    useEffect(() => {
        return () => {
            cleanup();
        };
    }, [cleanup]);

    return {
        handleVehicleAction,
        cleanup
    };
}