-- Apply Settings Function for Cursor
-- Called when settings change

function AiB_Cursor:ApplySettings()
    
    -- Create config if it doesn't exist yet
    if not AiB_CursorConfig then
        AiB_CursorConfig = {
            enabled = true,
            scale = 1.0,
            transparency = 1.0,
            showOnlyInCombat = false,
            colors = {
                mainRing = {r = 1.0, g = 1.0, b = 1.0},
                gcdRing = {r = 1.0, g = 1.0, b = 0.0},
                castRing = {r = 1.0, g = 0.8, b = 0.0},
                trail = {r = 1.0, g = 1.0, b = 1.0},
            }
        }
    end
    
    -- CHECK ENABLED STATE - Show/Hide entire cursor!
    if AiB_Cursor_CursorFrame then
        if AiB_CursorConfig.enabled then
            AiB_Cursor_CursorFrame:Show()
        else
            AiB_Cursor_CursorFrame:Hide()
            return -- Don't apply other settings if disabled
        end
    end
    
    -- Apply scale
    if AiB_CursorConfig.scale then
        self:SetGroupScale(AiB_CursorConfig.scale)
    end
    
    -- Apply transparency
    if AiB_Cursor_CursorFrame then
        local transparency = AiB_CursorConfig.transparency or 1.0
        AiB_Cursor_CursorFrame:SetAlpha(transparency)
    end
    
    -- HIDE Health/Power rings - we don't use them anymore
    if self.HealthFrame then 
        self.HealthFrame:Hide() 
    end
    if self.HealthBackgroundFrame then 
        self.HealthBackgroundFrame:Hide() 
    end
    if self.PowerFrame then 
        self.PowerFrame:Hide() 
    end
    
    -- Main Ring - ALWAYS visible at 70px (MIDDLE - wie Original mainRing slot)
    if AiB_Cursor_CursorFrame and AiB_Cursor_CursorFrame.MainRing then
        AiB_Cursor_CursorFrame.MainRing:SetSize(70, 70)
        AiB_Cursor_CursorFrame.MainRing:Show()
    end
    
    -- GCD Ring - ENABLED but HIDDEN at 50px (INNER - wie Original innerRing slot)
    if self.GCDCooldownFrame then
        self.GCDCooldownFrame:SetSize(50, 50)
        self.GCDCooldownFrame:Hide()  -- HIDDEN until GCD!
        self.enableGCD = true
    else
    end
    if self.GCDBackgroundFrame then
        self.GCDBackgroundFrame:SetSize(50, 50)
        self.GCDBackgroundFrame:Hide()  -- HIDDEN until GCD!
    else
    end
    
    -- Cast Ring - ALWAYS enabled at 90px (OUTER)
    if self.CastFrame then
        self.CastFrame:SetSize(90, 90)
        self.CastFrame:Hide()  -- HIDDEN until casting!
        self.enableCast = true
    else
    end
    if self.CastBackgroundFrame then
        self.CastBackgroundFrame:SetSize(90, 90)
        self.CastBackgroundFrame:Hide()  -- HIDDEN until casting!
    else
    end
    
    -- Register events
    if self.TrackerFrame then
        -- GCD events
        self.TrackerFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
        
        -- Cast events
        self.TrackerFrame:RegisterEvent("UNIT_SPELLCAST_START")
        self.TrackerFrame:RegisterEvent("UNIT_SPELLCAST_STOP")
        self.TrackerFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
        self.TrackerFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
    end
    
    -- Update colors
    if self.UpdateRingColors then
        self:UpdateRingColors()
    end
    
    -- Update visibility (combat check)
    if self.UpdateVisibility then
        self:UpdateVisibility()
    end
    
end

