'use strict';

angular.module("quison.ui.pager", [])
    .directive("qnPager", [
        function() {
            return {
                restrict: 'A',
                //require: '?ngModel',
                scope: {
                    pager: "=qnPager",
                    model: "=ngModel"
                },
                link: function(scope, element, attr, ngModel) {
                    var calculate = function() {
                        var size = scope.pager.size || 5;
                        scope.pager.from = ((scope.pager.page - 1) * size) + 1;
                        scope.pager.to = scope.pager.page * size;

                        
                    };

                    var init = function() {
                        element.find('.prev').bind('click', function() {
                            //console.log(scope.pager);
                            scope.pager.page--;
                            model.page = scope.pager.page;
                            calculate();
                        });

                        element.find('.next').bind('click', function() {
                            //console.log(scope.pager);
                            scope.pager.page++;
                            scope.model.page = scope.pager.page;
                            calculate();
                        });
                    };

                    init();
                    //scope.$watch("pager", init, true);


                }
            };
        }
    ])