#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Fetches the player's gear
 *
 * Arguments:
 * N/A
 *
 * Return Value:
 * N/A
 *
 * Examples:
 * [] call forge_client_locker_fnc_fetchPlayer;
 *
 * Public: Yes
 */

private _display = findDisplay IDD_LOCKERDIALOG;
private _itemList = _display displayCtrl IDC_PLAYEREQUIPMENTLIST;
private _data = [];

_data pushBack ["backpack", backpack player];
_data pushBack ["facewear", goggles player];
_data pushBack ["headgear", headgear player];
_data pushBack ["hmd", hmd player];
_data pushBack ["uniform", uniform player];
_data pushBack ["vest", vest player];
_data pushBack ["weapon", primaryWeapon player];
_data pushBack ["weapon", secondaryWeapon player];
_data pushBack ["weapon", handgunWeapon player];

{
    _data pushBack ["item", _x];
} forEach (assignedItems player + items player);

{
    private _magClass = _x select 0;
    private _ammoCount = _x select 1;
    private _magLocation = _x select 4;
    private _ammoFull = getNumber (configFile >> "CfgMagazines" >> _magClass >> "count");

    if (_magLocation in ["Uniform", "Vest", "Backpack"]) then {
        _data pushBack ["magazine", [_magClass, _ammoCount, _ammoFull, _magLocation]];
    };
} forEach (magazinesAmmoFull player);

_data = _data select { !(_x in [["backpack", ""], ["facewear", ""], ["headgear", ""], ["hmd", ""], ["item", ""], ["magazine", ""], ["uniform", ""], ["vest", ""], ["weapon", ""]]) };

{
    _x params ["_itemType", "_item"];
    private _index = -1;

    switch (_itemType) do {
        case "backpack": {
            private _displayName = getText (configFile >> "CfgVehicles" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgVehicles" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "facewear": {
            private _displayName = getText (configFile >> "CfgGlasses" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgGlasses" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "headgear": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "hmd": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "item": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "magazine": {
            private _displayName = format ["%1 (%2/%3) [%4]", getText (configFile >> "CfgMagazines" >> (_item select 0) >> "displayName"), (_item select 1), (_item select 2),  (_item select 3)];
            private _picture = getText (configFile >> "CfgMagazines" >> (_item select 0) >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "uniform": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "vest": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
        case "weapon": {
            private _displayName = getText (configFile >> "CfgWeapons" >> _item >> "displayName");
            private _picture = getText (configFile >> "CfgWeapons" >> _item >> "picture");

            _index = _itemList lbAdd _displayName;
            _itemList lbSetData [_index, str [_itemType, _item]];
            _itemList lbSetPicture [_index, _picture];
        };
    };
} forEach _data;