local RUI = LibStub("RUI-1.0")
if not RUI then return end

-- RUI.Widget.Input(parent, label, x, y, width, get, set) → EditBox, Refresh()
-- Integer input (positive and negative). Rounds on EnterPressed; reverts on Escape.
-- Total height consumed: LABEL_H(14) + INPUT_H(20) + CONTROL_GAP(4) = 38px.
function RUI.Widget.Input(parent, label, x, y, width, get, set)
    local lbl = RUI.Draw.MakeLabel(parent)
    lbl:SetTextColor(RUI.C.TEXT.r, RUI.C.TEXT.g, RUI.C.TEXT.b)
    lbl:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
    lbl:SetWidth(width)
    lbl:SetJustifyH("LEFT")
    lbl:SetText(label)

    local eb = RUI.Draw.MakeInputBox(parent, width)
    eb:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y - RUI.LABEL_H)
    eb:SetMaxLetters(12)

    eb:SetScript("OnEnterPressed", function(self)
        local n = tonumber(self:GetText())
        if n then set(math.floor(n + 0.5)) end
        self:ClearFocus()
    end)
    eb:SetScript("OnEscapePressed", function(self)
        self:SetText(tostring(get()))
        self:ClearFocus()
    end)

    local function Refresh()
        eb:SetText(tostring(get()))
    end
    Refresh()
    return eb, Refresh, lbl
end
