-- VDS_Bindings
-- ============================================================================
-- Keybinding glue. Bindings.xml declares the Apply + Revert live-mode bindings
-- under a "Vamoose's Dye Studio" section; the player assigns keys in Esc >
-- Options > Keybindings. The section comes from each binding's `category`
-- attribute pointing at the BINDING_HEADER_VAMOOSESDYESTUDIO global -- the modern
-- Settings UI convention (matches Baganator / AllTheThings). The old `header`
-- attribute renders as a bogus bindable row instead of a divider; an earlier
-- pass hit that and wrongly dropped the section.
--
-- Each binding action CLICKS the matching live-mode button when it is visible +
-- enabled -- reusing the button's full gate (live mode active + pending changes,
-- plus owned dyes for Apply) and its dispatch path, so the key can never act
-- when the button itself wouldn't.
--
-- No protected/secure plumbing is needed: the commit
-- (C_HousingCustomizeMode.CommitDyesForSelectedDecor) is a NORMAL function
-- (status:normal in the API DB) that already fires from the button's OnClick.

-- Key Bindings UI labels (read when that frame opens). The header names the
-- section; the per-binding names sit under it, so they can stay short.
_G.BINDING_HEADER_VAMOOSESDYESTUDIO = "Vamoose's Dye Studio"
_G.BINDING_NAME_VDSAPPLYDYES        = "Apply"
_G.BINDING_NAME_VDSREVERTDYES       = "Revert"

-- Click a live-mode action button only when it's actionable (visible + enabled),
-- so the key mirrors the button's full gate and is a harmless no-op elsewhere.
local function clickIfReady(btn)
    if btn and btn:IsVisible() and btn:IsEnabled() then  -- exception(nullable): _applyBtn/_revertBtn nil until first live-mode Wire
        btn:Click()  -- runs the button's OnClick (dispatchApply / dispatchRevert)
    end
end

function _G.VDS_ApplyDyesKeybind()  clickIfReady(VDS.Controller_Live._applyBtn)  end
function _G.VDS_RevertDyesKeybind() clickIfReady(VDS.Controller_Live._revertBtn) end
