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

-- Initialisation des variables de l'addon pour les fenêtres
addon.frames = {}
addon.FRAME_HEIGHT = 550
addon.FRAME_WIDTH_MAIN = 320
addon.FRAME_WIDTH_LOOT = 450
addon.FRAME_SPACING = 10

-- Fonction qui crée tous les éléments graphiques de l'addon
function addon:CreateFrames()
    local container = CreateFrame("Frame", "RPEContainerFrame", UIParent); container:SetSize(self.FRAME_WIDTH_MAIN, self.FRAME_HEIGHT); container:SetPoint("CENTER"); container:SetMovable(true); container:EnableMouse(true); container:SetClampedToScreen(true); container:Hide(); self.frames.container = container
    local mainFrame = CreateFrame("Frame", "RaidPlayerExportFrame", container, "BackdropTemplate"); mainFrame:SetSize(self.FRAME_WIDTH_MAIN, self.FRAME_HEIGHT); mainFrame:SetPoint("TOPLEFT"); mainFrame:EnableMouse(true); mainFrame:RegisterForDrag("LeftButton"); mainFrame:SetScript("OnDragStart", function(self) self:GetParent():StartMoving() end); mainFrame:SetScript("OnDragStop", function(self) self:GetParent():StopMovingOrSizing() end); mainFrame:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/DialogFrame/UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } }); mainFrame:SetBackdropColor(0.1, 0.1, 0.1, 0.95); self.frames.main = mainFrame
    local closeButton = CreateFrame("Button", nil, mainFrame, "UIPanelCloseButton"); closeButton:SetPoint("TOPRIGHT", -6, -6); closeButton:SetScript("OnClick", function() container:Hide() end)
    
    -- Bouton d'options
    local optionsButton = CreateFrame("Button", nil, mainFrame)
    optionsButton:SetSize(24, 24)
    optionsButton:SetPoint("TOPLEFT", 8, -8)
    optionsButton:SetNormalTexture("Interface\\CHATFRAME\\UI-ChatIcon-Settings-Up")
    optionsButton:SetPushedTexture("Interface\\CHATFRAME\\UI-ChatIcon-Settings-Down")
    optionsButton:SetHighlightTexture("Interface\\BUTTONS\\UI-Common-MouseHilight", "ADD")
    optionsButton:SetScript("OnClick", function() LibStub("AceConfigDialog-3.0"):Open(addonName) end)
    optionsButton:SetScript("OnEnter", function(self)
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:AddLine("Options", 1, 1, 1)
        GameTooltip:Show()
    end)
    optionsButton:SetScript("OnLeave", function() GameTooltip:Hide() end)

    mainFrame.title = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge"); mainFrame.title:SetPoint("TOP", 0, -18); mainFrame.title:SetText("Liste des joueurs")
    local statsFrame = CreateFrame("Frame", nil, mainFrame); statsFrame:SetSize(280, 120); statsFrame:SetPoint("TOP", mainFrame.title, "BOTTOM", 0, -5); self.frames.stats = statsFrame; self.statsWidgets = {}
    local scrollFrame = CreateFrame("ScrollFrame", nil, mainFrame, "UIPanelScrollFrameTemplate"); scrollFrame:SetSize(280, 300); scrollFrame:SetPoint("TOP", statsFrame, "BOTTOM", 0, -10)
    local editBox = CreateFrame("EditBox", nil, scrollFrame); editBox:SetMultiLine(true); editBox:SetMaxLetters(0); editBox:SetPoint("TOPLEFT"); editBox:SetWidth(scrollFrame:GetWidth()); editBox:SetFontObject("ChatFontNormal"); editBox:EnableMouse(true); editBox:SetAutoFocus(false); editBox:SetScript("OnTextChanged", function(self) if self.officialText and self:GetText() ~= self.officialText then self:SetText(self.officialText); self:HighlightText(0, 0) end end); scrollFrame:SetScrollChild(editBox); self.frames.playerList = editBox
    local footerFrame = CreateFrame("Frame", nil, mainFrame); footerFrame:SetSize(280, 60); footerFrame:SetPoint("BOTTOM", 0, 15)
    local copyButton = CreateFrame("Button", nil, footerFrame, "UIPanelButtonTemplate"); copyButton:SetSize(120, 25); copyButton:SetPoint("BOTTOMLEFT", 10, 10); copyButton:SetText("Copier Pseudos"); copyButton:SetScript("OnClick", function() editBox:SetFocus(true); editBox:HighlightText() end)
    local lootHistoryButton = CreateFrame("Button", nil, footerFrame, "UIPanelButtonTemplate"); lootHistoryButton:SetSize(120, 25); lootHistoryButton:SetPoint("BOTTOMRIGHT", -10, 10); lootHistoryButton:SetText("Historique Loots"); lootHistoryButton:SetScript("OnClick", function() self:ToggleLootFrame() end)
    local credits = footerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall"); credits:SetPoint("BOTTOM", 0, -5); credits:SetText("Addon créé par |cff0070DEEiganjos|r (Archimonde)")
    
    -- Cadre de l'historique de butin
    local lootFrame = CreateFrame("Frame", "RPELootHistoryFrame", container, "BackdropTemplate"); lootFrame:SetSize(self.FRAME_WIDTH_LOOT, self.FRAME_HEIGHT); lootFrame:SetPoint("LEFT", mainFrame, "RIGHT", self.FRAME_SPACING, 0); lootFrame:Hide(); lootFrame:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/DialogFrame/UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } }); lootFrame:SetBackdropColor(0.1, 0.1, 0.1, 0.95); self.frames.loot = lootFrame
    lootFrame.title = lootFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge"); lootFrame.title:SetPoint("TOP", 0, -18); lootFrame.title:SetText("Historique des Butins")
    local lootCloseButton = CreateFrame("Button", nil, lootFrame, "UIPanelCloseButton"); lootCloseButton:SetPoint("TOPRIGHT", -6, -6); lootCloseButton:SetScript("OnClick", function() self:ToggleLootFrame() end)
    
    local lootScrollFrame = CreateFrame("ScrollFrame", "RPELootHistoryScrollFrame", lootFrame, "UIPanelScrollFrameTemplate"); lootScrollFrame:SetPoint("TOPLEFT", 15, -45); lootScrollFrame:SetPoint("BOTTOMRIGHT", -15, 15)
    local lootEditBox = CreateFrame("EditBox", nil, lootScrollFrame); lootEditBox:SetMultiLine(true); lootEditBox:SetMaxLetters(0); lootEditBox:SetPoint("TOPLEFT"); lootEditBox:SetWidth(lootScrollFrame:GetWidth()); lootEditBox:SetFontObject("ChatFontNormal"); lootEditBox:SetAutoFocus(false); lootEditBox:SetScript("OnTextChanged", function(self) if self.officialText and self:GetText() ~= self.officialText then self:SetText(self.officialText); self:HighlightText(0, 0) end end)
    
    -- ### LIGNE CORRIGÉE ###
    -- On assigne bien lootEditBox à lootScrollFrame (et non à scrollFrame)
    lootScrollFrame:SetScrollChild(lootEditBox); 
    self.frames.lootHistory = lootEditBox
end
-- Fin du fichier