import { useEffect } from 'react';
import { useProductStore } from '../../../store/simulation/useProductStore';
import { useActionHandler } from '../actions/useActionHandler';
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
import { determineExecutionOrder } from './functions/determineExecutionOrder';
import { useSelectedProduct } from '../../../store/simulation/useSimulationStore';

function Simulator() {
    const { products, getProductById } = useProductStore();
    const { handleAction } = useActionHandler();
    const { selectedProduct } = useSelectedProduct();
    const { isPlaying } = usePlayButtonStore();
    const { isReset } = useResetButtonStore();

    useEffect(() => {
        if (!isPlaying || isReset || !selectedProduct.productId) return;

        const product = getProductById(selectedProduct.productId);
        if (!product) return;

        const executionOrder = determineExecutionOrder([product]);
        executionOrder.forEach(point => {
            const action = 'actions' in point ? point.actions[0] : point.action;
            handleAction(action);
        });
    }, [products, isPlaying, isReset, selectedProduct]);

    return (

        <>

        </>

    );
}

export default Simulator;