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

-- RUI.Widget.Checkbox(parent, label, get, set) → wrapper Frame, Refresh
-- Matches DandersFrames' CreateCheckbox: BackdropTemplate box (18×18) with
-- ELEMENT bg, BORDER/0.5 border, and a WHITE8x8 ACCENT-colored checkmark.
-- Label uses GameFontHighlightSmall in TEXT color.
-- Caller must SetPoint on the wrapper.
function RUI.Widget.Checkbox(parent, label, get, set)
    local wrapper = CreateFrame("Frame", nil, parent)
    wrapper:SetSize(200, RUI.CHECK_H)

    local cb = CreateFrame("CheckButton", nil, wrapper, "BackdropTemplate")
    cb:SetSize(18, 18)
    cb:SetPoint("LEFT", wrapper, "LEFT", 0, 0)
    cb:SetBackdrop({
        bgFile   = "Interface\\Buttons\\WHITE8x8",
        edgeFile = "Interface\\Buttons\\WHITE8x8",
        edgeSize = 1,
    })
    cb:SetBackdropColor(RUI.C.ELEMENT.r, RUI.C.ELEMENT.g, RUI.C.ELEMENT.b, 1)
    cb:SetBackdropBorderColor(RUI.C.BORDER.r, RUI.C.BORDER.g, RUI.C.BORDER.b, 0.5)

    local check = cb:CreateTexture(nil, "OVERLAY")
    check:SetTexture("Interface\\Buttons\\WHITE8x8")
    check:SetVertexColor(RUI.C.ACCENT.r, RUI.C.ACCENT.g, RUI.C.ACCENT.b)
    check:SetPoint("CENTER")
    check:SetSize(10, 10)
    cb:SetCheckedTexture(check)

    local lbl = wrapper:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    lbl:SetTextColor(RUI.C.TEXT.r, RUI.C.TEXT.g, RUI.C.TEXT.b)
    lbl:SetPoint("LEFT", cb, "RIGHT", 8, 0)
    lbl:SetText(label or "")

    cb:SetScript("OnClick", function(self)
        set(self:GetChecked())
    end)

    local function Refresh()
        cb:SetChecked(get())
    end
    Refresh()
    return wrapper, Refresh
end
