#include "..\script_component.hpp"

if (!hasInterface) exitWith {};

// ACE SELF-INTERACTIONS FOR FILING AND RESCINDING REINSERT REQUESTS NEAR BASE - ALL PLAYERS
localNamespace setVariable [QGVAR(fileForReinsertClassesAdded), []];
// add actions to current class
[["CAManBase"], true] call FUNC(addAceSelfActions);

/////////////////////////////////////////////////////
// PILOTS ONLY
// ACE SELF-INTERACTIONS FOR CHECKING REINSERT QUEUE - ONLY FOR PILOTS
localNamespace setVariable [QGVAR(checkReinsertQueueClassesAdded), []];
localNamespace setVariable [QGVAR(lastReinsertQueueCheck), diag_tickTime];

// add actions to pilot classes, and don't apply to child classes
[["B_Helipilot_F", "B_helicrew_F"], false] call FUNC(addCheckQueueSelfAction);
/////////////////////////////////////////////////////


// ADD TIMER FOR PILOTS - IF REINSERT LIST NOT CHECKED FOR 20 MINUTES, SHOW NOTIFICATION AUTOMATICALLY
if ((typeOf player) in ["B_Helipilot_F", "B_helicrew_F"]) then {
	[{
		// if module not enabled and pilot forced check not enabled, exit
		if (not (
			[QGVAR(setting_enabled)] call CBA_settings_fnc_get and
			[QGVAR(setting_pilotForcedCheckEnabled)] call CBA_settings_fnc_get
		)) exitWith {};

		// if last check was less than X minutes ago, skip
		private _lastCheck = localNamespace getVariable [QGVAR(lastReinsertQueueCheck), diag_tickTime];
		private _requiredCheckInterval = [QGVAR(setting_pilotForcedCheckInterval)] call CBA_settings_fnc_get;
		if (
			diag_tickTime - _lastCheck <
			_requiredCheckInterval
		) exitWith {}; // if last check was less than X minutes ago, skip

		// last check was greater than X minutes ago
		// reset last check time
		localNamespace setVariable [QGVAR(lastReinsertQueueCheck), diag_tickTime];
		// request notification from the server
		call FUNC(requestShowQueue);
	}, 30] call CBA_fnc_addPerFrameHandler;
};
/////////////////////////////////////////////////////

[
	LEVEL_DEBUG,
	QUOTE(COMPONENT),
	"initClient complete",
	[]
] call EFUNC(common,log);

localNamespace setVariable [QGVAR(complete), true];