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("Entlassen", "Setze den Gefangenen auf freiem Fuß");
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 jailList(globalData: IGlobalData) {

    var jailMenu: NativeUI.Menu;

    var prisoners;

    var prisoner = "";


    //Weapon Menu

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

            globalData.InMenu = true;

            prisoners = JSON.parse(prisonersArr);

            jailMenu = new Menu("Gefängnis PC", "", new Point(0, screenRes.y / 3), null, null);

            jailMenu.AddItem(new UIMenuListItem("Gefangener", "", new ItemsCollection(prisoners)));

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

            jailMenu.ListChange.on((item, index) => {
                switch (item.Text) {
                    case "Gefangener": 
                    prisoner = String(item.SelectedItem.DisplayText);
                    break;
                }
            });

            jailMenu.ItemSelect.on((item) => {
                if (item.Text === "Entlassen") {
                    mp.events.callRemote("setPrisonerFree", prisoner);
                    jailMenu.Close();
                    globalData.InMenu = false;
                } else if (item.Text === "Abbrechen") {
                    jailMenu.Close();
                    globalData.InMenu = false;
                }
            });

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