export default function interiors(globalData: GlobalData) {

    var keyBound = false;
    var interiorId = -1;
    var enterExit = undefined;

    mp.events.add('InteriorManager_ClearHelpText', () => {
        mp.game.ui.clearHelp(true);

        enterExit = undefined;

        if (keyBound) {
            mp.keys.unbind(0x45, false, keyPressHandler);
            keyBound = false;
        }
    });

    mp.events.add('InteriorManager_ShowHelpText', (interior, intId, entEx) => {
        mp.game.ui.setTextComponentFormat('STRING');
        mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um ~b~' + interior + ' ~s~zu ' + (entEx === 0 ? 'betreten' : 'verlassen'));
        mp.game.ui.displayHelpTextFromStringLabel(0, true, true, -1);

        interiorId = intId;
        enterExit = entEx;

        mp.keys.bind(0x45, false, keyPressHandler);
        keyBound = true;
    });

    function keyPressHandler() {
        if (globalData.InChat) return;
        mp.events.callRemote('InteriorManager_UseTeleport', interiorId, enterExit);
    }
}