Prat_Scroll = Prat:NewModule('scroll')

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

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

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

function Prat_Scroll:OnEnable()
    for i = 1, 7 do
        local cf = getglobal('ChatFrame'..i)
        cf:SetScript('OnMouseWheel', function() self:Scroll() end)
        cf:EnableMouseWheel(true)
    end
end

function Prat_Scroll:OnDisable()
    for i = 1, 7 do
        local cf = getglobal('ChatFrame'..i)
        cf:SetScript('OnMouseWheel', nil)
        cf:EnableMouseWheel(false)
    end
end

function Prat_Scroll:Scroll()
    if arg1 > 0 then
        if IsShiftKeyDown() then
            this:ScrollToTop()
        else
            this:ScrollUp()
        end
    elseif arg1 < 0 then
        if IsShiftKeyDown() then
            this:ScrollToBottom()
        else
            this:ScrollDown()
        end
    end
end

