-- HDG_HT_W_Featured.lua  (EXISTING)
-- Full-width row of up to 4 weekly featured items. Each mini-feature shows
-- icon + name + source. Uses the card's own title bar — no inline header.

local _, privateDB = ...
privateDB.HDG_HT = privateDB.HDG_HT or {}
privateDB.HDG_HT.Widgets = privateDB.HDG_HT.Widgets or {}
local W = { id = "featured", title = "Featured of the Week" }
privateDB.HDG_HT.Widgets.Featured = W

local SLOT_GAP = 8
local ICON_SIZE = 32

local function CreateMini(parent, scheme, applyFont)
    local mini = CreateFrame("Frame", nil, parent)

    mini.icon = mini:CreateTexture(nil, "ARTWORK")
    mini.icon:SetSize(ICON_SIZE, ICON_SIZE)
    mini.icon:SetPoint("TOPLEFT", mini, "TOPLEFT", 0, 0)
    mini.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)

    mini.name = mini:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    mini.name:SetPoint("TOPLEFT", mini.icon, "TOPRIGHT", 6, -1)
    mini.name:SetPoint("RIGHT", mini, "RIGHT", 0, 0)
    mini.name:SetJustifyH("LEFT")
    mini.name:SetWordWrap(false)
    mini.name:SetTextColor(scheme.text.r, scheme.text.g, scheme.text.b)
    applyFont(mini.name, scheme, "small")

    mini.source = mini:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
    mini.source:SetPoint("TOPLEFT", mini.name, "BOTTOMLEFT", 0, -1)
    mini.source:SetPoint("RIGHT", mini, "RIGHT", 0, 0)
    mini.source:SetJustifyH("LEFT")
    mini.source:SetWordWrap(false)
    mini.source:SetTextColor(scheme.text_dim.r, scheme.text_dim.g, scheme.text_dim.b)
    applyFont(mini.source, scheme, "small")

    function mini:Bind(f)
        if not f then self:Hide(); return end
        self:Show()
        self.icon:SetTexture(f.icon or "Interface\\Icons\\INV_Misc_QuestionMark")
        self.name:SetText(f.name or "?")
        local sub = f.sourceName or ""
        if f.sourceDetail and f.sourceDetail ~= "" then
            sub = sub .. (sub ~= "" and " - " or "") .. f.sourceDetail
        end
        self.source:SetText(sub)
    end

    return mini
end

function W.Create(parent, _)
    local self = { minis = {} }
    self.frame = CreateFrame("Frame", nil, parent)
    self.frame:SetAllPoints(parent)

    local Theme = privateDB.HDG_HT.Theme
    local scheme = Theme.GetCurrentScheme()
    local applyFont = Theme.ApplyFont

    for i = 1, 4 do
        self.minis[i] = CreateMini(self.frame, scheme, applyFont)
    end

    function self:Refresh(snap)
        local feats = (snap and snap.featured) or {}
        for i = 1, 4 do self.minis[i]:Bind(feats[i]) end
    end

    function self:Resize(w, h)
        local slotW = math.max(120, math.floor((w - SLOT_GAP * 3) / 4))
        for i = 1, 4 do
            local m = self.minis[i]
            m:SetSize(slotW, math.max(ICON_SIZE, h or ICON_SIZE))
            m:ClearAllPoints()
            m:SetPoint("TOPLEFT", self.frame, "TOPLEFT", (i - 1) * (slotW + SLOT_GAP), 0)
        end
    end

    return self
end

return W
