#include "..\script_component.hpp"

private _display = findDisplay IDD_BANKDIALOG;
private _input = _display displayCtrl IDC_AMOUNTINPUT;
private _dropdown = _display displayCtrl IDC_PLAYERINPUT;
private _amount = parseNumber (ctrlText _input);
private _selectedTarget = lbCurSel _dropdown;
private _selectedTargetData = _dropdown lbData _selectedTarget;
private _target = objectFromNetId _selectedTargetData;

// private _bank = player getVariable ["FORGE_Bank", 0];
// private _targetBank = _target getVariable ["FORGE_Bank", 0];
private _bank = GETVAR(player,FORGE_Bank,0);
private _targetBank = GETVAR(_target,FORGE_Bank,0);

if (!isNull _target && _amount > 0 && _amount <= _bank) then {
    _targetBank = _targetBank + _amount;
    // _target setVariable ["FORGE_Bank", _targetBank, true];
    SETPVAR(_target,FORGE_Bank,_targetBank);

    _bank = _bank - _amount;
    // player setVariable ["FORGE_Bank", _bank, true];
    SETPVAR(player,FORGE_Bank,_bank);

    // [] call forge_client_bank_fnc_refresh;
    [] call FUNC(refresh);
    // hint format ["Transferred $%1", _amount];
    [format ["Transferred $%1", _amount], "info", 3, "right"] call EFUNC(misc,notify);
} else {
    // hint "Invalid transfer details";
    [format ["Invalid transfer details"], "warning", 3, "right"] call EFUNC(misc,notify);
};