Prat_Editbox = Prat:NewModule('editbox')

function Prat_Editbox:OnInitialize()
    local db = Prat.db.profile

    if not db.Editbox then
        db.Editbox = {
            on = true
        }
    end

    Prat.Options.args.editbox = {
        name = 'Editbox',
        desc = 'Editbox',
        type = 'group',
        args = {
            toggle = {
                name = 'Toggle',
                desc = 'Toggle the module on and off',
                type = 'toggle',
                get = function() return db.Editbox.on end,
                set = function(v)
                    if v then
                        self:OnEnable()
                    else
                        self:OnDisable()
                    end
                    db.Editbox.on = v
                end
            },
            backdrop = {
                name = 'Backdrop',
                desc = 'Toggle the editbox backdrop on and off',
                type = 'toggle',
                get = function() return db.Editbox.CustomBackdrop end,
                set = function(v)
                    if v then
                        self:EnableCustomBackdrop()
                    else
                        self:DisableCustomBackdrop()
                    end
                    db.Editbox.CustomBackdrop = v
                end
            }
        }
    }
end

function Prat_Editbox:OnEnable()
    local db = Prat.db.profile.Editbox
    local eb = VisorEditBox or ChatFrameEditBox
    eb:ClearAllPoints()
    eb:SetPoint('BOTTOMLEFT',  'ChatFrame1', 'TOPLEFT',  -5, 0)
    eb:SetPoint('BOTTOMRIGHT', 'ChatFrame1', 'TOPRIGHT', 5, 0)

    if db.CustomBackdrop then
        self:EnableCustomBackdrop()
    end
end

function Prat_Editbox:OnDisable()
    local eb = VisorEditBox or ChatFrameEditBox
    eb:ClearAllPoints()
    eb:SetPoint('TOPLEFT',  'ChatFrame1', 'BOTTOMLEFT',  -5, 0)
    eb:SetPoint('TOPRIGHT', 'ChatFrame1', 'BOTTOMRIGHT', 5, 0)
end

function Prat_Editbox:EnableCustomBackdrop()
    local eb = VisorEditbox or ChatFrameEditBox
    for i,v in ipairs({eb:GetRegions()}) do
        if i==6 or i==7 or i==8 then
            v:SetAlpha(0)
        end
    end
end

function Prat_Editbox:DisableCustomBackdrop()
    local eb = VisorEditbox or ChatFrameEditBox
    for i,v in ipairs({eb:GetRegions()}) do
        if i==6 or i==7 or i==8 then
            v:SetAlpha(1)
        end
    end
end

