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

export function useCraneActions() {
    const { handlePickAndDrop } = usePickAndDropHandler();

    const handleWorkerAction = useCallback((action: CraneAction, materialId: string) => {
        handlePickAndDrop(action, materialId);
    }, [handlePickAndDrop]);

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

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

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

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

    return {
        handleCraneAction,
        cleanup
    };
}