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

-- RUI.Widget.InfoCallout(parent, width, height) → Frame
-- Bordered explanation box matching DF's GUI:CreateInfoCallout pattern.
-- ELEMENT background, ACCENT border (0.6 opacity), 8px text insets.
--   frame:SetContent(title, body)  — title rendered in ACCENT colour, body in TEXT
--   frame:SetText(text)            — plain body text only
-- Both label methods support word-wrap; caller provides fixed width and height.
function RUI.Widget.InfoCallout(parent, width, height)
    local frame = CreateFrame("Frame", nil, parent, "BackdropTemplate")
    frame:SetSize(width or 300, height or 60)
    frame:SetBackdrop({
        bgFile   = "Interface\\Buttons\\WHITE8x8",
        edgeFile = "Interface\\Buttons\\WHITE8x8",
        edgeSize = 1,
    })
    frame:SetBackdropColor(RUI.C.ELEMENT.r, RUI.C.ELEMENT.g, RUI.C.ELEMENT.b, 0.75)
    frame:SetBackdropBorderColor(RUI.C.ACCENT.r, RUI.C.ACCENT.g, RUI.C.ACCENT.b, 0.6)

    local lbl = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
    lbl:SetPoint("TOPLEFT",     frame, "TOPLEFT",      8,  -8)
    lbl:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -8,   8)
    lbl:SetJustifyH("LEFT")
    lbl:SetJustifyV("TOP")
    lbl:SetWordWrap(true)
    lbl:SetNonSpaceWrap(true)
    lbl:SetTextColor(RUI.C.TEXT.r, RUI.C.TEXT.g, RUI.C.TEXT.b)

    local curTitle, curBody = nil, nil

    local function Render()
        if curTitle and curTitle ~= "" then
            local c   = RUI.C.ACCENT
            local hex = string.format("ff%02x%02x%02x",
                math.floor(c.r * 255 + 0.5),
                math.floor(c.g * 255 + 0.5),
                math.floor(c.b * 255 + 0.5))
            lbl:SetText("|c" .. hex .. curTitle .. ":|r  " .. (curBody or ""))
        else
            lbl:SetText(curBody or "")
        end
    end

    function frame:SetContent(title, body)
        curTitle, curBody = title, body
        Render()
    end

    function frame:SetText(text)
        curTitle, curBody = nil, text
        Render()
    end

    return frame
end
