import { useEffect } from "react";
import { useSocketStore } from "../../../store/builder/store";
import useAssetResponseHandler from "../../builder/asset/responseHandler/useAssetResponseHandler";

function BuilderResponses() {
    const { socket } = useSocketStore();
    const { addAssetToScene, removeAssetFromScene } = useAssetResponseHandler();

    //#region Asset
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:model-asset:response:add", (data: any) => {
            if (!data.message) return;
            if (data.message === "Model created successfully") {
            } else if (data.message === "Updated successfully") {
            }
        });

        socket.on("v1:model-asset:response:delete", (data: any) => {
            if (!data.message) return;
            if (data.message === "Model deleted successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:model-asset:response:add");
                socket.off("v1:model-asset:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    //#region WallAsset
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:wall-asset:response:add", (data: any) => {
            if (!data.message) return;
            if (data.message === "WallAsset Created Successfully") {
            } else if (data.message === "WallAsset Updated Successfully") {
            }
        });

        socket.on("v1:wall-asset:response:delete", (data: any) => {
            if (!data.message) return;
            if (data.message === "WallAsset Created Successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:wall-asset:response:add");
                socket.off("v1:wall-asset:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    //#region Wall
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:model-Wall:response:add", (data: any) => {
            if (!data.message) return;
            if (data.message === "Wall Created Successfully") {
            } else if (data.message === "Wall Updated Successfully") {
            }
        });

        socket.on("v1:model-Wall:response:delete", (data: any) => {
            if (!data.message) return;
            if (data.message === "Wall Deleted Successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:model-Wall:response:add");
                socket.off("v1:model-Wall:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    //#region Floor
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:model-Floor:response:add", (data: any) => {
            if (!data.message) return;
            if (data.message === "Floor Created Successfully") {
            } else if (data.message === "Floor Updated Successfully") {
            }
        });

        socket.on("v1:model-Floor:response:delete", (data: any) => {
            if (!data.message) return;
            if (data.message === "Floor Deleted Successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:model-Floor:response:add");
                socket.off("v1:model-Floor:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    //#region Aisle
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:model-aisle:response:add", (data: any) => {
            if (!data.message) return;
            if (data.message === "Aisle Created Successfully") {
            } else if (data.message === "Aisle Updated Successfully") {
            }
        });

        socket.on("v1:model-aisle:response:delete", (data: any) => {
            if (!data.message) return;
            if (data.message === "Aisle Deleted Successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:model-aisle:response:add");
                socket.off("v1:model-aisle:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    //#region Zone
    useEffect(() => {
        if (!socket) return;

        socket.on("v1:zone:response:updates", (data: any) => {
            console.log("data: ", data);
            if (!data.message) return;
            if (data.message === "zone created successfully") {
            } else if (data.message === "zone updated") {
            }
        });

        socket.on("v1:zone:response:delete", (data: any) => {
            console.log("data: ", data);
            if (!data.message) return;
            if (data.message === "zone deleted created successfully") {
            }
        });

        return () => {
            if (socket) {
                socket.off("v1:zone:response:updates");
                socket.off("v1:zone:response:delete");
            }
        };
    }, [socket]);
    //#endregion

    return null;
}

export default BuilderResponses;
