import * as CONSTANTS from "../../../types/world/worldConstants";

interface FirstPersonCameraProps {
    setIsTransitioning?: (value: boolean) => void;
    state: any;
}

interface FirstPersonCameraParams extends FirstPersonCameraProps {
    camMode: string;
    setCamMode: (mode: string) => void;
    switchToFirstPerson: (controls: any, camera: any) => Promise<void>;
    switchToThirdPerson: (controls: any, camera: any) => Promise<void>;
}

export async function firstPersonCamera({
    setIsTransitioning,
    state,
    camMode,
    setCamMode,
    switchToFirstPerson,
    switchToThirdPerson
}: FirstPersonCameraParams): Promise<void> {
    setIsTransitioning && setIsTransitioning(true);

    state.controls.mouseButtons.left = CONSTANTS.controlsTransition.leftMouse;
    state.controls.mouseButtons.right = CONSTANTS.controlsTransition.rightMouse;
    state.controls.mouseButtons.wheel = CONSTANTS.controlsTransition.wheelMouse;
    state.controls.mouseButtons.middle = CONSTANTS.controlsTransition.middleMouse;

    if (camMode === "ThirdPerson") {
        setCamMode("FirstPerson");
        await switchToFirstPerson(state.controls, state.camera);
    } else if (camMode === "FirstPerson") {
        setCamMode("ThirdPerson");
        await switchToThirdPerson(state.controls, state.camera);
    }

    setIsTransitioning && setIsTransitioning(false);
}
