local ADDON_NAME, WDIGI = ...

------------------------------------------------------------
-- MAIN FRAME (MODERNIZED)
------------------------------------------------------------
-- This ensures compatibility even if the templates change in a future patch
local backdropTemplate = BackdropTemplateMixin and "BackdropTemplate" or nil
local f = CreateFrame("Frame", "WDIGI_MainFrame", UIParent, backdropTemplate)
WDIGI.MainFrame = f

f:SetSize(560, 600)
f:SetPoint("CENTER")
f:SetFrameStrata("HIGH")
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:Hide()

-- Modern Backdrop (Flat Dark UI)
f:SetBackdrop({
    bgFile = "Interface\\Buttons\\WHITE8X8",
    edgeFile = "Interface\\Buttons\\WHITE8X8",
    edgeSize = 1,
    insets = { left = 0, right = 0, top = 0, bottom = 0 }
})
f:SetBackdropColor(0.05, 0.05, 0.05, 0.95) -- Deep Dark
f:SetBackdropBorderColor(0.2, 0.2, 0.2, 1) -- Subtle Border

------------------------------------------------------------
-- HEADER / TITLE BAR
------------------------------------------------------------
local header = CreateFrame("Frame", nil, f)
header:SetSize(f:GetWidth(), 40)
header:SetPoint("TOP")

local title = header:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("LEFT", 15, 0)
title:SetText("|cff00ffffWhere Do I Get It?|r |cff888888v" .. (WDIGI.VERSION or "1.2.3") .. "|r")

-- Modern Close Button
local close = CreateFrame("Button", nil, f, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -5, -5)
close:SetScript("OnClick", function() f:Hide() end)

------------------------------------------------------------
-- SCROLL FRAME SETUP
------------------------------------------------------------
local scroll = CreateFrame("ScrollFrame", "WDIGI_MainScroll", f, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", 15, -60)
scroll:SetPoint("BOTTOMRIGHT", -35, 20)

-- Content Container
local content = CreateFrame("Frame", nil, scroll)
content:SetSize(scroll:GetWidth(), 1) -- Height auto-calculates
scroll:SetScrollChild(content)

local text = content:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
text:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
text:SetWidth(480)
text:SetJustifyH("LEFT")
text:SetJustifyV("TOP")
text:SetSpacing(4) -- Better readability

------------------------------------------------------------
-- CONTENT FORMATTING
------------------------------------------------------------
local function GetAboutText()
    local c = "|cff00ffff" -- Cyan
    local g = "|cffffff00" -- Gold
    local w = "|cffffffff" -- White
    local r = "|r"

    return table.concat({
        c.."ABOUT THE ADDON"..r,
        "WDIGI scans the world data to show you exactly where items come from. No more alt-tabbing to Wowhead while you're in the middle of a dungeon.",
        "",
        c.."QUICK START"..r,
        g.."• Tooltips:"..r.." Hover over any item link or inventory slot.",
        g.."• Navigation:"..r.." Ctrl+Shift+Click an item to drop a map pin.",
        g.."• Compendium:"..r.." Type "..w.."/wd comp"..r.." to search the full database.",
        "",
        c.."SLASH COMMANDS"..r,
        w.."/wd comp"..r.." - Open Search UI",
        w.."/wd pin"..r.." - Pin current tooltip item",
        w.."/wd about"..r.." - Show this info panel",
        w.."/wd nav off"..r.." - Clear the HUD",
        "",
        c.."WHAT'S NEW"..r,
        "• Fixed Node Identity issues in the database.",
        "• Standardized Title Casing for all item names.",
        "• Improved 14-node scraper stability reporting.",
        "",
        c.."SUPPORT THE PROJECT"..r,
        "If this addon saved you a trip to the browser, consider supporting development:",
        g.."buymeacoffee.com/slashzero"..r,
    }, "\n")
end

text:SetText(GetAboutText())

-- Resize container to fit the text
content:SetHeight(text:GetStringHeight() + 20)

------------------------------------------------------------
-- PUBLIC API
------------------------------------------------------------
function WDIGI.MainFrame:ShowAbout()
    if self:IsShown() then
        self:Hide()
    else
        -- Ensure text height is refreshed before showing
        text:SetText(GetAboutText())
        content:SetHeight(text:GetStringHeight() + 20)
        self:Show()
    end
end