-- Début du fichier
local addonName = "RaidPlayerExport"; local addon = LibStub("AceAddon-3.0"):GetAddon(addonName); if not addon then return end
SLASH_RaidPLAYEREXPORT1, SLASH_RaidPLAYEREXPORT2 = "/rpe", "/raidplayerexport"

function addon:UpdateRosterCache()
    wipe(self.raidRosterCache)
    if not IsInGroup() then return end
    for i = 1, GetNumGroupMembers() do
        local name, _, _, _, _, classFileName = GetRaidRosterInfo(i)
        if name then
            local cleanName = name:gsub("-.*", "")
            self.raidRosterCache[cleanName] = classFileName
        end
    end
end

function addon:TogglePlayerListFrame()
    local playerList = self.frames.playerListFrame
    playerList:SetShown(not playerList:IsShown())
    if playerList:IsShown() then
        self:UpdateRaidList()
        -- On met le texte en jaune (1,1,0 = R,G,B)
        self.frames.hub.playerListButton:GetFontString():SetTextColor(1, 1, 0)
    else
        -- On remet le texte en blanc (1,1,1 = R,G,B)
        self.frames.hub.playerListButton:GetFontString():SetTextColor(1, 1, 1)
    end
end

function addon:ToggleLootHistoryFrame()
    local show = not self.frames.loot:IsShown()
    self.frames.loot:SetShown(show)
    self.frames.filter:SetShown(show)
    if show then
        self.lootFilter = date("%d/%m/%Y")
        self:UpdateLootHistoryDisplay()
        self.frames.hub.lootHistoryButton:GetFontString():SetTextColor(1, 1, 0)
    else
        self.frames.hub.lootHistoryButton:GetFontString():SetTextColor(1, 1, 1)
    end
end

function addon:ToggleWindows() 
    local hub = self.frames.hub
    if hub:IsShown() then 
        hub:Hide()
    else
        hub:Show()
        self:UpdateRaidList()
    end 
end

function SlashCmdHandler(msg) 
    addon:ToggleWindows() 
end
SlashCmdList["RaidPLAYEREXPORT"] = SlashCmdHandler

local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")

eventFrame:SetScript("OnEvent", function(self, event, ...)
    if event == "ADDON_LOADED" then 
        local loadedAddonName = ...; 
        if loadedAddonName == addonName then 
            addon:CreateFrames();
            addon:UpdateRosterCache() 
            local LDB = LibStub("LibDataBroker-1.1"); 
            local LibDBIcon = LibStub("LibDBIcon-1.0"); 
            local dataObject = LDB:NewDataObject(addonName, { 
                type = "launcher", label = "RaidPlayerExport", icon = "Interface/AddOns/"..addonName.."/Media/Logo/Logo.tga", 
                OnClick = function(_, button)
                    if button == "LeftButton" then addon:ToggleWindows()
                    elseif button == "RightButton" then LibStub("AceConfigDialog-3.0"):Open(addonName) end
                end, 
                OnTooltipShow = function(tooltip) tooltip:AddLine("RaidPlayerExport"); tooltip:AddLine("Clic-droit pour les options.") end, 
            }); 
            LibDBIcon:Register(addonName, dataObject, addon.db.profile.minimap); 
            eventFrame:UnregisterEvent("ADDON_LOADED") 
        end
    elseif event == "GROUP_ROSTER_UPDATE" then
        addon:UpdateRosterCache()
        if addon.frames.hub and addon.frames.hub:IsShown() then
            addon:UpdateRaidList()
        end
    end
end)
-- Fin du fichier