#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Opens the admin dialog.
 *
 * Arguments:
 * None
 *
 * Return Value:
 * None
 *
 * Example:
 * [] call forge_client_admin_fnc_openAdmin;
 *
 * Public: Yes
 */

private _productVersion = productVersion;
private _steamBranchName = _productVersion select 8;
private _payGrades = (missionConfigFile >> "CfgPaygrades" >> "payGrades") call BFUNC(getCfgData);

if (_steamBranchName == "profiling") then {
	private _display = (findDisplay 46) createDisplay "RscWebAdmin";
	private _ctrl = _display displayCtrl 2025;

	_ctrl ctrlAddEventHandler ["JSDialog", {
		params ["_control", "_isConfirmDialog", "_message"];
		[QGVAR(handleEvents), [_control, _isConfirmDialog, _message]] call CFUNC(localEvent);
	}];

	_ctrl ctrlWebBrowserAction ["LoadFile", QUOTE(PATHTOF(ui\_site\index.html))];
} else {
	disableSerialization;
	createDialog "RscAdmin";

	private _dialog = findDisplay 202303;
	private _list = _dialog displayCtrl 2023001;
	private _list2 = _dialog displayCtrl 2023003;

	{
		if (str (side _x) == str (playerSide) && isPlayer _x) then {
			private _name = name (_x);
			private _uid = getPlayerUID _x;
			private _payGrade = GETVAR(_x,FORGE_PayGrade,QUOTE(E1));
			private _index = _list lbAdd format["%1 - %2", _name, _payGrade];

			_list lbSetData [_index, _uid];
		};
	} count (allPlayers);

	lbSetCurSel [2023001, 0];

	{
		private _index = _list2 lbAdd format ["%1 - $%2", (_x select 0), ((_x select 1) call EFUNC(misc,formatNumber))];

		_list2 lbSetData [_index, str _x];
	} forEach _payGrades;

	lbSetCurSel [2023003, 0];
	ctrlSetText [2023002, format ["$%1", (companyFunds call EFUNC(misc,formatNumber))]];
};