import { useCallback } from "react";
import { useSceneContext } from "../../scene/sceneContext";

function useFloorResponseHandler() {
    const { floorStore } = useSceneContext();
    const { addFloor, updateFloor, removeFloor } = floorStore();

    const addFloorToScene = useCallback(
        (floor: Floor, callback?: () => void) => {
            addFloor(floor);

            if (callback) callback();
        },
        [addFloor]
    );

    const updateFloorInScene = useCallback(
        (floor: Floor, callback?: () => void) => {
            updateFloor(floor.floorUuid, floor);

            if (callback) callback();
        },
        [updateFloor]
    );

    const removeFloorFromScene = useCallback(
        (floorUuid: string, callback?: () => void) => {
            removeFloor(floorUuid);

            if (callback) callback();
        },
        [removeFloor]
    );

    const duplicateFloorInScene = useCallback((floorUuid: string, callback?: () => void) => {
        console.log("Duplicating floor: ", floorUuid);

        if (callback) callback();
    }, []);

    const pasteAssetFloorToScene = useCallback((floor: Floor, callback?: () => void) => {
        console.log("Pasting floor: ", floor);

        if (callback) callback();
    }, []);

    return {
        addFloorToScene,
        updateFloorInScene,
        removeFloorFromScene,
        duplicateFloorInScene,
        pasteAssetFloorToScene,
    };
}

export default useFloorResponseHandler;
