---@diagnostic disable: undefined-field, undefined-global
---@class Private
local Private = select(2, ...)

local updatePopupWindow

local function OnEvent(_, event, ...)
    if event == "READY_CHECK" then
        local _, _, _, _, _, _, _, instanceID, _, _ = GetInstanceInfo()

        if Private.CheckInstanceID(instanceID) or true then
            if not updatePopupWindow then
                updatePopupWindow = Private:CreatePopupWindowWithButton()

                updatePopupWindow:SetHideOnClickOutside(false)
                updatePopupWindow:SetText(string.format("|cff%sWarning|r|n|nYour addon/auras are outdated!", Private.gs.visual.colorStrings.red))
                updatePopupWindow:SetButtonText(string.format("|cff%sOK|r", Private.gs.visual.colorStrings.green))
                updatePopupWindow:AddCheckButton("Don't show again")
                updatePopupWindow:SetButtonOnClick(
                    function(dontShowAgain)
                        Private:SetNotifyOnReadyCheck(not dontShowAgain)

                        updatePopupWindow.checkButton:SetChecked(false)
                    end
                )
            end

            if WildThingsSavedVars.settings.readyCheckPopup and not Private.upToDate and Private.window and not Private.window:IsShown() then
                updatePopupWindow:Pop()
                updatePopupWindow:SetPoint("CENTER", UIParent, "CENTER", 0, 150)
            end
        end
    end
end

local f = CreateFrame("Frame")
f:RegisterEvent("READY_CHECK")
f:SetScript("OnEvent", OnEvent)
