import { TicksPerSecond, system, world } from "@minecraft/server";
import FSEntityHelper from "../fs/FSEntityHelper";
import CameraManager from "../CameraManager";
import FSEntityPerms from "../fs/libs/perms/FSEntityPerms";
import FSLocalizedString from "../fs/FSLocalizedString";
import { COMPUTER_MONITOR_ACCESS_SCREEN_TIME, COMPUTER_MONITOR_RESET_TIME } from "../fs/FSConstants";
import FSUtil from "../fs/FSUtil";
export var ComputerMonitorScreen;
(function (ComputerMonitorScreen) {
    ComputerMonitorScreen["Screensaver"] = "screensaver";
    ComputerMonitorScreen["Static"] = "static";
    ComputerMonitorScreen["Locked"] = "locked";
    ComputerMonitorScreen["Denied"] = "denied";
    ComputerMonitorScreen["Allowed"] = "allowed";
    ComputerMonitorScreen["CameraOutside"] = "camera_outside";
    ComputerMonitorScreen["CameraNether"] = "camera_nether";
    ComputerMonitorScreen["CameraEnd"] = "camera_end";
    ComputerMonitorScreen["CameraSnow"] = "camera_snow";
    ComputerMonitorScreen["CameraCave"] = "camera_cave";
})(ComputerMonitorScreen || (ComputerMonitorScreen = {}));
export default class ComputerMonitor {
    static init(entity, spawnCause) {
        FSEntityHelper.snapRotation(entity);
        ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Static);
        system.runTimeout(() => {
            ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Locked);
            system.runTimeout(() => {
                ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Screensaver);
            }, TicksPerSecond * COMPUTER_MONITOR_RESET_TIME);
        }, TicksPerSecond * COMPUTER_MONITOR_ACCESS_SCREEN_TIME);
    }
    static setScreen(entity, screen) {
        try {
            if (entity.isValid()) {
                entity.setProperty("property:fs_sbunk_screen", screen);
                world.playSound("57d_sbunk.computer_monitor_button", entity.location);
                system.runTimeout(() => {
                    let wso = {
                        volume: 1,
                        pitch: 1
                    };
                    switch (screen) {
                        case ComputerMonitorScreen.Static: {
                            wso.pitch = 0.75 + FSUtil.random(-0.25, 0.25);
                            wso.volume = 0.5;
                            world.playSound("57d_sbunk.computer_monitor_static", entity.location, wso);
                            break;
                        }
                        case ComputerMonitorScreen.Allowed: {
                            wso.volume = 0.5;
                            world.playSound("fs.sbunk.access_granted", entity.location, wso);
                            break;
                        }
                        case ComputerMonitorScreen.Locked: {
                            wso.volume = 0.5;
                            world.playSound("57d_sbunk.computer_monitor_lock", entity.location, wso);
                            break;
                        }
                    }
                }, 5);
            }
        }
        catch (error) { }
    }
    static onInteract(entity, player) {
        const levelAccess = FSEntityPerms.getEntityPermission(entity);
        const canShow = CameraManager.sharedInstance().canShowCameraDialogue([levelAccess], false);
        if (!canShow) {
            const msg = {
                translate: FSLocalizedString.localize("computer_monitor.warning.no_cameras_found", "§l§c[!]§r No cameras found with access level: %s", "Hint for entering the bunker"),
                with: [`${FSEntityPerms.accessLevelName(levelAccess, true)}`]
            };
            player.playSound("fs.sbunk.chat_ping");
            player.sendMessage(msg);
        }
        else {
            ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Allowed);
            ComputerMonitor.outputAccessingCameraActionBar(player, 0);
            system.runTimeout(() => {
                ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Static);
                ComputerMonitor.outputAccessingCameraActionBar(player, 1);
                system.runTimeout(() => {
                    ComputerMonitor.outputAccessingCameraActionBar(player, 2);
                    if (player.isValid()) {
                        CameraManager.sharedInstance().showCameraDialogue(player, [levelAccess], false);
                    }
                }, TicksPerSecond * COMPUTER_MONITOR_ACCESS_SCREEN_TIME);
                system.runTimeout(() => {
                    ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Screensaver);
                }, TicksPerSecond * COMPUTER_MONITOR_RESET_TIME);
            }, TicksPerSecond * COMPUTER_MONITOR_ACCESS_SCREEN_TIME);
        }
    }
    static outputAccessingCameraActionBar(player, state) {
        const meter = state === 0 ? "§e█░░" : state === 1 ? "§6██░" : "§a███";
        const message = {
            rawtext: [
                { text: "§a[!] §r" },
                {
                    translate: FSLocalizedString.localize("entity.computer_monitor.accessing_cameras", "Accessing Cameras: ", "Feedback to the player popping the entity.")
                },
                {
                    text: meter
                }
            ]
        };
        player.onScreenDisplay.setActionBar(message);
        player.playSound("57d_sbunk.computer_monitor_next_screen");
    }
    static onDeny(entity) {
        world.sendMessage({ translate: FSLocalizedString.localize("chat.computer_monitor.access_denied", "§c[!] Access Denied", "Access Denied") });
        ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Denied);
        system.runTimeout(() => {
            ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Locked);
            system.runTimeout(() => {
                ComputerMonitor.setScreen(entity, ComputerMonitorScreen.Screensaver);
            }, TicksPerSecond * COMPUTER_MONITOR_RESET_TIME);
        }, TicksPerSecond * COMPUTER_MONITOR_ACCESS_SCREEN_TIME);
    }
    static onKilled(entity) { }
}

//# sourceMappingURL=../../../../_SBUNK_BPDebug/fs_sbunk/entity/ComputerMonitor.js.map
