(function () {
    'use strict';

    angular
        .module('setoresApp')
        .directive('autoScroll', autoScroll);

    autoScroll.$inject = [];

    /* @ngInject */
    function autoScroll() {
        let directive = {
            restrict: 'A',
            link: linkFunc,
            scope: false
        };
        return directive;

        function linkFunc(scope, element, attrs) {
            //exports
            angular.extend(scope.vm, {
                autoScroll: autoScroll,
                scrollBottom: scrollBottom
            });

            const animationTime = 600;

            function scrollBottom(element) {
                $(element).animate({
                    scrollTop: $(element)[0].scrollHeight
                }, animationTime, 'swing');
            }

            function autoScroll(container, element, padding) {
                if ($(container).length > 0 && $(element).length > 0) {
                    $(container).animate({
                        scrollTop: ($(element)[0].offsetTop - padding)
                    }, animationTime);
                }
            }
        }
    }
})();

