-- HDG_HT_W_Capacity.lua  (A1)
-- Decor capacity gauge: owned / max with tier-coloured fill.

local _, privateDB = ...
privateDB.HDG_HT = privateDB.HDG_HT or {}
privateDB.HDG_HT.Widgets = privateDB.HDG_HT.Widgets or {}
local W = { id = "capacity", title = "Decor Capacity" }
privateDB.HDG_HT.Widgets.Capacity = W

local Patterns = privateDB.HDG_HT.Patterns

local function format(n)
    if BreakUpLargeNumbers then return BreakUpLargeNumbers(n) end
    return tostring(n)
end

function W.Create(parent, dims)
    local self = { dims = dims }
    self.pattern = Patterns.GaugeBar(parent, dims, {
        barSegments = dims.barSegments or 10,
        segmentHeight = dims.fillbarHeight or 12,
        barStyle = dims.barStyle or "solid",
        subLineCount = 2,
    })

    function self:Refresh(snap)
        local cap = snap and snap.capacity
        if not cap then self.pattern:Update(nil); return end
        local subs = {}
        if cap.exempt and cap.exempt > 0 then
            subs[#subs + 1] = string.format("+%d exempt items", cap.exempt)
        end
        local rooms = snap and snap.rooms
        if rooms and rooms.total > 0 then
            subs[#subs + 1] = string.format("Rooms %d/%d unlocked", rooms.owned, rooms.total)
        end
        self.pattern:Update({
            value = cap.owned, max = cap.max,
            overlayText = string.format("%s / %s", format(cap.owned), format(cap.max)),
            tier = cap.tier,
            subLines = subs,
        })
    end

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

    return self
end

return W
