import * as NativeUI from '../libs/NativeUI';

const Menu = NativeUI.Menu;
const UIMenuItem = NativeUI.UIMenuItem;
const UIMenuListItem = NativeUI.UIMenuListItem;
const UIMenuCheckboxItem = NativeUI.UIMenuCheckboxItem;
const BadgeStyle = NativeUI.BadgeStyle;
const Point = NativeUI.Point;
const ItemsCollection = NativeUI.ItemsCollection;
const Color = NativeUI.Color;

let screenRes = mp.game.graphics.getScreenResolution(0, 0);
let saveItem = new UIMenuItem("Bestätigen", "");
saveItem.BackColor = new Color(13, 71, 161);
saveItem.HighlightedBackColor = new Color(25, 118, 210);

let cancelItem = new UIMenuItem("Abbrechen", "");
cancelItem.BackColor = new Color(213, 0, 0);
cancelItem.HighlightedBackColor = new Color(229, 57, 53);

export default function elevatorList(globalData: IGlobalData) {
    var elevatorMenu: NativeUI.Menu;

    var stages;

    var stage = "";

    //Weapon Menu

    mp.events.add('showElevatorMenu', (stagesArr) => {
        if (!globalData.InMenu) {
            globalData.InMenu = true;

            stages = JSON.parse(stagesArr);

            elevatorMenu = new Menu("Aufzug", "", new Point(50, 50), null, null);

            elevatorMenu.AddItem(new UIMenuListItem("Stock", "", new ItemsCollection(stages)));

            elevatorMenu.AddItem(saveItem);
            elevatorMenu.AddItem(cancelItem);
            elevatorMenu.Visible = true;

            elevatorMenu.ListChange.on((item, index) => {
                switch (item.Text) {
                    case "Stock":
                        stage = String(item.SelectedItem.DisplayText);
                        break;
                }
            });

            elevatorMenu.ItemSelect.on((item) => {
                if (item.Text === "Bestätigen") {
                    mp.events.callRemote("sendClientToStage", stage);
                    elevatorMenu.Close();
                    globalData.InMenu = false;
                } else if (item.Text === "Abbrechen") {
                    elevatorMenu.Close();
                    globalData.InMenu = false;
                }
            });

            elevatorMenu.MenuClose.on(() => {
                globalData.InMenu = false;
            });
        }
    });
}