#include "..\script_component.hpp"

/*
 * Function: forge_store_fnc_openStore
 * Author: J. Schmidt
 *
 * Description:
 * Opens the store.
 *
 * Arguments:
 * 0: Store <OBJECT> - The store object
 *
 * Return Value:
 * None
 *
 * Example:
 * [storeObject] call forge_store_fnc_openStore
 *
 * Public: No
 */

params [["_store", objNull, [objNull]]];

if (isNull _store) exitWith {};

disableSerialization;
createDialog "RscStoreDialog";

private _display = findDisplay IDD_STOREDIALOG;
private _categoryList = _display displayCtrl IDC_CATEGORYLIST;
private _paymentList = _display displayCtrl IDC_PAYMENTLIST;
private _storeName = _display displayCtrl IDC_DIALOGNAME;
private _data = _store getVariable ["storeData", []];

_data params [["_categories", [], [[]]], ["_products", [], [[]]], ["_name", "", [""]], ["_paymentMethods", [], [[]]]];

GVAR(currentStore) = _data;
_storeName ctrlSetText _name;

{
    private _index = _categoryList lbAdd _x;
    _categoryList lbSetData [_index, _x];
} forEach _categories;
_categoryList lbSetCurSel 0;

{
    private _payment = _x select 0;
    private _index = _paymentList lbAdd _payment;
    _paymentList lbSetData [_index, format ["%1", _x]];
} forEach _paymentMethods;
_paymentList lbSetCurSel 0;