local MythicMateNS = _G.MythicMate
if not MythicMateNS then return end

MythicMateNS.HeaderFilters = MythicMateNS.HeaderFilters or {}
local HeaderFilters = MythicMateNS.HeaderFilters

function HeaderFilters.CycleTypeFilter(current)
    if current == "Raid" then
        return "Dungeon"
    elseif current == "Dungeon" then
        return "Mythic"
    elseif current == "Mythic" then
        return "ALL"
    else
        return "Raid"
    end
end

function HeaderFilters.GetBossHeaderBaseText(activeTab)
    if activeTab == "SHARED" then
        return "Locked by"
    elseif activeTab == "MPLUS" then
        return "Key level"
    elseif activeTab == "KEYSTONE" then
        return "Key"
    end
    return "Progress"
end

function HeaderFilters.GetDiffHeaderBaseText(activeTab)
    if activeTab == "PLAYERS" then
        return "Category"
    elseif activeTab == "MPLUS" then
        return "Info"
    elseif activeTab == "KEYSTONE" then
        return "Dungeon"
    end
    return "Type"
end

function HeaderFilters.GetResetHeaderBaseText(activeTab)
    if activeTab == "SHARED" then
        return "Available by"
    elseif activeTab == "KEYSTONE" then
        return "Seen"
    end
    return "Reset In"
end

function HeaderFilters.UpdateHeaderFilterText(activeTab, filters, bossHeader, resetHeader, diffHeader)
    if not filters or not activeTab then return end
    if activeTab == "MPLUS" or activeTab == "KEYSTONE" then return end

    local fh = filters[activeTab]
    if not fh then return end

    local bossBase = HeaderFilters.GetBossHeaderBaseText(activeTab)
    local diffBase = HeaderFilters.GetDiffHeaderBaseText(activeTab)
    local resetBase = HeaderFilters.GetResetHeaderBaseText(activeTab)

    local bossSuffix = fh.hideLocked and " (Avail only)" or ""
    local resetSuffix = fh.hideLocked and " (Avail only)" or ""
    local tf = fh.typeFilter or "ALL"
    local diffSuffix = (tf and tf ~= "ALL") and (" (" .. tf .. ")") or ""

    if activeTab == "SHARED" then
        if bossHeader and bossHeader.SetText then
            bossHeader:SetText(bossBase)
        end
        if resetHeader and resetHeader.SetText then
            resetHeader:SetText(resetBase .. resetSuffix)
        end
    else
        if bossHeader and bossHeader.SetText then
            bossHeader:SetText(bossBase .. bossSuffix)
        end
        if resetHeader and resetHeader.SetText then
            resetHeader:SetText(resetBase)
        end
    end
    if diffHeader and diffHeader.SetText then
        diffHeader:SetText(diffBase .. diffSuffix)
    end
end
