import * as NativeUI from '../libs/NativeUI';
import jailList from './criminalrelease';
import InputHelper from '../inputhelper';

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 deleteItem = new UIMenuItem("Entfernen", "Entfernt das Ticket aus der Liste");
deleteItem.BackColor = new Color(42, 46, 49);
let saveItem = new UIMenuItem("Annehmen", "Starte direkten Chat mit dem User");
saveItem.BackColor = new Color(13, 71, 161);
saveItem.HighlightedBackColor = new Color(25, 118, 210);

let sendItem = new UIMenuItem("Absenden", "Sende Report an alle Admins");
sendItem.BackColor = new Color(13, 71, 161);
sendItem.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 reportList(globalData: IGlobalData) {

    var reportMenu: NativeUI.Menu;

    var users;
    var reportTexts;

    var user = "";
    var reportText = "";


    //Weapon Menu

    mp.events.add('showReportMenu', (userTickets, TicketsArr) => {
        if (!globalData.InMenu) {

            globalData.InMenu = true;

            users = JSON.parse(userTickets);
            reportTexts = JSON.parse(userTickets);

            reportMenu = new Menu("Offene Tickets", "", new Point(0, screenRes.y / 3), null, null);

            reportMenu.AddItem(new UIMenuListItem("Ticket", "", new ItemsCollection(reportTexts)));

            reportMenu.AddItem(deleteItem);
            reportMenu.AddItem(saveItem);
            reportMenu.AddItem(cancelItem);
            reportMenu.Visible = true;

            user = users[0];

            reportMenu.ListChange.on((item, index) => {
                switch (item.Text) {
                    case "Ticket":
                        user = String(item.SelectedItem.DisplayText);                        
                        break;
                }
            });

            reportMenu.ItemSelect.on((item) => {
                if (item.Text === "Annehmen") {
                    mp.events.callRemote("acceptReport", user);
                    reportMenu.Close();
                    globalData.InMenu = false;
                } else if (item.Text === "Abbrechen") {
                    reportMenu.Close();
                    globalData.InMenu = false;
                } else if (item.Text === "Entfernen") {
                    mp.events.callRemote("deleteReport", user);
                    reportMenu.Close();
                    globalData.InMenu = false;
                }
            });

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

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

            var type;

            globalData.InMenu = true;
            
            var types = ["Quick Report", "Ticket Report"];

            reportMenu = new Menu("QuickReport/Ticket", "", new Point(0, screenRes.y / 3), null, null);
            var typesItem = new UIMenuListItem("Typ", "", new ItemsCollection(types));
            reportMenu.AddItem(typesItem);

            reportMenu.AddItem(sendItem);
            reportMenu.AddItem(cancelItem);
            reportMenu.Visible = true;

            reportMenu.ItemSelect.on((item) => {
                if (item.Text === "Absenden") {
                    globalData.InMenu = true;
                    var ticketContentBox = new InputHelper("Worin besteht dein Anliegen?", globalData);
                    ticketContentBox.show();
                    ticketContentBox.getValue(data => {

                        var type = typesItem.SelectedItem.DisplayText;

                        var content = JSON.stringify(data);

                        //mp.gui.chat.push(content);
                        //mp.gui.chat.push(type);

                        mp.events.callRemote("requestReport", type, content);
                        mp.events.call("SERVER:CloseReportMenu");
                        reportMenu.Close();
                    });
                    

                    globalData.InMenu = false;
                } else if (item.Text === "Abbrechen") {
                    reportMenu.Close();
                    globalData.InMenu = false;
                }
            });

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

    var textBoxBrowser: BrowserMp;
    var loginCam: CameraMp = mp.cameras.new('login', new mp.Vector3(-1883.736, -781.4911, 78.27616), new mp.Vector3(3.185999, 0, -79.59519), 40);

    var localPlayer: PlayerMp = mp.players.local;

    mp.events.add('textbox', () => {
        mp.gui.cursor.show(true, true);
        mp.gui.chat.show(false);
        mp.game.ui.displayHud(false);
        mp.game.ui.displayRadar(false);

        textBoxBrowser = mp.browsers.new("package://assets/html/SimpleTextBox.html");

        /*
        loginCam.setActive(true);
        mp.game.cam.renderScriptCams(true, false, 0, true, false);
        */
    });


    mp.events.add('report_submitText', (tmp) => {
        
        mp.events.callRemote("requestReport", tmp);
    });

    mp.events.add("SERVER:CloseReportMenu", () => {
        mp.game.ui.clearHelp(true);
        if (reportMenu != null) {
            reportMenu.Close();
        }
    });

}