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

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

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

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

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

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

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

        builderSocket.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") {
            }
        });

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

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

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

        builderSocket.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") {
            }
        });

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

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

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

        builderSocket.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") {
            }
        });

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

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

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

        builderSocket.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") {
            }
        });

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

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

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

        builderSocket.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") {
            }
        });

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

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

    return null;
}

export default BuilderResponses;
