import * as tslib_1 from "tslib";
import { Component, Input, Output, EventEmitter, ViewEncapsulation, ChangeDetectionStrategy, ViewChild, ViewChildren, ContentChildren, QueryList, ChangeDetectorRef } from '@angular/core';
import { TabComponent } from './tab';
import { InkBarComponent } from './ink-bar';
import { TabHeaderComponent } from './tab-header';
import { OnChange } from '../core/decorators';
var TabsComponent = /** @class */ (function () {
    function TabsComponent(cdRef) {
        this.cdRef = cdRef;
        /**
         * Tabs尺寸, 'default' | 'large'
         * @default default
         */
        this.size = 'default';
        /**
         * Tabs是否有下划线, true | false
         * @default false
         */
        this.underline = false;
        /**
         * 各Tab间是否有分割线, true | false
         * @default false
         */
        this.splitline = false;
        /**
         *  panel 活动状态发生改变时事件 emit
         *
         */
        this.change = new EventEmitter();
    }
    TabsComponent.prototype.ngOnInit = function () {
    };
    TabsComponent.prototype.ngAfterViewInit = function () {
        var _this = this;
        if (this.tabs.length === 0) {
            return;
        }
        /** 是否有某个Tab是选中状态，如果没有的话，选中第一个 */
        var activeIndex = this.tabs.toArray().findIndex(function (item) { return item.active === true; });
        this.activeIndex = activeIndex === -1 ? 0 : activeIndex;
        setTimeout(function () {
            _this.tabs.toArray()[_this.activeIndex].active = true;
        });
        this.initializeActiveIndexChange = true;
    };
    TabsComponent.prototype.ngAfterViewChecked = function () {
        if (this.initializeActiveIndexChange) {
            this.alignInkBar();
        }
    };
    /**
     * 设置当前Tab为选中状态
     *
     * @param {number} index - 当前Tab的索引
     */
    TabsComponent.prototype.setActive = function (index) {
        var tab = this.tabs.toArray()[index];
        if (tab.disabled) {
            return;
        }
        if (tab.active) {
            return;
        }
        this.activeIndex = index;
        this.initializeActiveIndexChange = false;
        this.tabs.toArray().forEach(function (t) { return t.active = false; });
        tab.active = true;
        this.alignInkBar();
        this.change.emit({
            activeIndex: index
        });
    };
    /**
     * 设置选中线的位置
     *
     */
    TabsComponent.prototype.alignInkBar = function () {
        var activeTitle = this.tabHeader.toArray()[this.activeIndex];
        if (activeTitle) {
            this.inkBar.alignToElement(activeTitle.elementRef.nativeElement);
        }
    };
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", String)
    ], TabsComponent.prototype, "size", void 0);
    tslib_1.__decorate([
        OnChange(true),
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TabsComponent.prototype, "underline", void 0);
    tslib_1.__decorate([
        OnChange(true),
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TabsComponent.prototype, "splitline", void 0);
    tslib_1.__decorate([
        Output(),
        tslib_1.__metadata("design:type", EventEmitter)
    ], TabsComponent.prototype, "change", void 0);
    tslib_1.__decorate([
        ContentChildren(TabComponent),
        tslib_1.__metadata("design:type", QueryList)
    ], TabsComponent.prototype, "tabs", void 0);
    tslib_1.__decorate([
        ViewChild(InkBarComponent, { static: false }),
        tslib_1.__metadata("design:type", InkBarComponent)
    ], TabsComponent.prototype, "inkBar", void 0);
    tslib_1.__decorate([
        ViewChildren(TabHeaderComponent),
        tslib_1.__metadata("design:type", QueryList)
    ], TabsComponent.prototype, "tabHeader", void 0);
    TabsComponent = tslib_1.__decorate([
        Component({
            selector: 'nb-tabs',
            template: "<div class=\"nb-tabs nb-tabs-{{size}}\" [class.nb-tabs-underline]=\"underline\" [class.nb-tabs-splitline]=\"splitline\"><nb-tab-header *ngFor=\"let tab of tabs; let index = index\" [class.active]=\"tab.active\" [class.disabled]=\"tab.disabled\" (click)=\"setActive(index)\"><ng-template [ngIf]=\"tab.templateTitle && tab.templateTitle.nbTabTitle === tab.title\"><div [nbAttach]=\"tab.templateTitle\"></div></ng-template><ng-template [ngIf]=\"!(tab.templateTitle && tab.templateTitle.nbTabTitle === tab.title)\">{{ tab.title }}</ng-template></nb-tab-header><nb-ink-bar></nb-ink-bar></div><ng-content></ng-content>",
            encapsulation: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            preserveWhitespaces: false,
            host: {
                'class': 'nb-widget'
            },
            exportAs: 'nbTabs'
        }),
        tslib_1.__metadata("design:paramtypes", [ChangeDetectorRef])
    ], TabsComponent);
    return TabsComponent;
}());
export { TabsComponent };
//# sourceMappingURL=tabs.js.map