-- Auto-start Cursor Enhancement
-- This runs AFTER all other cursor files are loaded


-- Wait a bit for everything to be ready
C_Timer.After(1, function()
    
    -- Check if everything exists
    if not AiB_Cursor then
        return
    end
    
    if not AiB_Cursor_CursorFrame then
        return
    end
    
    if not AiB_Cursor.SetupUI then
        return
    end
    
    if not AiB_Cursor.OnInitialize then
        return
    end
    
    
    -- Call OnInitialize
    local success, err = pcall(function()
        AiB_Cursor:OnInitialize()
    end)
    
    if success then
        
        -- Double-check that SetupUI was called
        if AiB_Cursor.GCDCooldownFrame then
                
                -- Apply saved colors
                if AiB_ApplySavedCursorColors then
                    AiB_ApplySavedCursorColors()
                end
                
                -- Apply ring slot settings
                if AiB_Cursor.ApplySettings then
                    AiB_Cursor:ApplySettings()
                end
        else
            AiB_Cursor:SetupUI()
            
            if AiB_Cursor.GCDCooldownFrame then
            else
            end
        end
        
        -- Initialize Settings
        if AiB_Cursor.InitializeSettings then
            AiB_Cursor:InitializeSettings()
        end
        
        
    else
        print(err)
    end
end)

-- Also try after PLAYER_LOGIN (backup)
local loginFrame = CreateFrame("Frame")
loginFrame:RegisterEvent("PLAYER_LOGIN")
loginFrame:SetScript("OnEvent", function()
    C_Timer.After(2, function()
        if not AiB_Cursor.GCDCooldownFrame then
            
            if AiB_Cursor and AiB_Cursor.SetupUI then
                AiB_Cursor:SetupUI()
                if AiB_ApplySavedCursorColors then
                    AiB_ApplySavedCursorColors()
                end
            end
        end
    end)
end)

