local DGV = DugisGuideViewer

local UIE = DGV:RegisterModule("UIEventHandlers")
UIE.essential = true

DGVUIFrameMixin = {}

local function GetHandler(widget)
    local handlerKey = widget.DGVEventKey or select(3,strfind(widget:GetDebugName(), "%.?([^%.]+)$"))
    return handlerKey and UIE[handlerKey]
end

local function InitInternal(widget)
    if widget.initialized then return end
    local handler = GetHandler(widget)
    if handler then
        for scriptName, script in next, handler do
            if type(script) == "function" then
                widget:SetScript(scriptName, script)
            end
        end
    end
    widget.initialized = true
end

function DGVUIFrameMixin:Init()
    InitInternal(self)
end

function DGVUIFrameMixin:OnLoad()
    InitInternal(self)
end

function UIE:Initialize()
    DugisEquipPromptFrame:Init()
end