import game from "..";
import { Key } from "../game";
import { Menu, Point, UIMenuItem } from "../libs/NativeUI";
import { createMenuItem } from "../util";
import moneyformat from "../moneyformat";
var screenRes = mp.game.graphics.getScreenResolution(0, 0);
var menu: Menu = new Menu("Polizeirevier", "Die Hilfestelle der Polizei", new Point(0, screenRes.y / 3));

menu.AddItem(createMenuItem("Waffenschein kaufen", "Erwerbe einen Waffenschein", (item) => {
    item.SetRightLabel("$" + moneyformat(5000));
}));

menu.Close();

menu.ItemSelect.on((item, index: number) => {
    game.events.callServer("PoliceDepartment_MenuSelect", index);
    menu.Close();
});

menu.MenuClose.on(() => {
    game.ui.inMenu = false;
});

game.events.add("SERVER:PoliceDepartment_EnterColShape", () => {
    //game.ui.setHelpText("Drücke ~INPUT_CONTEXT~, um das Menü des Polizeireviers zu öffnen");
    
    mp.events.call("renderHelpTextOnScreen", "~s~Drücke ~g~E~s~ um das Menü des ~b~Polizeireviers ~s~zu öffnen")
    game.events.bindKey(Key.E, false, keyPressHandler);
});

game.events.add("SERVER:PoliceDepartment_ExitColShape", () => {
    game.ui.clearHelpText();
    game.events.unbindKey(Key.E, false, keyPressHandler);

    menu.Close();
});

function keyPressHandler() {
    game.ui.clearHelpText();
    game.ui.inMenu = true;
    menu.Open();
}