-- ============================================================================
-- File: ArenaCore/Core/MidnightWindow.lua
-- Purpose: MIDNIGHT expansion information window
-- ============================================================================

local AC = _G.ArenaCore
if not AC then return end

-- Create the MIDNIGHT information window
function AC:ShowMidnightWindow()
    -- Close existing window if open
    if self.midnightWindow then
        self.midnightWindow:Hide()
        self.midnightWindow = nil
    end
    
    -- Create main window frame
    local window = CreateFrame("Frame", "ArenaCoreM idnightWindow", UIParent)
    window:SetSize(550, 520)
    window:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
    window:SetFrameStrata("DIALOG")
    window:SetMovable(true)
    window:EnableMouse(true)
    window:RegisterForDrag("LeftButton")
    window:SetScript("OnDragStart", window.StartMoving)
    window:SetScript("OnDragStop", window.StopMovingOrSizing)
    window:SetClampedToScreen(true)
    
    -- Outer border
    local outerBorder = window:CreateTexture(nil, "BACKGROUND")
    outerBorder:SetAllPoints()
    outerBorder:SetColorTexture(0.2, 0.2, 0.2, 1)
    
    -- Inner background (dark)
    local bg = window:CreateTexture(nil, "BORDER")
    bg:SetPoint("TOPLEFT", 2, -2)
    bg:SetPoint("BOTTOMRIGHT", -2, 2)
    bg:SetColorTexture(0.08, 0.08, 0.08, 0.98)
    
    -- Accent line at top (purple)
    local accent = window:CreateTexture(nil, "ARTWORK")
    accent:SetPoint("TOPLEFT", 2, -2)
    accent:SetPoint("TOPRIGHT", -2, -2)
    accent:SetHeight(2)
    accent:SetColorTexture(0.55, 0.35, 0.65, 1)
    
    -- Title
    local title = window:CreateFontString(nil, "OVERLAY")
    title:SetFont("Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf", 16, "OUTLINE")
    title:SetText("MIDNIGHT EXPANSION")
    title:SetTextColor(0.8, 0.6, 1.0, 1) -- Light purple
    title:SetPoint("TOP", window, "TOP", 0, -20)
    
    -- Alert icon (Crosshair_Important_128)
    local alertIcon = window:CreateTexture(nil, "OVERLAY")
    alertIcon:SetAtlas("Crosshair_Important_128")
    alertIcon:SetSize(40, 40)
    alertIcon:SetPoint("RIGHT", title, "LEFT", -10, 0)
    
    -- Divider line under title
    local divider1 = window:CreateTexture(nil, "ARTWORK")
    divider1:SetPoint("TOPLEFT", window, "TOPLEFT", 20, -55)
    divider1:SetPoint("TOPRIGHT", window, "TOPRIGHT", -20, -55)
    divider1:SetHeight(1)
    divider1:SetColorTexture(0.4, 0.4, 0.4, 0.5)
    
    -- Message text (formatted like hotfix/alert text) - no scroll frame needed
    local messageText = window:CreateFontString(nil, "OVERLAY")
    messageText:SetFont("Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf", 11)
    messageText:SetJustifyH("LEFT")
    messageText:SetJustifyV("TOP")
    messageText:SetWidth(500)
    messageText:SetPoint("TOPLEFT", window, "TOPLEFT", 25, -65)
    
    -- Format text with colorful formatting and emphasis
    local messageContent = [[|cffFF8C00Arena Core|r is |cff00FF00actively changing|r for |cff8B45FFMidnight expansion|r, there will likely be |cffFFFF00bugs|r and |cffFF6347growing pains|r as things progress and evolve into the season. Please report |cffFF0000ANY|r bugs or issues in the |cff8B45FFDiscord|r (link below) so they can get resolved quickly.

|cff00FFFFFeatures|r will continue to get |cff00FF00added|r, |cffFFD700adjusted|r and |cffFF6347removed|r as needed as time goes on. |cffFF8C00Arena Core|r will be an |cff00FF00active project|r and something you can count on being around, however it stays |cff00FFFFbug free|r and evolving with your |cffFFD700ideas|r, |cff00FFFFsuggestions|r and |cffFF6347bug reports|r. All of which are done in our |cff8B45FFDiscord|r, lots of really cool people in it and we'd love to have you!

|cffFF69B4Thank you|r for using |cffFF8C00Arena Core|r and I hope you continue to do so |cffFF69B4<3|r]]
    
    messageText:SetText(messageContent)
    
    -- Static image below Development Team text
    local imageFrame = CreateFrame("Frame", nil, window)
    imageFrame:SetSize(160, 120)
    imageFrame:SetPoint("BOTTOM", window, "BOTTOM", 0, 70)
    
    local imageTexture = imageFrame:CreateTexture(nil, "ARTWORK")
    imageTexture:SetAllPoints()
    imageTexture:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\gif\\frame_2_delay-0.16s_result.png")
    imageTexture:SetTexCoord(0, 1, 0, 1)
    
    -- Divider line above buttons
    local divider2 = window:CreateTexture(nil, "ARTWORK")
    divider2:SetPoint("BOTTOMLEFT", window, "BOTTOMLEFT", 20, 50)
    divider2:SetPoint("BOTTOMRIGHT", window, "BOTTOMRIGHT", -20, 50)
    divider2:SetHeight(1)
    divider2:SetColorTexture(0.4, 0.4, 0.4, 0.5)
    
    -- Discord button (purple styled) - left side
    local discordBtn = CreateFrame("Button", nil, window)
    discordBtn:SetSize(120, 32)
    discordBtn:SetPoint("BOTTOMLEFT", window, "BOTTOMLEFT", 80, 15)
    
    -- Background (purple)
    local discordBg = discordBtn:CreateTexture(nil, "BACKGROUND")
    discordBg:SetAllPoints()
    discordBg:SetColorTexture(0.545, 0.271, 1.000, 1) -- ArenaCore PRIMARY purple
    
    -- Border (darker for depth)
    local discordBorder = discordBtn:CreateTexture(nil, "BORDER")
    discordBorder:SetPoint("TOPLEFT", 1, -1)
    discordBorder:SetPoint("BOTTOMRIGHT", -1, 1)
    discordBorder:SetColorTexture(0.4, 0.2, 0.7, 1)
    
    -- Text
    local discordText = discordBtn:CreateFontString(nil, "OVERLAY")
    discordText:SetFont("Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf", 11)
    discordText:SetText("Discord")
    discordText:SetTextColor(1, 1, 1, 1)
    discordText:SetPoint("CENTER")
    
    -- Add purple glow overlay on hover (same as ProfileStyle buttons)
    local glow = discordBtn:CreateTexture(nil, "OVERLAY")
    glow:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\tab-purple-matte.tga")
    glow:SetAllPoints()
    glow:SetBlendMode("ADD")
    glow:SetAlpha(0)
    discordBtn.glow = glow
    
    -- Hover effect
    discordBtn:SetScript("OnEnter", function()
        discordBg:SetColorTexture(0.645, 0.371, 1.000, 1) -- Lighter purple
        -- Fade in purple glow
        discordBtn.glow:SetAlpha(0.3)
    end)
    discordBtn:SetScript("OnLeave", function()
        discordBg:SetColorTexture(0.545, 0.271, 1.000, 1) -- Original purple
        -- Fade out purple glow
        discordBtn.glow:SetAlpha(0)
    end)
    
    -- Click handler - print Discord link to chat with Arena Core prefix
    discordBtn:SetScript("OnClick", function()
        print("|cff8B45FFArena Core:|r https://AcDiscord.com (Discord Link)")
    end)
    
    -- Close button (purple styled) - right side
    local closeBtn = CreateFrame("Button", nil, window)
    closeBtn:SetSize(120, 32)
    closeBtn:SetPoint("BOTTOMRIGHT", window, "BOTTOMRIGHT", -80, 15)
    
    -- Background (purple)
    local closeBg = closeBtn:CreateTexture(nil, "BACKGROUND")
    closeBg:SetAllPoints()
    closeBg:SetColorTexture(0.545, 0.271, 1.000, 1) -- ArenaCore PRIMARY purple
    
    -- Border (darker for depth)
    local closeBorder = closeBtn:CreateTexture(nil, "BORDER")
    closeBorder:SetPoint("TOPLEFT", 1, -1)
    closeBorder:SetPoint("BOTTOMRIGHT", -1, 1)
    closeBorder:SetColorTexture(0.4, 0.2, 0.7, 1)
    
    -- Text
    local closeText = closeBtn:CreateFontString(nil, "OVERLAY")
    closeText:SetFont("Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf", 11)
    closeText:SetText("Close")
    closeText:SetTextColor(1, 1, 1, 1)
    closeText:SetPoint("CENTER")
    
    -- Add purple glow overlay on hover (same as ProfileStyle buttons)
    local glow = closeBtn:CreateTexture(nil, "OVERLAY")
    glow:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\tab-purple-matte.tga")
    glow:SetAllPoints()
    glow:SetBlendMode("ADD")
    glow:SetAlpha(0)
    closeBtn.glow = glow
    
    -- Hover effect
    closeBtn:SetScript("OnEnter", function()
        closeBg:SetColorTexture(0.645, 0.371, 1.000, 1) -- Lighter purple
        -- Fade in purple glow
        closeBtn.glow:SetAlpha(0.3)
    end)
    closeBtn:SetScript("OnLeave", function()
        closeBg:SetColorTexture(0.545, 0.271, 1.000, 1) -- Original purple
        -- Fade out purple glow
        closeBtn.glow:SetAlpha(0)
    end)
    
    -- Close handler
    closeBtn:SetScript("OnClick", function()
        window:Hide()
        AC.midnightWindow = nil
    end)
    
    -- ESC key to close
    window:SetScript("OnKeyDown", function(self, key)
        if key == "ESCAPE" then
            window:Hide()
            AC.midnightWindow = nil
        end
    end)
    
    -- Store reference
    self.midnightWindow = window
    window:Show()
end
