#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Shows the email
 *
 * Arguments:
 * None
 *
 * Return Value:
 * None
 *
 * Example:
 * [] call forge_client_phone_fnc_showEmail;
 *
 * Public: Yes
 */

private _metaCtrls = [2023001, 2023002, 2023003];

{
	ctrlShow [_x, true];
	ctrlEnable [_x, true];
} forEach _metaCtrls;

private _ctrl01 = (findDisplay 202300) displayCtrl 202319;
_ctrl01 ctrlRemoveAllEventHandlers "ButtonClick";
_ctrl01 ctrlAddEventHandler ["ButtonClick", {
	_this spawn FUNC(viewEmail);

	ctrlShow [2023001, false];
	ctrlShow [2023002, false];
	ctrlShow [2023003, false];
	ctrlShow [202305, false];
	ctrlShow [202306, false];
}];

ctrlShow [202305, true];
ctrlShow [202306, true];

disableSerialization;

private _control = _this select 0;
private _index = _this select 1;

private _from = _control lbText _index;
private _email = _control lbData _index;
private _data = call compile format["%1", _email];

private _subject = _data select 0;
private _body = _data select 1;

ctrlSetText [202307, "Emails"];
ctrlSetText [202308, "Read your email"];

ctrlSetText [2023001, "FROM"];
ctrlSetText [2023002, _from];
ctrlSetText [2023003, "EMAIL"];
ctrlSetText [202306, _body];

private _ctrl01 = (findDisplay 202300) displayCtrl 202306;

private _ctrl01Pos = ctrlPosition _ctrl01;
private _oldH = _ctrl01Pos select 3;
private _newH = ctrlTextHeight _ctrl01;
private _x = _ctrl01Pos select 0;
private _y = _ctrl01Pos select 1;
private _z = _ctrl01Pos select 2;

_ctrl01 ctrlSetPosition [_x, _y, _z, _newH];
_ctrl01 ctrlCommit 0;