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

function useAisleResponseHandler() {
    const { aisleStore } = useSceneContext();
    const { addAisle, updateAisle, removeAisle } = aisleStore();

    const addAisleToScene = useCallback(
        (aisle: Aisle, callback?: () => void) => {
            addAisle(aisle);

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

    const updateAisleInScene = useCallback(
        (aisle: Aisle, callback?: () => void) => {
            updateAisle(aisle.aisleUuid, aisle);

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

    const removeAisleFromScene = useCallback(
        (aisleUuid: string, callback?: () => void) => {
            removeAisle(aisleUuid);

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

    const duplicateAisleInScene = useCallback((aisleUuid: string, callback?: () => void) => {
        console.log("Duplicating aisle: ", aisleUuid);

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

    const pasteAssetAisleToScene = useCallback((aisle: Aisle, callback?: () => void) => {
        console.log("Pasting aisle: ", aisle);

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

    return {
        addAisleToScene,
        updateAisleInScene,
        removeAisleFromScene,
        duplicateAisleInScene,
        pasteAssetAisleToScene,
    };
}

export default useAisleResponseHandler;
