;
(function () {
    'use strict';
    const
        apiService = require('app-service'),
        lodash = require('lodash'),
        EventEmitter = require('myevents');
    angular
        .module('app.widgets')
        .directive('pager', header);
    header.$inject = [];

    function header() {
        return {
            restrict: 'E',
            template: `<div class="pager-foot" id="{{::pagerId}}">  
                            <div class="total">{{pageInfo.total}}项 </div>
                            <div id="s-pager" style="text-align: center" > 
                            </div>
                            <i style="background-image: url('./assets/imgs/footer/foot.png');
                             background-repeat: no-repeat; position: absolute; right: -5px;  width: 15px;  height: 15px; top: 23px;"></i>
                        </div>
                `,
            transclude: true,

            scope: {
                pagerId: '@',
                pageInfo: '=',
                groups: '@',
                ngClick: '='
            },
            link: function (scope, element, attrs) {

                scope.$watch('pageInfo', function (value) {
                    if (!value) {
                        return;
                    }
                    setTimeout(() => {
                        pager();
                    });
                });

                function pager() {
                    laypage({
                        cont: 's-pager',
                        pages: scope.pageInfo.pages || 0, // 总页数
                        curr: scope.pageInfo.page || 1, //当前页
                        first: '<<',
                        last: '>>',
                        prev: '<', // 若不显示，设置false即可
                        next: '>', // 若不显示，设置false即可
                        jump: function (e, first) { // 触发分页后的回调
                            if (first) { // 一定要加此判断，否则初始时会无限刷新
                                return
                            }
                            if (typeof scope.ngClick === 'function') {
                                scope.ngClick(e.curr);
                            }
                        },
                        skip: false, // 是否开启跳页
                        skin: '#41cac0',
                        groups: scope.groups || 10 // 连续显示分页数
                    });
                }


            }
        };
    }
})();
