local AceGUI = LibStub("AceGUI-3.0")
local Media = LibStub("LibSharedMedia-3.0")

AceGUISharedMediaWidgets = {}
do
    AceGUIWidgetLSMlists = {
        font = Media:HashTable("font"),
        sound = Media:HashTable("sound"),
        statusbar = Media:HashTable("statusbar"),
        border = Media:HashTable("border"),
        background = Media:HashTable("background"),
    }

    local function fixlevels(parent, ...)
        local index = 1
        local child = select(index, ...)
        while child do
            child:SetFrameLevel(parent:GetFrameLevel() + 1)
            fixlevels(child, child:GetChildren())
            index = index + 1
            child = select(index, ...)
        end
    end

    local function OnItemValueChanged(this, _, checked)
        local self = this.userdata.obj
        if checked then
            self:SetValue(this.userdata.value)
            self:Fire("OnValueChanged", this.userdata.value)
        else
            this:SetValue(true)
        end
        self.pullout:Close()
    end

    local function SetValue(self, value)
        if value then
            self:SetText(value or "")
        end
        self.value = value
    end

    AceGUISharedMediaWidgets.fixlevels = fixlevels
    AceGUISharedMediaWidgets.OnItemValueChanged = OnItemValueChanged
    AceGUISharedMediaWidgets.SetValue = SetValue
end
