-- HDG_HT_W_TopVendors.lua
-- Top-5 vendors with the most uncollected decor at their stall. Source:
-- snap.topVendors (computed in HDG_HT_Aggregator from HDG_VendorByItem +
-- HDG_VendorDB). Each row shows a SAMPLE uncollected item's icon — so the
-- art on the row IS one of the uncollected pieces, making the "uncollected"
-- meaning visually obvious. Click row → switches to Acquisition tab.

local _, privateDB = ...
privateDB.HDG_HT = privateDB.HDG_HT or {}
privateDB.HDG_HT.Widgets = privateDB.HDG_HT.Widgets or {}
local W = { id = "topVendors", title = "Top Vendors" }
privateDB.HDG_HT.Widgets.TopVendors = W

local Patterns = privateDB.HDG_HT.Patterns

function W.Create(parent, dims)
    local self = {}
    self.pattern = Patterns.IconRowList(parent, dims, {
        rowHeight = dims.rowHeight or 26,
        iconSize  = dims.iconSize  or 22,
    })

    function self:Refresh(snap)
        local Theme = privateDB.HDG_HT.Theme
        local cWarning = (Theme.C_Warning and Theme.C_Warning()) or Theme.C_Accent()
        local vendors = (snap and snap.topVendors) or {}
        local rows = {}
        for i, v in ipairs(vendors) do
            rows[i] = {
                icon  = v.sampleIcon or "Interface\\Icons\\INV_Misc_QuestionMark",
                lineA = v.name or "?",
                lineB = v.zone or "",
                -- Count + label so the meaning is obvious without context.
                chip  = string.format("%s%d|r %suncollected|r",
                    cWarning, v.count or 0,
                    Theme.C_Dim and Theme.C_Dim() or ""),
                onClick = function()
                    if _G.HDG_UI and _G.HDG_UI.SwitchTab then
                        _G.HDG_UI.SwitchTab("acquisition")
                    end
                end,
            }
        end
        -- Header chip up top makes the column meaning explicit even before
        -- a row's chip text resolves.
        self.pattern:Update({
            rows = rows,
            headerChip = (Theme.C_Dim and Theme.C_Dim() or "") .. "uncollected at vendor|r",
        })
    end

    function self:Resize(w, h) self.pattern:Resize(w, h) end
    return self
end

return W
