import { Component, ViewEncapsulation, Input, ElementRef, EventEmitter, Output } from '@angular/core';
var NzPaginationComponent = (function () {
    function NzPaginationComponent(_elementRef) {
        this._elementRef = _elementRef;
        this._current = 1;
        this._pageSize = 10;
        this._firstIndex = 1;
        this._lastIndex = Infinity;
        this._pages = [];
        this._options = [10, 20, 30, 40, 50];
        this._showSizeChanger = false;
        this._showQuickJumper = false;
        this._showTotal = false;
        this._simple = false;
        this.nzPageSizeChange = new EventEmitter();
        this.nzPageIndexChange = new EventEmitter();
        this.nzPageIndexClickChange = new EventEmitter();
        this._el = this._elementRef.nativeElement;
    }
    Object.defineProperty(NzPaginationComponent.prototype, "nzShowSizeChanger", {
        get: function () {
            return this._showSizeChanger;
        },
        set: function (value) {
            if (value === '') {
                this._showSizeChanger = true;
            }
            else {
                this._showSizeChanger = value;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NzPaginationComponent.prototype, "nzShowQuickJumper", {
        get: function () {
            return this._showQuickJumper;
        },
        set: function (value) {
            if (value === '') {
                this._showQuickJumper = true;
            }
            else {
                this._showQuickJumper = value;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NzPaginationComponent.prototype, "nzShowTotal", {
        get: function () {
            return this._showTotal;
        },
        set: function (value) {
            if (value === '') {
                this._showTotal = true;
            }
            else {
                this._showTotal = value;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NzPaginationComponent.prototype, "nzSimple", {
        get: function () {
            return this._simple;
        },
        set: function (value) {
            if (value === '') {
                this._simple = true;
            }
            else {
                this._simple = value;
            }
        },
        enumerable: true,
        configurable: true
    });
    NzPaginationComponent.prototype._jumpBefore = function (pageSize) {
        this._jumpPage(this._current - Math.round(pageSize / 2));
    };
    NzPaginationComponent.prototype._jumpAfter = function (pageSize) {
        this._jumpPage(this._current + Math.round(pageSize / 2));
    };
    Object.defineProperty(NzPaginationComponent.prototype, "nzPageIndex", {
        get: function () {
            return this._current;
        },
        set: function (value) {
            if (this._current === value) {
                return;
            }
            if (value > this._lastIndex || value < this._firstIndex) {
                return;
            }
            this._current = Number(value);
            this._buildIndexes();
        },
        enumerable: true,
        configurable: true
    });
    ;
    ;
    Object.defineProperty(NzPaginationComponent.prototype, "nzPageSize", {
        get: function () {
            return this._pageSize;
        },
        set: function (value) {
            if (value === this._pageSize) {
                return;
            }
            this._pageSize = value;
            this.nzPageIndexChange.emit(this.nzPageIndex);
            this._buildIndexes();
        },
        enumerable: true,
        configurable: true
    });
    ;
    ;
    Object.defineProperty(NzPaginationComponent.prototype, "nzTotal", {
        get: function () {
            return this._total;
        },
        set: function (value) {
            if (value === this._total) {
                return;
            }
            this._total = value;
            this._buildIndexes();
        },
        enumerable: true,
        configurable: true
    });
    ;
    NzPaginationComponent.prototype._pageSizeChange = function ($event) {
        this.nzPageSize = $event;
        this.nzPageSizeChange.emit($event);
    };
    NzPaginationComponent.prototype._nzPageIndexChange = function ($event) {
        this.nzPageIndex = $event;
        this.nzPageIndexChange.emit(this.nzPageIndex);
    };
    /** generate indexes list */
    NzPaginationComponent.prototype._buildIndexes = function () {
        this._lastIndex = Math.ceil(this._total / this._pageSize);
        if (this._current > this._lastIndex) {
            this._jumpPage(this._lastIndex);
        }
        var tmpPages = [];
        if (this._lastIndex <= 9) {
            for (var i = 2; i <= this._lastIndex - 1; i++) {
                tmpPages.push({ index: i });
            }
        }
        else {
            var current = +this._current;
            var left = Math.max(2, current - 2);
            var right = Math.min(current + 2, this._lastIndex - 1);
            if (current - 1 <= 2) {
                right = 5;
            }
            if (this._lastIndex - current <= 2) {
                left = this._lastIndex - 4;
            }
            for (var i = left; i <= right; i++) {
                tmpPages.push({ index: i });
            }
        }
        this._pages = tmpPages;
    };
    NzPaginationComponent.prototype._jumpPage = function (index) {
        if (index < this._firstIndex) {
            this.nzPageIndex = this._firstIndex;
        }
        else if (index > this._lastIndex) {
            this.nzPageIndex = this._lastIndex;
        }
        else {
            this.nzPageIndex = index;
        }
        this.nzPageIndexClickChange.emit(this.nzPageIndex);
        this.nzPageIndexChange.emit(this.nzPageIndex);
    };
    Object.defineProperty(NzPaginationComponent.prototype, "_isLastIndex", {
        get: function () {
            return this._current === this._lastIndex;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NzPaginationComponent.prototype, "_isFirstIndex", {
        get: function () {
            return this._current === this._firstIndex;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NzPaginationComponent.prototype, "_roundPageSize", {
        get: function () {
            return Math.round(this._pageSize / 2);
        },
        enumerable: true,
        configurable: true
    });
    return NzPaginationComponent;
}());
export { NzPaginationComponent };
NzPaginationComponent.decorators = [
    { type: Component, args: [{
                selector: 'nz-pagination',
                encapsulation: ViewEncapsulation.None,
                template: "\n    <ul class=\"ant-pagination ant-pagination-simple\" *ngIf=\"nzSimple\">\n      <li\n        title=\"\u4E0A\u4E00\u9875\"\n        class=\"ant-pagination-prev\"\n        (click)=\"_jumpPage(_current-1)\"\n        [class.ant-pagination-disabled]=\"_isFirstIndex\">\n        <a></a>\n      </li>\n      <li [attr.title]=\"_current+'/'+_lastIndex\" class=\"ant-pagination-simple-pager\">\n        <input [ngModel]=\"nzPageIndex\" (ngModelChange)=\"_nzPageIndexChange($event)\" size=\"3\"><span class=\"ant-pagination-slash\">\uFF0F</span>{{_lastIndex}}\n      </li>\n      <li\n        title=\"\u4E0B\u4E00\u9875\"\n        class=\"ant-pagination-next\"\n        (click)=\"_jumpPage(_current+1)\"\n        [class.ant-pagination-disabled]=\"_isLastIndex\">\n        <a></a>\n      </li>\n    </ul>\n    <ul *ngIf=\"!nzSimple\" class=\"ant-pagination\" [class.mini]=\"nzSize=='small'\">\n      <span class=\"ant-pagination-total-text\" *ngIf=\"nzShowTotal\">\u5171 {{_total}} \u6761</span>\n      <li\n        title=\"\u4E0A\u4E00\u9875\"\n        class=\"ant-pagination-prev\"\n        (click)=\"_jumpPage(_current-1)\"\n        [class.ant-pagination-disabled]=\"_isFirstIndex\">\n        <a></a>\n      </li>\n      <li\n        title=\"\u7B2C\u4E00\u9875\"\n        class=\"ant-pagination-item\"\n        (click)=\"_jumpPage(_firstIndex)\"\n        [class.ant-pagination-item-active]=\"_isFirstIndex\">\n        <a>{{_firstIndex}}</a>\n      </li>\n      <li\n        [attr.title]=\"'\u5411\u524D '+_roundPageSize+' \u9875'\"\n        (click)=\"_jumpBefore(_pageSize)\"\n        class=\"ant-pagination-jump-prev\"\n        *ngIf=\"(_lastIndex >9)&&(_current-3>_firstIndex)\">\n        <a></a>\n      </li>\n      <li\n        *ngFor=\"let page of _pages\"\n        [attr.title]=\"page.index\"\n        class=\"ant-pagination-item\"\n        (click)=\"_jumpPage(page.index)\"\n        [class.ant-pagination-item-active]=\"_current==page.index\">\n        <a>{{page.index}}</a>\n      </li>\n      <li\n        [attr.title]=\"'\u5411\u540E '+_roundPageSize+' \u9875'\"\n        (click)=\"_jumpAfter(_pageSize)\"\n        class=\"ant-pagination-jump-next\"\n        *ngIf=\"(_lastIndex >9)&&(_current+3<_lastIndex)\">\n        <a></a>\n      </li>\n      <li\n        [attr.title]=\"'\u6700\u540E\u4E00\u9875: '+_lastIndex\"\n        class=\"ant-pagination-item\"\n        (click)=\"_jumpPage(_lastIndex)\"\n        *ngIf=\"(_lastIndex>0)&&(_lastIndex!==_firstIndex)\"\n        [class.ant-pagination-item-active]=\"_isLastIndex\">\n        <a>{{_lastIndex}}</a>\n      </li>\n      <li\n        title=\"\u4E0B\u4E00\u9875\"\n        class=\"ant-pagination-next\"\n        (click)=\"_jumpPage(_current+1)\"\n        [class.ant-pagination-disabled]=\"_isLastIndex\">\n        <a></a>\n      </li>\n      <div class=\"ant-pagination-options\">\n        <nz-select\n          *ngIf=\"nzShowSizeChanger\"\n          [nzSize]=\"nzSize=='small'?'small':''\"\n          class=\"ant-pagination-options-size-changer\"\n          [ngModel]=\"_pageSize\"\n          (ngModelChange)=\"_pageSizeChange($event)\">\n          <nz-option\n            *ngFor=\"let option of _options\"\n            [nzLabel]=\"option+ '\u6761/\u9875'\"\n            [nzValue]=\"option\">\n          </nz-option>\n          <nz-option\n            *ngIf=\"_options.indexOf(nzPageSize)==-1\"\n            [nzLabel]=\"nzPageSize+ '\u6761/\u9875'\"\n            [nzValue]=\"nzPageSize\">\n          </nz-option>\n        </nz-select>\n        <div class=\"ant-pagination-options-quick-jumper\"\n          *ngIf=\"nzShowQuickJumper\">\n          \u8DF3\u81F3<input [ngModel]=\"nzPageIndex\" (ngModelChange)=\"_nzPageIndexChange($event)\">\u9875\n        </div>\n      </div>\n    </ul>",
                styles: [
                    "/* stylelint-disable at-rule-empty-line-before,at-rule-name-space-after,at-rule-no-unknown */\n/* stylelint-disable declaration-bang-space-before */\n/* stylelint-disable declaration-bang-space-before */\n.ant-pagination {\n  font-size: 12px;\n}\n.ant-pagination:after {\n  content: \" \";\n  display: block;\n  height: 0;\n  clear: both;\n  overflow: hidden;\n  visibility: hidden;\n}\n.ant-pagination-total-text {\n  display: inline-block;\n  vertical-align: middle;\n  height: 28px;\n  line-height: 28px;\n  margin-right: 8px;\n}\n.ant-pagination-item {\n  cursor: pointer;\n  border-radius: 4px;\n  user-select: none;\n  min-width: 28px;\n  height: 28px;\n  line-height: 28px;\n  text-align: center;\n  list-style: none;\n  display: inline-block;\n  vertical-align: middle;\n  border: 1px solid #d9d9d9;\n  background-color: #fff;\n  margin-right: 8px;\n  font-family: Arial;\n  outline: 0;\n}\n.ant-pagination-item a {\n  text-decoration: none;\n  color: rgba(0, 0, 0, 0.65);\n  transition: none;\n  margin: 0 6px;\n}\n.ant-pagination-item:focus,\n.ant-pagination-item:hover {\n  transition: all .3s;\n  border-color: #108ee9;\n}\n.ant-pagination-item:focus a,\n.ant-pagination-item:hover a {\n  color: #108ee9;\n}\n.ant-pagination-item-active {\n  background-color: #108ee9;\n  border-color: #108ee9;\n}\n.ant-pagination-item-active:focus,\n.ant-pagination-item-active:hover {\n  background-color: #49a9ee;\n  border-color: #49a9ee;\n}\n.ant-pagination-item-active a,\n.ant-pagination-item-active:focus a,\n.ant-pagination-item-active:hover a {\n  color: #fff;\n}\n.ant-pagination-jump-prev,\n.ant-pagination-jump-next {\n  outline: 0;\n}\n.ant-pagination-jump-prev:after,\n.ant-pagination-jump-next:after {\n  content: \"\u2022\u2022\u2022\";\n  display: block;\n  letter-spacing: 2px;\n  color: rgba(0, 0, 0, 0.25);\n  text-align: center;\n}\n.ant-pagination-jump-prev:focus:after,\n.ant-pagination-jump-next:focus:after,\n.ant-pagination-jump-prev:hover:after,\n.ant-pagination-jump-next:hover:after {\n  color: #108ee9;\n  display: inline-block;\n  font-size: 12px;\n  font-size: 8px 9;\n  transform: scale(0.66666667) rotate(0deg);\n  /* IE6-IE8 */\n  -ms-filter: \"progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=1, M12=0, M21=0, M22=1)\";\n  zoom: 1;\n  letter-spacing: -1px;\n  font-family: \"anticon\";\n}\n:root .ant-pagination-jump-prev:focus:after,\n:root .ant-pagination-jump-next:focus:after,\n:root .ant-pagination-jump-prev:hover:after,\n:root .ant-pagination-jump-next:hover:after {\n  filter: none;\n}\n:root .ant-pagination-jump-prev:focus:after,\n:root .ant-pagination-jump-next:focus:after,\n:root .ant-pagination-jump-prev:hover:after,\n:root .ant-pagination-jump-next:hover:after {\n  font-size: 12px;\n}\n.ant-pagination-jump-prev:focus:after,\n.ant-pagination-jump-prev:hover:after {\n  content: \"\\e620\\e620\";\n}\n.ant-pagination-jump-next:focus:after,\n.ant-pagination-jump-next:hover:after {\n  content: \"\\e61f\\e61f\";\n}\n.ant-pagination-prev,\n.ant-pagination-jump-prev,\n.ant-pagination-jump-next {\n  margin-right: 8px;\n}\n.ant-pagination-prev,\n.ant-pagination-next,\n.ant-pagination-jump-prev,\n.ant-pagination-jump-next {\n  font-family: Arial;\n  cursor: pointer;\n  color: rgba(0, 0, 0, 0.65);\n  border-radius: 4px;\n  list-style: none;\n  min-width: 28px;\n  height: 28px;\n  line-height: 28px;\n  text-align: center;\n  transition: all .3s;\n  display: inline-block;\n  vertical-align: middle;\n}\n.ant-pagination-prev,\n.ant-pagination-next {\n  border: 1px solid #d9d9d9;\n  background-color: #fff;\n  outline: 0;\n}\n.ant-pagination-prev a,\n.ant-pagination-next a {\n  color: rgba(0, 0, 0, 0.65);\n  outline: none;\n}\n.ant-pagination-prev a:after,\n.ant-pagination-next a:after {\n  display: inline-block;\n  font-size: 12px;\n  font-size: 8px 9;\n  transform: scale(0.66666667) rotate(0deg);\n  /* IE6-IE8 */\n  -ms-filter: \"progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=1, M12=0, M21=0, M22=1)\";\n  zoom: 1;\n  display: block;\n  height: 26px;\n  line-height: 26px;\n  font-family: \"anticon\";\n  text-align: center;\n}\n:root .ant-pagination-prev a:after,\n:root .ant-pagination-next a:after {\n  filter: none;\n}\n:root .ant-pagination-prev a:after,\n:root .ant-pagination-next a:after {\n  font-size: 12px;\n}\n.ant-pagination-prev:focus,\n.ant-pagination-next:focus,\n.ant-pagination-prev:hover,\n.ant-pagination-next:hover {\n  border-color: #108ee9;\n}\n.ant-pagination-prev:focus a,\n.ant-pagination-next:focus a,\n.ant-pagination-prev:hover a,\n.ant-pagination-next:hover a {\n  color: #108ee9;\n}\n.ant-pagination-prev a:after {\n  content: \"\\e620\";\n  display: block;\n}\n.ant-pagination-next a:after {\n  content: \"\\e61f\";\n  display: block;\n}\n.ant-pagination-disabled {\n  cursor: not-allowed;\n}\n.ant-pagination-disabled:hover {\n  border-color: #d9d9d9;\n}\n.ant-pagination-disabled:hover a {\n  color: rgba(0, 0, 0, 0.25);\n  cursor: not-allowed;\n}\n.ant-pagination-disabled a {\n  color: rgba(0, 0, 0, 0.25);\n}\n.ant-pagination-slash {\n  margin: 0 10px 0 5px;\n}\n.ant-pagination-options {\n  display: inline-block;\n  vertical-align: middle;\n  margin-left: 16px;\n}\n.ant-pagination-options-size-changer {\n  display: inline-block;\n  margin-right: 8px;\n}\n.ant-pagination-options-quick-jumper {\n  display: inline-block;\n  height: 28px;\n  line-height: 28px;\n}\n.ant-pagination-options-quick-jumper input {\n  position: relative;\n  display: inline-block;\n  padding: 4px 7px;\n  width: 100%;\n  height: 28px;\n  cursor: text;\n  font-size: 12px;\n  line-height: 1.5;\n  color: rgba(0, 0, 0, 0.65);\n  background-color: #fff;\n  background-image: none;\n  border: 1px solid #d9d9d9;\n  border-radius: 4px;\n  transition: all .3s;\n  margin: 0 8px;\n  width: 50px;\n}\n.ant-pagination-options-quick-jumper input::-moz-placeholder {\n  color: rgba(0, 0, 0, 0.25);\n  opacity: 1;\n}\n.ant-pagination-options-quick-jumper input:-ms-input-placeholder {\n  color: rgba(0, 0, 0, 0.25);\n}\n.ant-pagination-options-quick-jumper input::-webkit-input-placeholder {\n  color: rgba(0, 0, 0, 0.25);\n}\n.ant-pagination-options-quick-jumper input:hover {\n  border-color: #49a9ee;\n}\n.ant-pagination-options-quick-jumper input:focus {\n  border-color: #49a9ee;\n  outline: 0;\n  box-shadow: 0 0 0 2px rgba(16, 142, 233, 0.2);\n}\n.ant-pagination-options-quick-jumper input-disabled {\n  background-color: #f7f7f7;\n  opacity: 1;\n  cursor: not-allowed;\n  color: rgba(0, 0, 0, 0.25);\n}\n.ant-pagination-options-quick-jumper input-disabled:hover {\n  border-color: #e2e2e2;\n}\ntextarea.ant-pagination-options-quick-jumper input {\n  max-width: 100%;\n  height: auto;\n  vertical-align: bottom;\n}\n.ant-pagination-options-quick-jumper input-lg {\n  padding: 6px 7px;\n  height: 32px;\n}\n.ant-pagination-options-quick-jumper input-sm {\n  padding: 1px 7px;\n  height: 22px;\n}\n.ant-pagination-simple .ant-pagination-prev,\n.ant-pagination-simple .ant-pagination-next {\n  border: 0;\n  height: 24px;\n  line-height: 24px;\n  margin: 0;\n  font-size: 18px;\n}\n.ant-pagination-simple .ant-pagination-simple-pager {\n  display: inline-block;\n  vertical-align: middle;\n  margin-right: 8px;\n}\n.ant-pagination-simple .ant-pagination-simple-pager input {\n  margin: 0 8px;\n  box-sizing: border-box;\n  background-color: #fff;\n  border-radius: 4px;\n  border: 1px solid #d9d9d9;\n  outline: none;\n  padding: 5px 8px;\n  height: 24px;\n  text-align: center;\n  transition: border-color 0.3s;\n}\n.ant-pagination-simple .ant-pagination-simple-pager input:hover {\n  border-color: #108ee9;\n}\n.ant-pagination.mini .ant-pagination-total-text {\n  height: 20px;\n  line-height: 20px;\n}\n.ant-pagination.mini .ant-pagination-item {\n  border: 0;\n  margin: 0;\n  min-width: 20px;\n  height: 20px;\n  line-height: 20px;\n}\n.ant-pagination.mini .ant-pagination-prev,\n.ant-pagination.mini .ant-pagination-next {\n  margin: 0;\n  min-width: 20px;\n  height: 20px;\n  line-height: 20px;\n  border: 0;\n}\n.ant-pagination.mini .ant-pagination-prev a:after,\n.ant-pagination.mini .ant-pagination-next a:after {\n  height: 20px;\n  line-height: 20px;\n}\n.ant-pagination.mini .ant-pagination-jump-prev,\n.ant-pagination.mini .ant-pagination-jump-next {\n  height: 20px;\n  line-height: 20px;\n}\n.ant-pagination.mini .ant-pagination-options {\n  margin-left: 8px;\n}\n.ant-pagination.mini .ant-pagination-options-quick-jumper {\n  height: 20px;\n  line-height: 20px;\n}\n.ant-pagination.mini .ant-pagination-options-quick-jumper input {\n  padding: 1px 7px;\n  height: 22px;\n  width: 44px;\n}\n@media only screen and (max-width: 1024px) {\n  .ant-pagination-item-after-jump-prev,\n  .ant-pagination-item-before-jump-next {\n    display: none;\n  }\n}\n"
                ]
            },] },
];
/** @nocollapse */
NzPaginationComponent.ctorParameters = function () { return [
    { type: ElementRef, },
]; };
NzPaginationComponent.propDecorators = {
    'nzShowSizeChanger': [{ type: Input },],
    'nzShowQuickJumper': [{ type: Input },],
    'nzShowTotal': [{ type: Input },],
    'nzSimple': [{ type: Input },],
    'nzSize': [{ type: Input },],
    'nzPageSizeChange': [{ type: Output },],
    'nzPageIndexChange': [{ type: Output },],
    'nzPageIndexClickChange': [{ type: Output },],
    'nzPageIndex': [{ type: Input },],
    'nzPageSize': [{ type: Input },],
    'nzTotal': [{ type: Input },],
};
