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

function useZoneResponseHandler() {
    const { zoneStore } = useSceneContext();
    const { addZone, updateZone, removeZone } = zoneStore();

    const addZoneToScene = useCallback(
        (zone: Zone, callback?: () => void) => {
            addZone(zone);

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

    const updateZoneInScene = useCallback(
        (zone: Zone, callback?: () => void) => {
            updateZone(zone.zoneUuid, zone);

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

    const removeZoneFromScene = useCallback(
        (zoneUuid: string, callback?: () => void) => {
            removeZone(zoneUuid);

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

    const duplicateZoneInScene = useCallback((zoneUuid: string, callback?: () => void) => {
        console.log("Duplicating zone: ", zoneUuid);

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

    const pasteAssetZoneToScene = useCallback((zone: Zone, callback?: () => void) => {
        console.log("Pasting zone: ", zone);

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

    return {
        addZoneToScene,
        updateZoneInScene,
        removeZoneFromScene,
        duplicateZoneInScene,
        pasteAssetZoneToScene,
    };
}

export default useZoneResponseHandler;
