-- HDG_HT_Placeholder.lua
-- Wireframe content for placeholder cards. Used by the test window before any
-- real widget rendering exists. Shows id/width/minHeight/row inside a colored
-- fill keyed by width. Hover → tooltip with full LAYOUT_CONFIG block for that widget.

local _, privateDB = ...
privateDB.HDG_HT = privateDB.HDG_HT or {}
local Placeholder = {}
privateDB.HDG_HT.Placeholder = Placeholder

local FILL_COLORS = {
    third     = { 0.20, 0.40, 0.65, 0.30 },    -- blue tint
    twoThirds = { 0.20, 0.55, 0.55, 0.30 },    -- teal tint
    full      = { 0.65, 0.50, 0.20, 0.30 },    -- amber tint
}

-- card: a Card frame from Cards.Create()
-- spec: the resolved widget spec (from Resolver)
-- meta: { row = N }  -- from the layout pass (assigned in TestWindow)
function Placeholder.Render(card, spec, meta)
    if not card or not card.body then return end

    -- Clear any previous placeholder content
    if card._placeholderFill then card._placeholderFill:Hide() end
    if card._placeholderText then card._placeholderText:Hide() end

    -- Colored fill across body
    local fill = card._placeholderFill or card.body:CreateTexture(nil, "ARTWORK")
    fill:SetTexture("Interface\\Buttons\\WHITE8x8")
    fill:SetVertexColor(unpack(FILL_COLORS[spec.width] or FILL_COLORS.third))
    fill:SetAllPoints(card.body)
    fill:Show()
    card._placeholderFill = fill

    -- Wireframe text. Show specRef + id on first line, dims + phase on second.
    local text = card._placeholderText or card.body:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    text:SetPoint("CENTER", card.body, "CENTER", 0, 0)
    local refPart = spec.specRef and ("|cFFffd34d" .. spec.specRef .. "|r  ") or ""
    local phasePart = spec.phase and ("  ·  " .. spec.phase) or ""
    text:SetText(string.format("%s%s\n%s · %dpx · row %d%s",
        refPart, spec.id,
        spec.width, spec.minHeight or 0, (meta and meta.row) or 0,
        phasePart))
    text:SetJustifyH("CENTER")
    text:Show()
    card._placeholderText = text

    -- Tooltip on hover with full spec dump
    card:SetScript("OnEnter", function(self)
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:AddLine(spec.id, 1, 1, 0)
        for k, v in pairs(spec) do
            if k ~= "id" then
                GameTooltip:AddDoubleLine(k, tostring(v), 0.7, 0.7, 0.7, 1, 1, 1)
            end
        end
        GameTooltip:Show()
    end)
    card:SetScript("OnLeave", function() GameTooltip:Hide() end)
end
