params ["_vic"];


_vicDispName = configOf _vic call BIS_fnc_displayName;
private _thisArr = [];

// _thisArr pushBack getItemCargo _vic;
// _thisArr pushBack getBackpackCargo _vic;
// _thisArr pushBack getMagazineCargo _vic;
// _thisArr pushBack getWeaponCargo _vic;

private _ItemCargo = [];
private _MagazineCargo = [];
private _WeaponCargo = [];
private _BackpackCargo = [];

{
	private _config = _x call CBA_fnc_getItemConfig;
	_ItemCargo pushBack [
		getText (_config >> "displayName"),
		getText (_config >> "picture")
	];
} forEach ItemCargo _vic;
{
	private _config = _x call CBA_fnc_getItemConfig;
	_MagazineCargo pushBack [
		getText (_config >> "displayName"),
		getText (_config >> "picture")
	];
} forEach MagazineCargo _vic;
{
	// private _config = _x call CBA_fnc_getObjectConfig;
	_WeaponCargo pushBack [
		getText (configFile >> "CfgWeapons" >> _x >> "displayName"),
		getText (configFile >> "CfgWeapons" >> _x >> "picture")
	];
} forEach WeaponCargo _vic;
{
	private _config = _x call CBA_fnc_getObjectConfig;
	_BackpackCargo pushBack [
		getText (_config >> "displayName"),
		getText (_config >> "picture")
	];
} forEach BackpackCargo _vic;

private _sortedItemCargo = ([_ItemCargo call BIS_fnc_consolidateArray, [], {_x # 0 # 0}] call BIS_fnc_sortBy) select {!(_x # 0 # 0 isEqualTo "")};
private _sortedMagazineCargo = ([_MagazineCargo call BIS_fnc_consolidateArray, [], {_x # 0 # 0}] call BIS_fnc_sortBy) select {!(_x # 0 # 0 isEqualTo "")};
private _sortedWeaponCargo = ([_WeaponCargo call BIS_fnc_consolidateArray, [], {_x # 0 # 0}] call BIS_fnc_sortBy) select {!(_x # 0 # 0 isEqualTo "")};
private _sortedBackpackCargo = ([_BackpackCargo call BIS_fnc_consolidateArray, [], {_x # 0 # 0}] call BIS_fnc_sortBy) select {!(_x # 0 # 0 isEqualTo "")};

// "debug_console" callExtension(str _sortedItemCargo + "~0100");
// "debug_console" callExtension(str _sortedMagazineCargo + "~0100");
// "debug_console" callExtension(str _sortedWeaponCargo + "~0100");
// "debug_console" callExtension(str _sortedBackpackCargo + "~0100");

if (count _sortedItemCargo > 0) then {
	_thisArr pushBack format["<font color='#ffffff' size='12' face='PuristaMedium'>Items:</font>"];
	private _itemCargoOut = [];
	{
		private _name = _x # 0 # 0;
		private _pic = _x # 0 # 1;
		private _count = _x # 1;
		if (_pic == "") then {
			_itemCargoOut pushBack format["<font color='#ffffff' size='12' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>%3 x%2</execute></font>", _pic, _count, _name];
		} else {
			_itemCargoOut pushBack format["<img height='30' image='%1'/><font color='#ffffff' size='10' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>x%2</execute></font>", _pic, _count, _name];
		};
		if ((_forEachIndex + 1) mod 6 == 0) then {_itemCargoOut pushBack "<br/>"};
	} forEach _sortedItemCargo;
	_thisArr pushBack (_itemCargoOut joinString "");
};
if (count _sortedMagazineCargo > 0) then {
	_thisArr pushBack format["<font color='#ffffff' size='12' face='PuristaMedium'>Magazines:</font>"];
	private _magCargoOut = [];
	{
		private _name = _x # 0 # 0;
		private _pic = _x # 0 # 1;
		private _count = _x # 1;
		if (_pic == "") then {
			_magCargoOut pushBack format["<font color='#ffffff' size='12' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>%3 x%2</execute></font>", _pic, _count, _name];
		} else {
			_magCargoOut pushBack format["<img height='30' image='%1'/><font color='#ffffff' size='10' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>x%2</execute></font>", _pic, _count, _name];
		};
		if ((_forEachIndex + 1) mod 6 == 0) then {_magCargoOut pushBack "<br/>"};
	} forEach _sortedMagazineCargo;
	_thisArr pushBack (_magCargoOut joinString "");
};
if (count _sortedWeaponCargo > 0) then {
	_thisArr pushBack format["<font color='#ffffff' size='12' face='PuristaMedium'>Weapons:</font>"];
	private _weaponCargoOut = [];
	{
		private _name = _x # 0 # 0;
		private _pic = _x # 0 # 1;
		private _count = _x # 1;
		if (_pic == "") then {
			_weaponCargoOut pushBack format["<font color='#ffffff' size='12' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>%3 x%2</execute></font>", _pic, _count, _name];
		} else {
			_weaponCargoOut pushBack format["<img height='50' image='%1'/><font color='#ffffff' size='10' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>x%2</execute></font>", _pic, _count, _name];
		};
		if ((_forEachIndex + 1) mod 3 == 0) then {_weaponCargoOut pushBack "<br/>"};
	} forEach _sortedWeaponCargo;
	_thisArr pushBack (_weaponCargoOut joinString "");
};
if (count _sortedBackpackCargo > 0) then {
	_thisArr pushBack format["<font color='#ffffff' size='12' face='PuristaMedium'>Backpacks:</font>"];
	private _backpackCargoOut = [];
	{
		private _name = _x # 0 # 0;
		private _pic = _x # 0 # 1;
		private _count = _x # 1;
		if (_pic == "") then {
			_backpackCargoOut pushBack format["<font color='#ffffff' size='12' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>%3 x%2</execute></font>", _pic, _count, _name];
		} else {
			_backpackCargoOut pushBack format["<img height='50' image='%1'/><font color='#ffffff' size='10' face='EtelkaMonospacePro'><execute expression='systemChat ""%3"";'>x%2</execute></font>", _pic, _count, _name];
		};
		if ((_forEachIndex + 1) mod 4 == 0) then {_backpackCargoOut pushBack "<br/>"};
	} forEach _sortedBackpackCargo;
	_thisArr pushBack (_backpackCargoOut joinString "");
	// "debug_console" callExtension(str _backpackCargoOut + "~0100");
};

// "debug_console" callExtension(str _thisArr + "~1100");
_thisArr;