local addonName, ns = ...

------------------------------------------------------------
-- Shopping List help popup: a movable, themed dialog explaining how to use
-- the shopping list. Opened by the "Help" button on the Shopping List tab.
------------------------------------------------------------

local function heading(text)
    return ns.Colorize(ns.Theme.HEADING, text)
end

-- One string per paragraph/bullet; the fontstring word-wraps each to the
-- popup width. Do NOT hard-wrap mid-sentence here — manual breaks combine
-- with the auto-wrap and split lines in the wrong places.
local HELP_TEXT = table.concat({
    heading("Housing Herald - Shopping List"),
    "",
    "Track the decor and dyes you want to collect. Each row shows how many you already have available versus how many you need.",
    "",
    heading("Adding items"),
    "- Ctrl+Alt+Click a decor in the housing catalog. Click it again to raise the quantity.",
    "- Ctrl+Alt+Click a decor link in chat, or a decor or dye item in your bags or chat.",
    "- Click Add Dye to browse and add any housing dye by name.",
    "- Import a list from housing-herald.com with the Import button.",
    "",
    heading("Managing your list"),
    "- Change an amount with the number box on a row (type a number, then press Enter).",
    "- Remove an item with its X button.",
    "- Export copies your list out to share or back up; Clear empties it.",
    "",
    heading("Tracking"),
    "- Your list also appears in the objective tracker, showing a green check once you have enough of an item.",
    "- Click an item to open it in the housing catalog.",
}, "\n")

local helpFrame = CreateFrame("Frame", "HHHelpFrame", UIParent, "BackdropTemplate")
helpFrame:SetSize(470, 360)
helpFrame:SetPoint("CENTER")
helpFrame:SetFrameStrata("FULLSCREEN_DIALOG")
helpFrame:SetMovable(true)
helpFrame:EnableMouse(true)
helpFrame:RegisterForDrag("LeftButton")
helpFrame:SetScript("OnDragStart", helpFrame.StartMoving)
helpFrame:SetScript("OnDragStop", helpFrame.StopMovingOrSizing)
helpFrame:SetClampedToScreen(true)
helpFrame:Hide()

helpFrame:SetBackdrop({
    bgFile = "Interface\\Buttons\\WHITE8x8",
    edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
    edgeSize = 14,
    insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
helpFrame:SetBackdropColor(ns.Theme.BG.r, ns.Theme.BG.g, ns.Theme.BG.b, 0.97)
helpFrame:SetBackdropBorderColor(ns.Theme.BORDER:GetRGBA())
ns._helpFrame = helpFrame
ns.RegisterPopup(helpFrame)

local helpTitle = helpFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
helpTitle:SetPoint("TOP", 0, -12)
helpTitle:SetText("Shopping List Help")

ns.CreateThemedCloseButton(helpFrame)

local helpScroll = CreateFrame("ScrollFrame", nil, helpFrame, "UIPanelScrollFrameTemplate")
helpScroll:SetPoint("TOPLEFT", 16, -36)
helpScroll:SetPoint("BOTTOMRIGHT", -32, 16)

local helpContent = CreateFrame("Frame", nil, helpScroll)
helpContent:SetSize(410, 10)
helpScroll:SetScrollChild(helpContent)

local helpText = helpContent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
helpText:SetPoint("TOPLEFT", 0, 0)
helpText:SetWidth(410)
helpText:SetJustifyH("LEFT")
helpText:SetWordWrap(true)
helpText:SetText(HELP_TEXT)
helpContent:SetHeight(helpText:GetStringHeight() + 8)

function ns:ShowShoppingHelp()
    ns.ShowPopup(helpFrame)
end
