---@diagnostic disable: duplicate-doc-alias ---@diagnostic disable: duplicate-doc-field ---@type promise? local alert = nil local alertId = 0 ---@class AlertDialogProps ---@field header string; ---@field content string; ---@field centered? boolean?; ---@field size? 'xs' | 'sm' | 'md' | 'lg' | 'xl'; ---@field overflow? boolean?; ---@field cancel? boolean?; ---@field labels? {cancel?: string, confirm?: string} ---@param data AlertDialogProps ---@param timeout? number Force the window to timeout after `x` milliseconds. ---@return 'cancel' | 'confirm' | nil function AlertDialog(data, timeout) if alert then return end local id = alertId + 1 alertId = id alert = promise.new() Utils.setNuiFocus(false) SendNUIMessage({ action = 'sendAlert', data = data }) if timeout then SetTimeout(timeout, function() if id == alertId then CloseAlertDialog('timeout') end end) end return Citizen.Await(alert) end ---@param reason? string An optional reason for the window to be closed. function CloseAlertDialog(reason) if not alert then return end Utils.resetNuiFocus() SendNUIMessage({ action = 'closeAlertDialog' }) local p = alert alert = nil if reason then p:reject(reason) else p:resolve() end end RegisterNUICallback('closeAlert', function(data, cb) cb(1) Utils.resetNuiFocus() local promise = alert --[[@as promise]] alert = nil promise:resolve(data) end) RegisterNetEvent('ox_lib:alertDialog', AlertDialog)