import { useCallback } from "react";
import { useMaterialStore } from "../../../../../store/simulation/useMaterialStore";

export function useDespawnHandler() {
    const { addMaterial, getMaterialById, removeMaterial } = useMaterialStore();

    const deSpawnLogStatus = (materialUuid: string, status: string) => {
        // console.log(`${materialUuid}, ${status}`);
    }

    const handleDespawn = useCallback((action: ConveyorAction, materialId?: string) => {
        if (!action || action.actionType !== 'despawn' || !materialId) return;

        const material = getMaterialById(materialId);
        if (!material) return;

        removeMaterial(material.materialId);

        deSpawnLogStatus(material.materialId, `Despawned`);

    }, [addMaterial, getMaterialById, removeMaterial]);

    return {
        handleDespawn,
    };
}