-- ============================================================
-- RNTools_Styles.lua  Shared visual style — matches AceGUI neutral theme
-- UI_Core.lua re-declares RNTS inline (must stay in sync with this file)
-- ============================================================

RNTS = {}  -- global style table

-- Backdrops — matches AceGUI PaneBackdrop (ChatFrameBackground + UI-Tooltip-Border)
RNTS.BACKDROP = {
    bgFile   = "Interface/ChatFrame/ChatFrameBackground",
    edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
    tile=true, tileSize=16, edgeSize=16,
    insets={left=3, right=3, top=5, bottom=3},
}
RNTS.BACKDROP_BTN = {
    bgFile   = "Interface/ChatFrame/ChatFrameBackground",
    edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
    tile=true, tileSize=16, edgeSize=16,
    insets={left=3, right=3, top=5, bottom=3},
}

-- Color constants — AceGUI InlineGroup neutral palette
RNTS.C = {
    bg          = {0.10,  0.10,  0.10,  0.50},
    bgBtn       = {0.14,  0.14,  0.14,  1.00},
    bgBtnHover  = {0.22,  0.22,  0.22,  1.00},
    bgBtnDown   = {0.08,  0.08,  0.08,  1.00},
    bgBtnActive = {0.06,  0.18,  0.06,  1.00},
    border      = {0.40,  0.40,  0.40,  1.00},
    borderBtn   = {0.40,  0.40,  0.40,  1.00},
    borderGold  = {1.00,  0.82,  0.00,  1.00},
    borderGreen = {0.10,  0.80,  0.30,  1.00},
    borderRed   = {0.80,  0.20,  0.10,  1.00},
    textMain    = {0.95,  0.95,  0.95,  1.00},
    textGold    = {1.00,  0.82,  0.00,  1.00},
    textGrey    = {0.55,  0.55,  0.55,  1.00},
    textGreen   = {0.20,  1.00,  0.40,  1.00},
    textRed     = {1.00,  0.40,  0.40,  1.00},
    divider     = {0.40,  0.40,  0.40,  0.70},
}

-- Panel: SetBackdrop + colors
function RNTS.Panel(f, bgR,bgG,bgB,bgA, brR,brG,brB,brA)
    local C = RNTS.C
    f:SetBackdrop(RNTS.BACKDROP)
    f:SetBackdropColor(bgR or C.bg[1], bgG or C.bg[2], bgB or C.bg[3], bgA or C.bg[4])
    f:SetBackdropBorderColor(brR or C.border[1], brG or C.border[2],
                             brB or C.border[3], brA or C.border[4])
end

function RNTS.DarkPanel(f)
    RNTS.Panel(f)
end

-- Button factory — matches UIPanelButtonTemplate2 style via raw backdrop
function RNTS.Btn(parent, label, w, h)
    local C   = RNTS.C
    local btn = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate2")
    btn:SetSize(w, h or 22)
    btn:SetText(label)
    btn._fs = btn:GetFontString()
    return btn
end

-- Section header — matches AceGUI Heading (GameFontNormal + UI-Tooltip-Border lines)
function RNTS.Header(parent, text, y)
    local hdr = CreateFrame("Frame", nil, parent)
    hdr:SetPoint("TOPLEFT",  parent, "TOPLEFT",  4, y)
    hdr:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -4, y)
    hdr:SetHeight(18)

    local label = hdr:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
    label:SetPoint("TOP"); label:SetPoint("BOTTOM")
    label:SetJustifyH("CENTER")
    label:SetText(text)

    local left = hdr:CreateTexture(nil, "BACKGROUND")
    left:SetHeight(8)
    left:SetPoint("LEFT", 3, 0)
    left:SetPoint("RIGHT", label, "LEFT", -5, 0)
    left:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
    left:SetTexCoord(0.81, 0.94, 0.5, 1)

    local right = hdr:CreateTexture(nil, "BACKGROUND")
    right:SetHeight(8)
    right:SetPoint("RIGHT", -3, 0)
    right:SetPoint("LEFT", label, "RIGHT", 5, 0)
    right:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
    right:SetTexCoord(0.81, 0.94, 0.5, 1)

    hdr._fs = label
    return hdr
end

-- Divider line — matches AceGUI UI-Tooltip-Border line
function RNTS.Divider(parent, y, lx, rx)
    local t = parent:CreateTexture(nil, "BACKGROUND")
    t:SetHeight(8)
    t:SetPoint("TOPLEFT",  parent, "TOPLEFT",  lx or 3,  y)
    t:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -(rx or 3), y)
    t:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
    t:SetTexCoord(0.81, 0.94, 0.5, 1)
    return t
end

-- Tab button — matches AceGUI OptionsFrameTabButtonTemplate with SetActive(bool)
function RNTS.TabBtn(parent, label, w, h)
    local tabname = "RNTSTabBtn" .. tostring(math.random(1, 999999))
    local btn = CreateFrame("Button", tabname, parent, "OptionsFrameTabButtonTemplate")
    btn:SetSize(w, h or 26)
    btn:SetText(label)
    btn._active = false
    btn.SetActive = function(self, on)
        self._active = on
        if on then
            PanelTemplates_SelectTab(self)
        else
            PanelTemplates_DeselectTab(self)
        end
    end
    return btn
end
