local _, ns = ...

ns.Settings = {}

local MEDIA_GENERATED = "Interface\\AddOns\\ForgeFishing\\Media\\generated\\"

local function applyBrandTexture(texture)
    if not texture then return end
    texture:SetTexture(MEDIA_GENERATED .. "logo_primary.png")
end

EventUtil.ContinueOnAddOnLoaded(ns.addonName, function()
    if not Settings or not Settings.RegisterCanvasLayoutCategory then return end

    local frame = CreateFrame("Frame", nil, UIParent)
    frame.name = "Forge Fishing"

    -- Big logo, top-left
    local logo = frame:CreateTexture(nil, "ARTWORK")
    logo:SetSize(160, 160)
    logo:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -16)
    applyBrandTexture(logo)
    logo:SetVertexColor(1, 1, 1, 1.0)

    -- Title to the right of the logo
    local title = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightHuge")
    title:SetPoint("TOPLEFT", logo, "TOPRIGHT", 18, -4)
    title:SetText("Forge Fishing")

    local ver = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    ver:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -6)
    ver:SetText("v2.1.16  \124cff88bbe8WoW Retail Fishing Companion\124r")

    local desc = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
    desc:SetPoint("TOPLEFT", ver, "BOTTOMLEFT", 0, -10)
    desc:SetWidth(460)
    desc:SetJustifyH("LEFT")
    desc:SetWordWrap(true)
    desc:SetText("Beautiful fishing bridge with watcher analytics, lure and equipment-set awareness, double-right-click casting, bite alerts, and session tracking. Use \124cffffd700/aa\124r to open the addon.")

    local openBtn = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
    openBtn:SetSize(180, 26)
    openBtn:SetText("Open Forge Fishing")
    openBtn:SetPoint("TOPLEFT", desc, "BOTTOMLEFT", 0, -14)
    openBtn:SetScript("OnClick", function()
        if ns.UI and ns.UI.ToggleMain then ns.UI:ToggleMain() end
    end)

    -- Separator line below the logo block
    local sep = frame:CreateTexture(nil, "ARTWORK")
    sep:SetColorTexture(0.3, 0.3, 0.3, 0.6)
    sep:SetSize(700, 1)
    sep:SetPoint("TOPLEFT", logo, "BOTTOMLEFT", 0, -20)

    -- "What's New" header
    local clHeader = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge")
    clHeader:SetPoint("TOPLEFT", sep, "BOTTOMLEFT", 0, -14)
    clHeader:SetText("What's New")

    -- v2.1.16
    local v16label = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    v16label:SetPoint("TOPLEFT", clHeader, "BOTTOMLEFT", 0, -10)
    v16label:SetTextColor(1.0, 0.85, 0.35)
    v16label:SetText("v2.1.16")

    local v16body = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
    v16body:SetPoint("TOPLEFT", v16label, "BOTTOMLEFT", 4, -4)
    v16body:SetWidth(670)
    v16body:SetJustifyH("LEFT")
    v16body:SetWordWrap(true)
    v16body:SetText("\124cffadd8e6\226\128\162\124r Added automatic nearby addon pings so players in local range can be discovered.\n\124cffadd8e6\226\128\162\124r Added same-zone nearby player dots on the minimap.")

    -- v2.1.15
    local v15label = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    v15label:SetPoint("TOPLEFT", v16body, "BOTTOMLEFT", -4, -10)
    v15label:SetTextColor(0.85, 0.75, 0.55)
    v15label:SetText("v2.1.15")

    local v15body = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
    v15body:SetPoint("TOPLEFT", v15label, "BOTTOMLEFT", 4, -4)
    v15body:SetWidth(670)
    v15body:SetJustifyH("LEFT")
    v15body:SetWordWrap(true)
    v15body:SetText("\124cffadd8e6\226\128\162\124r Fixed double-right-click casting regression.\n\124cffadd8e6\226\128\162\124r Fixed lure attaching workflow regressions after tool-target tightening.")

    -- v2.1.14
    local v14label = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
    v14label:SetPoint("TOPLEFT", v15body, "BOTTOMLEFT", -4, -10)
    v14label:SetTextColor(0.72, 0.68, 0.58)
    v14label:SetText("v2.1.14")

    local v14body = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
    v14body:SetPoint("TOPLEFT", v14label, "BOTTOMLEFT", 4, -4)
    v14body:SetWidth(670)
    v14body:SetJustifyH("LEFT")
    v14body:SetWordWrap(true)
    v14body:SetText("\124cffadd8e6\226\128\162\124r Fixed fishing tool/lure workflow so lure logic only runs with a valid lure target.\n\124cffadd8e6\226\128\162\124r Modern fishing tool detection now prefers the dedicated fishing tool slot.\n\124cffadd8e6\226\128\162\124r Added retry-based lure confirmation to reduce false negatives.")

    local category = Settings.RegisterCanvasLayoutCategory(frame, "Azeroth Angler")
    ns.Settings.categoryID = category:GetID()
    Settings.RegisterAddOnCategory(category)
end)
