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 drivingSchoolList(globalData: IGlobalData) {

    var drivingMenu: NativeUI.Menu;


    var stage = "";


    //Weapon Menu

    mp.events.add('showDrivingSchoolSelector', () => {
        if (!globalData.InMenu) {

            globalData.InMenu = true;

            drivingMenu = new Menu("Fahrschule", "", new Point(50, 50), null, null);


            drivingMenu.AddItem(new UIMenuListItem("Prüfung", "", new ItemsCollection(["Auto", "Motorrad"])));

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

            drivingMenu.ListChange.on((item, index) => {
                switch (item.Text) {
                    case "Prüfung":
                        stage = String(item.SelectedItem.DisplayText);
                        break;
                }
            });

            drivingMenu.ItemSelect.on((item) => {
                if (item.Text === "Bestätigen") {
                    if (stage == "Auto") {
                        mp.events.callRemote("startDrivingSchool");
                    } else if (stage == "Motorrad") {
                        mp.events.callRemote("startBikeSchool");
                    }
                   
                    drivingMenu.Close();
                    globalData.InMenu = false;
                } else if (item.Text === "Abbrechen") {            
                    drivingMenu.Close();
                    globalData.InMenu = false;
                }
            });

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