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

export function useRoboticArmActions() {
    const { handlePickAndPlace } = usePickAndPlaceHandler();

    const handlePickAndPlaceAction = useCallback((action: RoboticArmAction, materialId: string) => {
        handlePickAndPlace(action, materialId);
    }, [handlePickAndPlace]);

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

        switch (action.actionType) {
            case 'pickAndPlace':
                handlePickAndPlaceAction(action, materialId);
                break;
            default:
                console.warn(`Unknown robotic arm action type: ${action.actionType}`);
        }
    }, [handlePickAndPlaceAction]);

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

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

    return {
        handleRoboticArmAction,
        cleanup
    };
}