#include "..\script_component.hpp"

/*
 * Function: forge_store_fnc_handleDelivery
 * Description:
 * Handles the delivery timer and locker updates for purchased items
 *
 * Parameters:
 * 0: New Locker Contents <ARRAY>
 *
 * Returns:
 * None
 *
 * Example:
 * [_newLocker] spawn forge_store_fnc_handleDelivery
 */

params [["_newLocker", [], [[]]]];

private _deliveryTime = ["DT", 0] call BIS_fnc_getParamValue;

if (_newLocker isEqualTo []) exitWith {};
if (_deliveryTime > 0) then {
    [
        format [
            "<t align='left'>Order Processing</t><br/><t size='0.8' align='left'>Estimated delivery: %1</t>", 
            [_deliveryTime, "MM:SS"] call BIS_fnc_secondsToString
        ],
        "info",
        3,
        "right"
    ] call EFUNC(misc,notify);

    uiSleep (_deliveryTime / 2);

    [
        "<t align='left'>Package in transit</t>",
        "warning",
        2,
        "left"
    ] call EFUNC(misc,notify);
    
    uiSleep (_deliveryTime / 2);

    SETPVAR(player,FORGE_Locker,_newLocker);

    [
        "<t align='left'>Order Delivered!</t><br/><t size='0.8' align='left'>Check your locker</t>",
        "success",
        5,
        "left"
    ] call EFUNC(misc,notify);
    
    if (hasInterface) then { playSound "FD_Finish_F"; };
} else {
    SETPVAR(player,FORGE_Locker,_newLocker);
    
    [
        "<t align='left'>Order Complete!</t><br/><t size='0.8' align='left'>Items added to locker</t>",
        "success",
        5,
        "left"
    ] call EFUNC(misc,notify);

    if (hasInterface) then { playSound "FD_Finish_F"; };
};