(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/cdk/coercion')) :
    typeof define === 'function' && define.amd ? define('@ng-tangram/components/pagination', ['exports', '@angular/common', '@angular/core', '@angular/cdk/coercion'], factory) :
    (global = global || self, factory((global.nt = global.nt || {}, global.nt.components = global.nt.components || {}, global.nt.components.pagination = {}), global.ng.common, global.ng.core, global.ng.cdk.coercion));
}(this, (function (exports, common, core, coercion) { 'use strict';

    var NtPaginationConfig = (function () {
        function NtPaginationConfig() {
            this.previousLabel = 'Previous';
            this.nextLabel = 'Next';
            this.size = 3;
            this.pageSize = 10;
        }
        return NtPaginationConfig;
    }());
    var NT_PAGINATION_CONFIG = new core.InjectionToken('nt-pagination-config');

    var __assign = (this && this.__assign) || function () {
        __assign = Object.assign || function(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                    t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __param = (this && this.__param) || function (paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    };
    var PAGINATION_ELLIPSIS = '...';
    var NtPaginationComponent = (function () {
        function NtPaginationComponent(defaultConfig) {
            this._options = new NtPaginationConfig();
            this._totalPage = 1;
            this._pages = [1];
            this._total = 0;
            this._pageIndex = 1;
            this.pageChange = new core.EventEmitter();
            this._options = __assign(__assign({}, this._options), defaultConfig || {});
        }
        Object.defineProperty(NtPaginationComponent.prototype, "options", {
            get: function () { return this._options; },
            set: function (value) {
                if (typeof value === 'object') {
                    this._options = Object.assign(this._options, value);
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "totalPage", {
            get: function () { return this._totalPage; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "pages", {
            get: function () { return this._pages; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "pageSize", {
            get: function () { return this.options.pageSize; },
            set: function (value) { this._options.pageSize = coercion.coerceNumberProperty(value); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "previousLabel", {
            get: function () { return this.options.previousLabel; },
            set: function (value) { this._options.previousLabel = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "nextLabel", {
            get: function () { return this.options.nextLabel; },
            set: function (value) { this._options.nextLabel = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "total", {
            get: function () { return this._total; },
            set: function (value) { this._total = coercion.coerceNumberProperty(value); this._build(); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtPaginationComponent.prototype, "pageIndex", {
            get: function () { return this._pageIndex; },
            set: function (value) { this._pageIndex = coercion.coerceNumberProperty(value, 1); this._build(); },
            enumerable: true,
            configurable: true
        });
        NtPaginationComponent.prototype._pageChange = function (index) {
            this._pageIndex = coercion.coerceNumberProperty(index, 1);
            this.pageChange.emit(index);
        };
        NtPaginationComponent.prototype._build = function () {
            this._totalPage = Math.ceil(this.total / this.options.pageSize);
            var pages = [1];
            if (this._totalPage > 1) {
                var start = this.pageIndex - this.options.size, end = this.pageIndex + this.options.size;
                start = start < 2 ? 2 : start;
                end = end > this.totalPage - 1 ? this.totalPage - 1 : end;
                start - 2 >= 1 && (pages.push(PAGINATION_ELLIPSIS));
                pages = pages.concat(Array(end - start + 1).fill(start).map(function (value, index) { return value + index; }));
                end + 2 <= this.totalPage && (pages.push(PAGINATION_ELLIPSIS));
                this.totalPage > 1 && pages.push(this.totalPage);
            }
            this._pages = pages;
        };
        NtPaginationComponent.ctorParameters = function () { return [
            { type: NtPaginationConfig, decorators: [{ type: core.Optional }, { type: core.Inject, args: [NT_PAGINATION_CONFIG,] }] }
        ]; };
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "options", null);
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "pageSize", null);
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "previousLabel", null);
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "nextLabel", null);
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "total", null);
        __decorate([
            core.Input()
        ], NtPaginationComponent.prototype, "pageIndex", null);
        __decorate([
            core.Output()
        ], NtPaginationComponent.prototype, "pageChange", void 0);
        NtPaginationComponent = __decorate([
            core.Component({
                selector: 'nt-pagination, [nt-pagination]',
                template: "<ul class=\"pagination\">\n  <li class=\"pagination-previous disabled\" *ngIf=\"pageIndex <= 1\">{{ previousLabel }}</li>\n  <li class=\"pagination-previous\" *ngIf=\"pageIndex > 1\"><a (click)=\"_pageChange(pageIndex - 1)\">{{ previousLabel }}</a></li>\n\n  <ng-container *ngFor=\"let page of pages\">\n    <li *ngIf=\"page === pageIndex\" [class.current]=\"page === pageIndex\">{{ page }}</li>\n    <li *ngIf=\"page !== pageIndex && page !== '...'\"><a (click)=\"_pageChange(page)\">{{ page }}</a></li>\n    <li class=\"ellipsis\" *ngIf=\"page === '...'\"></li>\n  </ng-container>\n\n  <li class=\"pagination-next disabled\" *ngIf=\"pageIndex >= totalPage\">{{ nextLabel }}</li>\n  <li class=\"pagination-next\" *ngIf=\"pageIndex < totalPage\"><a (click)=\"_pageChange(pageIndex + 1)\">{{ nextLabel }}</a></li>\n</ul>\n",
                encapsulation: core.ViewEncapsulation.None
            }),
            __param(0, core.Optional()), __param(0, core.Inject(NT_PAGINATION_CONFIG))
        ], NtPaginationComponent);
        return NtPaginationComponent;
    }());

    var __decorate$1 = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var NtPaginationModule = (function () {
        function NtPaginationModule() {
        }
        NtPaginationModule_1 = NtPaginationModule;
        NtPaginationModule.withConfig = function (config) {
            return {
                ngModule: NtPaginationModule_1,
                providers: [
                    { provide: NT_PAGINATION_CONFIG, useValue: config || new NtPaginationConfig() }
                ]
            };
        };
        var NtPaginationModule_1;
        NtPaginationModule = NtPaginationModule_1 = __decorate$1([
            core.NgModule({
                imports: [common.CommonModule],
                exports: [NtPaginationComponent],
                declarations: [NtPaginationComponent]
            })
        ], NtPaginationModule);
        return NtPaginationModule;
    }());

    exports.NT_PAGINATION_CONFIG = NT_PAGINATION_CONFIG;
    exports.NtPaginationComponent = NtPaginationComponent;
    exports.NtPaginationConfig = NtPaginationConfig;
    exports.NtPaginationModule = NtPaginationModule;
    exports.PAGINATION_ELLIPSIS = PAGINATION_ELLIPSIS;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=pagination.umd.js.map
