import { useEffect } from 'react'
import { useInputValues, useProductionCapacityData, useThroughPutData } from '../../../../store/builder/store'
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';

export default function ProductionCapacityData() {
    const { throughputData } = useThroughPutData()
    const { setProductionCapacityData } = useProductionCapacityData()
    const { inputValues } = useInputValues();
    const { isPlaying } = usePlayButtonStore();

    useEffect(() => {
        if (!isPlaying) {
            setProductionCapacityData(0);
        }
    }, [isPlaying]);

    useEffect(() => {
        if (!inputValues || throughputData === undefined || !isPlaying) return;
        const workingDaysPerYear = parseFloat(inputValues["Working days / year"]);

        if (!isNaN(workingDaysPerYear) && throughputData > 0) {
            const Monthly_working_days = workingDaysPerYear / 12;
            const Production_capacity_per_month = throughputData * Monthly_working_days;

            setProductionCapacityData(Number(Production_capacity_per_month.toFixed(2)));
        }
    }, [throughputData, inputValues, isPlaying]);

    return (
        <></>
    )
}


