import React, { useEffect } from 'react'
import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore';
import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore';
import { useResetButtonStore } from '../../../../../store/usePlayButtonStore';

function ConveyorInstance({ conveyor }: { conveyor: ConveyorStatus }) {
    const { materials, getMaterialsByCurrentModelUuid } = useMaterialStore();
    const { isReset } = useResetButtonStore();

    const { setConveyorPaused } = useConveyorStore();

    useEffect(() => {
        const conveyorMaterials = getMaterialsByCurrentModelUuid(conveyor.modelUuid);
        if (conveyorMaterials && conveyorMaterials?.length > 0) {

            const hasPausedMaterials = conveyorMaterials.some(material => material.isPaused);

            if (hasPausedMaterials) {
                setConveyorPaused(conveyor.modelUuid, true);
            } else {
                setConveyorPaused(conveyor.modelUuid, false);
            }
        }

    }, [materials, conveyor.modelUuid, getMaterialsByCurrentModelUuid, setConveyorPaused, isReset]);

    useEffect(() => {
        // console.log('conveyor: ', conveyor);
    }, [conveyor])

    return (
        <>
        </>
    )
}

export default ConveyorInstance