import { __decorate, __extends, __spread, __param } from 'tslib';
import { TemplateRef, Directive, EventEmitter, Renderer2, ElementRef, ChangeDetectorRef, NgZone, ViewChild, Input, Output, ContentChildren, forwardRef, ViewChildren, Component, ChangeDetectionStrategy, ViewEncapsulation, ViewContainerRef, ContentChild, Optional, HostListener, NgModule } from '@angular/core';
import { st2c, StyleCollection, LY_COMMON_STYLES, mixinStyleUpdater, mixinBg, mixinElevation, mixinShadowColor, mixinColor, mixinRaised, mixinDisabled, mixinOutlined, mixinDisableRipple, toBoolean, XPosition, YPosition, AlignAlias, LyTheme2, StyleRenderer, Style, Dir, scrollWithAnimation, LyRippleService, LyFocusState, LyThemeModule, LyCommonModule, NgTranscludeModule } from '@alyle/ui';
import { LyButton } from '@alyle/ui/button';
import { Subscription, Subject } from 'rxjs';
import { ViewportRuler } from '@angular/cdk/scrolling';
import { Platform } from '@angular/cdk/platform';
import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
import { switchMapTo, take, takeUntil } from 'rxjs/operators';
import { CommonModule } from '@angular/common';

var LyTabContent = /** @class */ (function () {
    function LyTabContent(template) {
        this.template = template;
    }
    LyTabContent.ctorParameters = function () { return [
        { type: TemplateRef }
    ]; };
    LyTabContent = __decorate([
        Directive({ selector: '[ly-tab-content]' })
    ], LyTabContent);
    return LyTabContent;
}());

var DEFAULT_DISABLE_RIPPLE = false;
var STYLE_PRIORITY = -2;
var DEFAULT_BG = 'primary';
var DEFAULT_INDICATOR_COLOR = 'accent';
var DEFAULT_ELEVATION = 4;
var DEFAULT_HEADER_PLACEMENT = 'above';
var STYLES = function (theme, ref) {
    var __ = ref.selectorsOf(STYLES);
    return {
        $name: LyTabs.и,
        $priority: STYLE_PRIORITY,
        root: function () { return function (className) { return className + "{display:flex;}" + st2c(((theme.tab
            && theme.tab.root
            && (theme.tab.root instanceof StyleCollection
                ? theme.tab.root.setTransformer(function (fn) { return fn(__); }).css
                : theme.tab.root(__)))), "" + className); }; },
        tab: function (className) { return className + "{position:relative;display:inline-flex;}"; },
        /** Tab container */
        contentContainer: function (className) { return className + "{display:flex;overflow:hidden;flex-grow:1;width:100%;position:relative;}"; },
        /** Tab header */
        labels: function (className) { return className + "{display:flex;position:relative;height:100%;}"; },
        labelsContainer: function () { return function (className) { return className + "{overflow:hidden;flex-shrink:0;}@media (hover: none){" + __.scrollable + " " + className + "{overflow:auto;}}"; }; },
        label: function (className) { return className + "{-webkit-tap-highlight-color:transparent;-webkit-appearance:none;background-color:transparent;user-select:none;border:0;min-width:72px;padding:0 24px;cursor:pointer;height:48px;display:inline-flex;justify-content:center;align-items:center;position:relative;overflow:hidden;font-family:" + theme.typography.fontFamily + ";font-size:" + theme.pxToRem(theme.typography.fontSize) + ";letter-spacing:0.02857em;color:currentColor;outline:none;width:100%;font-weight:500;opacity:.7;}@media " + theme.breakpoints['XSmall'] + "{" + className + "{padding:0 12px;}}"; },
        labelActive: function (className) { return className + "{opacity:1;}"; },
        contents: function (className) { return className + "{display:flex;width:100%;}"; },
        content: function (className) { return "" + st2c((LY_COMMON_STYLES.fill), "" + className) + className + "{width:100%;height:100%;position:absolute;overflow:auto;}"; },
        contentActive: function (className) { return className + "{position:relative;z-index:1;}"; },
        contentInner: null,
        indicator: function (className) { return className + "{position:absolute;height:2px;transition:450ms cubic-bezier(.1, 1, 0.5, 1);background:currentColor;}"; },
        indicatorForServer: function (className) { return className + "{position:absolute;background:currentColor;}"; },
        rippleContainer: function (className) { return "" + st2c((LY_COMMON_STYLES.fill), "" + className) + className + "{overflow:hidden;}"; },
        scrollable: null,
        hiddenContent: function () { return function (className) { return className + "{visibility:hidden;}"; }; },
        column: null,
        row: null
    };
};
/** @docs-private */
var LyTabsBase = /** @class */ (function () {
    function LyTabsBase(_theme) {
        this._theme = _theme;
    }
    return LyTabsBase;
}());
/** @docs-private */
var LyTabsMixinBase = mixinStyleUpdater(mixinBg(mixinElevation(mixinShadowColor(LyTabsBase))));
/** @docs-private */
var LyTabLabelBase = /** @class */ (function () {
    function LyTabLabelBase(_theme, _ngZone, _platform) {
        this._theme = _theme;
        this._ngZone = _ngZone;
        this._platform = _platform;
    }
    return LyTabLabelBase;
}());
/** @docs-private */
var LyTabLabelMixinBase = mixinStyleUpdater(mixinBg(mixinColor(mixinRaised(mixinDisabled(mixinOutlined(mixinElevation(mixinShadowColor(mixinDisableRipple(LyTabLabelBase)))))))));
var ɵ0 = function (val) { return function (theme, ref) {
    var __ = ref.selectorsOf(STYLES);
    return function (className) { return className + " " + __.indicator + "{color:" + theme.colorOf(val) + ";}"; };
}; };
/**
 * @dynamic
 */
var LyTabs = /** @class */ (function (_super) {
    __extends(LyTabs, _super);
    function LyTabs(theme, renderer, el, cd, _viewportRuler, sRenderer, _platform, _ngZone) {
        var _this = _super.call(this, theme) || this;
        _this.theme = theme;
        _this.renderer = renderer;
        _this.el = el;
        _this.cd = cd;
        _this._viewportRuler = _viewportRuler;
        _this.sRenderer = sRenderer;
        _this._platform = _platform;
        _this._ngZone = _ngZone;
        /** @docs-private */
        _this.$priority = STYLE_PRIORITY;
        /** @docs-private */
        _this.classes = _this.sRenderer.renderSheet(STYLES, true);
        _this._tabsSubscription = Subscription.EMPTY;
        _this._timeoutIds = {};
        /** Emits whenever the component is destroyed. */
        _this._destroy = new Subject();
        _this.selectedIndexOnChange = 'auto';
        _this.selectedIndexChange = new EventEmitter();
        _this.setAutoContrast();
        _this.animationDuration = 500;
        return _this;
    }
    Object.defineProperty(LyTabs.prototype, "keepContent", {
        get: function () {
            return this._keepContent;
        },
        /**
         * Keep the content.
         * By default, when changing a tab, the previous one is created and deleted.
         * With this, the content will only be hidden instead of deleting it.
         */
        set: function (val) {
            var newVal = toBoolean(val);
            this._keepContent = newVal;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "animationDuration", {
        get: function () {
            return this._animationDuration;
        },
        /** Animation duration in milliseconds */
        set: function (val) {
            var _this = this;
            this._animationDuration = val;
            Promise.resolve().then(function () {
                _this.tabContents.nativeElement.style.transitionDuration = val + "ms";
            });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "dynamicHeight", {
        get: function () {
            return this._dynamicHeight;
        },
        /**
         * Whether the tab group should grow to the size of the active tab.
         */
        set: function (val) {
            var newVal = toBoolean(val);
            this._dynamicHeight = newVal;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "scrollable", {
        get: function () {
            return this._scrollable;
        },
        set: function (val) {
            var newVal = toBoolean(val);
            if (newVal) {
                this.renderer.addClass(this.el.nativeElement, this.classes.scrollable);
            }
            else if (this._scrollable != null) {
                this.renderer.removeClass(this.el.nativeElement, this.classes.scrollable);
            }
            this._scrollable = newVal;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "headerPlacement", {
        get: function () {
            return this._headerPlacement;
        },
        set: function (val) {
            var _this = this;
            if (val !== this.headerPlacement) {
                this._headerPlacement = val;
                this.sRenderer.toggleClass(this.classes.column, val === 'above' || val === 'below');
                this.sRenderer.toggleClass(this.classes.row, val === 'before' || val === 'after');
                this._headerPlacementClass = this.theme.addStyle("lyTabs.headerPlacement:" + val, function () {
                    var _a, _b;
                    var flexDirectionContainer;
                    var flexDirection = _this._getFlexDirection(val);
                    var position;
                    var height = null;
                    var width = null;
                    var heightServer = null;
                    var widthServer = null;
                    switch (val) {
                        case YPosition.above:
                            flexDirectionContainer = 'column';
                            position = YPosition.below;
                            height = '2px';
                            widthServer = '100%';
                            break;
                        case YPosition.below:
                            flexDirectionContainer = 'column-reverse';
                            position = YPosition.above;
                            height = '2px';
                            widthServer = '100%';
                            break;
                        case XPosition.before:
                            flexDirectionContainer = 'row';
                            position = XPosition.after;
                            width = '2px';
                            heightServer = '100%';
                            break;
                        case XPosition.after:
                            flexDirectionContainer = 'row-reverse';
                            position = XPosition.before;
                            width = '2px';
                            heightServer = '100%';
                            break;
                        default:
                            throw new Error("LyTabs: value:" + val + " do not is valid for `headerPlacement`");
                    }
                    if (val === YPosition.above || val === YPosition.below) {
                        flexDirection = 'row';
                    }
                    else {
                        flexDirection = 'column';
                    }
                    return _a = {},
                        _a["&"] = {
                            flexDirection: flexDirectionContainer
                        },
                        _a["& ." + _this.classes.indicator + ",& ." + _this.classes.indicatorForServer] = (_b = {},
                            _b[position] = 0,
                            _b.height = height,
                            _b.width = width,
                            _b),
                        _a["." + _this.classes.indicatorForServer] = {
                            width: widthServer,
                            height: heightServer
                        },
                        _a["& ." + _this.classes.labels + ",& ." + _this.classes.contents] = { flexDirection: flexDirection },
                        _a["." + _this.classes.contents] = { flexDirection: flexDirection },
                        _a;
                }, this.el.nativeElement, this._headerPlacementClass, STYLE_PRIORITY);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "alignTabs", {
        get: function () {
            return this._alignTabs;
        },
        set: function (val) {
            var _a, _b;
            this._alignTabs = val;
            this._alignTabsClass = this.theme.addStyle("lyAlignTabs: " + val, (val === 'stretch' ? (_a = {},
                _a["& ." + this.classes.labels + " ." + this.classes.tab] = {
                    flexBasis: 0,
                    flexGrow: 1
                },
                _a) : (_b = {},
                _b["& ." + this.classes.labels] = {
                    justifyContent: val in AlignAlias ? AlignAlias[val] : val
                },
                _b)), this.el.nativeElement, this._alignTabsClass, STYLE_PRIORITY);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "textColor", {
        get: function () {
            return this._textColor;
        },
        set: function (val) {
            var _this = this;
            this._textColor = val;
            this._textColorClass = this.theme.addStyle("lyTabs.textColor:" + val, function (theme) {
                var _a;
                return (_a = {},
                    _a["& ." + _this.classes.labelActive] = {
                        color: theme.colorOf(val)
                    },
                    _a);
            }, this.el.nativeElement, this._textColorClass, STYLE_PRIORITY);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LyTabs.prototype, "selectedIndex", {
        get: function () {
            return this._selectedIndex;
        },
        set: function (val) {
            var _this = this;
            if (val !== this.selectedIndex) {
                this._selectedBeforeIndex = this._selectedIndex;
                this._selectedIndex = this._findIndex(val, 'auto');
                this._selectedBeforeTab = this._selectedTab;
                if (this._isViewInitLoaded) {
                    this._updateTabs();
                }
                else {
                    Promise.resolve(null).then(function () { return _this._updateTabs(); });
                }
                this.selectedIndexChange.emit(this._selectedIndex);
                this._markForCheck();
            }
        },
        enumerable: true,
        configurable: true
    });
    LyTabs.prototype.ngOnChanges = function () {
        if (this._isViewInitLoaded) {
            this.updateStyle(this.tabsRef.nativeElement);
        }
    };
    LyTabs.prototype.ngOnInit = function () {
        if (this.selectedIndex == null) {
            this.selectedIndex = 0;
        }
        this.renderer.addClass(this.el.nativeElement, this.classes.root);
        var tabsIndicatorEl = this.tabsIndicator.nativeElement;
        this.renderer.addClass(tabsIndicatorEl, this.classes.indicator);
        /** Set default Color */
        if (!this.indicatorColor && !this.bg && !this.textColor && !this.elevation) {
            this.indicatorColor = DEFAULT_INDICATOR_COLOR;
            this.bg = DEFAULT_BG;
            this.elevation = DEFAULT_ELEVATION;
        }
        if (!this.headerPlacement) {
            this.headerPlacement = DEFAULT_HEADER_PLACEMENT;
        }
    };
    LyTabs.prototype.ngAfterContentInit = function () {
        var _this = this;
        this._tabsSubscription = this.tabsList.changes.subscribe(function () {
            if (_this._selectedIndex !== _this.selectedIndexOnChange) {
                _this.selectedIndex = _this._findIndex(_this.selectedIndex, _this.selectedIndexOnChange);
            }
            _this.cd.markForCheck();
        });
    };
    LyTabs.prototype.ngAfterViewInit = function () {
        var _this = this;
        this._isViewInitLoaded = true;
        this.tabsList.changes
            .pipe(switchMapTo(this._ngZone.onStable.asObservable().pipe(take(1))), takeUntil(this._destroy))
            .subscribe(function () {
            _this._updateTabs();
        });
        this._updateTabs();
        this.updateStyle(this.tabsRef.nativeElement);
        if (this._platform.isBrowser) {
            this._tabResizeSub = this._viewportRuler.change().subscribe(function () {
                if (_this._selectedTab) {
                    _this._updateIndicator(_this._selectedTab);
                    _this._selectedTab._tabLabel._updateTabScroll();
                }
            });
        }
    };
    LyTabs.prototype.ngOnDestroy = function () {
        this._destroy.next();
        this._destroy.complete();
        this._tabsSubscription.unsubscribe();
        if (this._tabResizeSub) {
            this._tabResizeSub.unsubscribe();
        }
        this._clearTimeouts();
    };
    LyTabs.prototype._findIndex = function (selectedIndex, index) {
        if (!this.tabsList) {
            return selectedIndex;
        }
        var indexOfLastTab = this.tabsList.length - 1;
        var currentIndex = typeof index === 'number' ? index : selectedIndex;
        return currentIndex < 0 ? 0 : currentIndex > indexOfLastTab ? indexOfLastTab : currentIndex;
    };
    LyTabs.prototype._updateIndicator = function (currentTab, beforeTab) {
        if (currentTab) {
            if (beforeTab) {
                beforeTab._renderer.removeAttribute(beforeTab._tabIndicator.nativeElement, 'class');
            }
            var el = currentTab._el.nativeElement;
            var rects = el.getBoundingClientRect();
            if (this.headerPlacement === XPosition.after || this.headerPlacement === XPosition.before) {
                this.renderer.setStyle(this.tabsIndicator.nativeElement, 'height', rects.height + "px");
                this.renderer.setStyle(this.tabsIndicator.nativeElement, 'top', el.offsetTop + "px");
                this.renderer.removeStyle(this.tabsIndicator.nativeElement, 'width');
                this.renderer.removeStyle(this.tabsIndicator.nativeElement, 'left');
            }
            else {
                this.renderer.setStyle(this.tabsIndicator.nativeElement, 'width', rects.width + "px");
                this.renderer.setStyle(this.tabsIndicator.nativeElement, 'left', el.offsetLeft + "px");
                this.renderer.removeStyle(this.tabsIndicator.nativeElement, 'height');
                this.renderer.removeStyle(this.tabsIndicator.nativeElement, 'top');
            }
        }
    };
    LyTabs.prototype._markForCheck = function () {
        this.cd.markForCheck();
    };
    LyTabs.prototype._updateTabs = function () {
        var _this = this;
        if (!this._isViewInitLoaded) {
            return;
        }
        var tabsContents = this.tabContentList.toArray();
        var tabsForUpdate = [];
        this.tabsList.forEach(function (tab, index) {
            var tabContent = tabsContents[index].nativeElement;
            if (_this.selectedIndex === index || _this._selectedBeforeIndex === index) {
                tab._activeContent = true;
                tabsForUpdate.push([tab, tabContent, index]);
            }
            else {
                if (_this.keepContent) {
                    _this.renderer.addClass(tabContent, _this.classes.hiddenContent);
                }
            }
        });
        this._ngZone.run(function () {
            _this._markForCheck();
        });
        this._ngZone.onStable.asObservable()
            .pipe(take(1), takeUntil(this._destroy))
            .subscribe(function () {
            return tabsForUpdate.forEach(function (parms) {
                return _this._updateContentStyle.apply(_this, __spread(parms));
            });
        });
    };
    LyTabs.prototype.loadTemplate = function (tab, index) {
        var _this = this;
        tab.index = index;
        if (this.selectedIndex === tab.index) {
            // set 0 if is null
            this._selectedTab = tab;
            Promise.resolve(null).then(function () {
                // this._updateDynamicHeight(tabContent, index);
                if (_this._platform.isBrowser) {
                    _this._updateIndicator(tab);
                }
                else {
                    // for server
                    var selectedBeforeTab = _this._selectedBeforeTab;
                    if (selectedBeforeTab) {
                        _this.renderer.removeClass(selectedBeforeTab._tabIndicator.nativeElement, _this.classes.indicatorForServer);
                    }
                    _this.renderer.addClass(_this._selectedTab._tabIndicator.nativeElement, _this.classes.indicatorForServer);
                }
            });
        }
        else if (this._selectedBeforeIndex === index) {
            // Promise.resolve(null).then(() => this._updateDynamicHeight(tabContent, index));
        }
        tab._tabLabel._updateTabState();
        if (this.keepContent) {
            return tab.content;
        }
        if (tab._activeContent) {
            return tab.content;
        }
        return null;
    };
    LyTabs.prototype._getFlexDirection = function (val) {
        var flexDirection;
        if (val === YPosition.above || val === YPosition.below) {
            flexDirection = 'row';
        }
        else {
            flexDirection = 'column';
        }
        return flexDirection;
    };
    LyTabs.prototype._updateContentStyle = function (tab, tabContent, index) {
        var _this = this;
        if (this.selectedIndex === index || this._selectedBeforeIndex === index) {
            var prevIndex = this._selectedBeforeIndex;
            var currentIndex_1 = this.selectedIndex;
            var dynamicHeight_1 = this.dynamicHeight && this._platform.isBrowser && prevIndex != null;
            var contentInner = tabContent.firstElementChild;
            var contentHeight = dynamicHeight_1 ? contentInner.getBoundingClientRect().height : null;
            var contentHeightPrev = dynamicHeight_1
                ? this.tabContentList.toArray()[prevIndex].nativeElement.firstElementChild.getBoundingClientRect().height
                : null;
            if (currentIndex_1 === index) {
                this.renderer.addClass(tabContent, this.classes.contentActive);
                if (this.keepContent) {
                    this.renderer.removeClass(tabContent, this.classes.hiddenContent);
                }
            }
            else {
                this.renderer.removeClass(tabContent, this.classes.contentActive);
            }
            if (prevIndex == null || !this._platform.isBrowser || prevIndex === currentIndex_1) {
                return;
            }
            this._clearTimeouts(index);
            var before = this._theme.variables.before;
            var isDirRow = this.headerPlacement === XPosition.after
                || this.headerPlacement === XPosition.before;
            var x = before === 'left'
                ? 100
                : isDirRow
                    ? 100
                    : -100;
            if (currentIndex_1 === index) {
                var sign = prevIndex < index ? 1 : -1;
                var pos = isDirRow ? "0," + x * sign + "%" : x * sign + "%, 0";
                tabContent.style.overflow = 'hidden';
                if (dynamicHeight_1) {
                    tabContent.style.height = contentHeightPrev + "px";
                }
                tabContent.style.transform = "translate3d(" + pos + ", 0)";
                enforceStyleRecalculation(tabContent);
                tabContent.style.transition = this.animationDuration + "ms cubic-bezier(0.35, 0, 0.25, 1)";
                tabContent.style.transform = "translate3d(0%, 0, 0)";
                if (dynamicHeight_1) {
                    tabContent.style.height = contentHeight + "px";
                }
            }
            else {
                var sign = currentIndex_1 < index ? 1 : -1;
                var pos = isDirRow ? "0," + x * sign + "%" : x * sign + "%, 0";
                tabContent.style.overflow = 'hidden';
                tabContent.style.transform = "translate3d(0%, 0, 0)";
                enforceStyleRecalculation(tabContent);
                tabContent.style.transition = this.animationDuration + "ms cubic-bezier(0.35, 0, 0.25, 1)";
                tabContent.style.transform = "translate3d(" + pos + ", 0)";
            }
            this._runTimeoutOutsideZone(index, function () {
                tabContent.style.transform = "";
                tabContent.style.transition = "";
                tabContent.style.overflow = "";
                if (dynamicHeight_1) {
                    tabContent.style.height = "";
                }
                if (currentIndex_1 !== index) {
                    if (_this.keepContent) {
                        _this.renderer.addClass(tabContent, _this.classes.hiddenContent);
                    }
                    tab._activeContent = false;
                    _this._ngZone.run(function () { return _this._markForCheck(); });
                }
            }, this.animationDuration);
        }
    };
    /** Runs a timeout outside of the Angular zone to avoid triggering the change detection. */
    LyTabs.prototype._runTimeoutOutsideZone = function (index, fn, delay) {
        var _this = this;
        if (delay === void 0) { delay = 0; }
        this._ngZone.runOutsideAngular(function () { return _this._timeoutIds["_" + index] = window.setTimeout(fn, delay); });
    };
    LyTabs.prototype._clearTimeouts = function (tabIndex) {
        var _this = this;
        if (tabIndex != null) {
            var key = "_" + tabIndex;
            if (this._timeoutIds[key] != null) {
                window.clearTimeout(this._timeoutIds[key]);
                delete this._timeoutIds[key];
            }
        }
        else {
            Object.keys(this._timeoutIds)
                .forEach(function (key) { return window.clearTimeout(_this._timeoutIds["_" + key]); });
        }
    };
    /** @docs-private */
    LyTabs.и = 'LyTabs';
    LyTabs.ctorParameters = function () { return [
        { type: LyTheme2 },
        { type: Renderer2 },
        { type: ElementRef },
        { type: ChangeDetectorRef },
        { type: ViewportRuler },
        { type: StyleRenderer },
        { type: Platform },
        { type: NgZone }
    ]; };
    __decorate([
        ViewChild('tabs', { static: true })
    ], LyTabs.prototype, "tabsRef", void 0);
    __decorate([
        ViewChild('tabContents', { static: true })
    ], LyTabs.prototype, "tabContents", void 0);
    __decorate([
        ViewChild('tabsIndicator', { static: true, read: ElementRef })
    ], LyTabs.prototype, "tabsIndicator", void 0);
    __decorate([
        Input()
    ], LyTabs.prototype, "selectedIndexOnChange", void 0);
    __decorate([
        Input()
    ], LyTabs.prototype, "keepContent", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "animationDuration", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "dynamicHeight", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "scrollable", null);
    __decorate([
        Input(),
        Style(ɵ0)
    ], LyTabs.prototype, "indicatorColor", void 0);
    __decorate([
        Input()
    ], LyTabs.prototype, "headerPlacement", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "alignTabs", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "textColor", null);
    __decorate([
        Input()
    ], LyTabs.prototype, "selectedIndex", null);
    __decorate([
        Output()
    ], LyTabs.prototype, "selectedIndexChange", void 0);
    __decorate([
        ContentChildren(forwardRef(function () { return LyTab; }))
    ], LyTabs.prototype, "tabsList", void 0);
    __decorate([
        ViewChildren('tabContent')
    ], LyTabs.prototype, "tabContentList", void 0);
    LyTabs = __decorate([
        Component({
            selector: 'ly-tabs',
            template: "<div #tabs [className]=\"classes.labelsContainer\">\n  <div [className]=\"classes.labels\">\n    <ng-content></ng-content>\n    <span #tabsIndicator></span>\n  </div>\n</div>\n<div [className]=\"classes.contentContainer\">\n  <div [className]=\"classes.contents\" #tabContents>\n    <div #tabContent *ngFor=\"let item of tabsList; index as x\" [className]=\"classes.content\">\n      <div [className]=\"classes.contentInner\">\n        <ng-template\n          [cdkPortalOutlet]=\"loadTemplate(item, x)\"\n        ></ng-template>\n      </div>\n    </div>\n  </div>\n</div>\n",
            changeDetection: ChangeDetectionStrategy.OnPush,
            encapsulation: ViewEncapsulation.None,
            exportAs: 'lyTabs',
            inputs: [
                'bg', 'elevation', 'shadowColor'
            ],
            providers: [
                StyleRenderer
            ]
        })
    ], LyTabs);
    return LyTabs;
}(LyTabsMixinBase));
var LyTab = /** @class */ (function () {
    function LyTab(_tabs, _renderer, _el, sRenderer, _platform, _viewContainerRef) {
        this._tabs = _tabs;
        this._renderer = _renderer;
        this._el = _el;
        this.sRenderer = sRenderer;
        this._platform = _platform;
        this._viewContainerRef = _viewContainerRef;
        this._isBrowser = this._platform.isBrowser;
        /** Portal that will be the hosted content of the tab */
        this._contentPortal = null;
    }
    Object.defineProperty(LyTab.prototype, "content", {
        /** @docs-private */
        get: function () {
            return this._contentPortal;
        },
        enumerable: true,
        configurable: true
    });
    LyTab.prototype.ngOnInit = function () {
        this._renderer.addClass(this._el.nativeElement, this._tabs.classes.tab);
        this._contentPortal = new TemplatePortal(this._templateRefLazy || this._templateRef, this._viewContainerRef);
    };
    LyTab.ctorParameters = function () { return [
        { type: LyTabs },
        { type: Renderer2 },
        { type: ElementRef },
        { type: StyleRenderer },
        { type: Platform },
        { type: ViewContainerRef }
    ]; };
    __decorate([
        ContentChild(LyTabContent, { read: TemplateRef, static: true })
    ], LyTab.prototype, "_templateRefLazy", void 0);
    __decorate([
        ViewChild('_templateNgContent', { static: true })
    ], LyTab.prototype, "_templateRef", void 0);
    __decorate([
        ViewChild('tabIndicator', { static: false })
    ], LyTab.prototype, "_tabIndicator", void 0);
    __decorate([
        ContentChild(forwardRef(function () { return LyTabLabel; }), { static: true })
    ], LyTab.prototype, "_tabLabel", void 0);
    LyTab = __decorate([
        Component({
            selector: 'ly-tab',
            template: "<ng-content select=\"ly-tab-label\"></ng-content>\n<ng-content select=\"[ly-tab-label]\"></ng-content>\n<ng-content select=\"[ly-tab-label-native]\"></ng-content>\n<div></div>\n<span *ngIf=\"!_isBrowser\" #tabIndicator></span>\n<ng-template #_templateNgContent>\n  <ng-content></ng-content>\n</ng-template>",
            changeDetection: ChangeDetectionStrategy.OnPush,
            encapsulation: ViewEncapsulation.None,
            providers: [
                StyleRenderer
            ]
        })
    ], LyTab);
    return LyTab;
}());
var LyTabLabel = /** @class */ (function (_super) {
    __extends(LyTabLabel, _super);
    function LyTabLabel(_el, _renderer, _theme, _ngZone, _rippleService, _focusState, sRenderer, _tab, _tabs, platform) {
        var _this = _super.call(this, _el, _renderer, _theme, _ngZone, _rippleService, _focusState, sRenderer, platform, null) || this;
        _this.sRenderer = sRenderer;
        _this._tab = _tab;
        _this._tabs = _tabs;
        _this._isBrowser = _this._platform.isBrowser;
        return _this;
    }
    Object.defineProperty(LyTabLabel.prototype, "active", {
        get: function () {
            return this._active;
        },
        set: function (val) {
            var _this = this;
            var newVal = toBoolean(val);
            if (newVal && val !== this.active) {
                Promise.resolve(null).then(function () { return _this._tabs.selectedIndex = _this._tab.index; });
            }
        },
        enumerable: true,
        configurable: true
    });
    LyTabLabel.prototype._onClickTab = function () {
        if (!this.disabled) {
            this._tabs.selectedIndex = this._tab.index;
        }
    };
    LyTabLabel.prototype.ngOnInit = function () {
        this._renderer.addClass(this._el.nativeElement, this._tabs.classes.label);
        // set default disable ripple
        if (this.disableRipple == null) {
            this.disableRipple = DEFAULT_DISABLE_RIPPLE;
        }
    };
    LyTabLabel.prototype._updateTabState = function () {
        // update styles for active tab
        if (this._tabs._selectedIndex === this._tab.index) {
            if (!this._activeTabStyle) {
                this._activeTabStyle = true;
                this._renderer.addClass(this._el.nativeElement, this._tabs.classes.labelActive);
                this._updateTabScroll();
            }
        }
        else if (this._activeTabStyle) {
            this._activeTabStyle = false;
            this._renderer.removeClass(this._el.nativeElement, this._tabs.classes.labelActive);
        }
    };
    LyTabLabel.prototype._updateTabScroll = function () {
        if (this._platform.isBrowser && this._tabs.scrollable) {
            var tab = this._tab._el.nativeElement;
            var tabContainer = this._tabs.tabsRef.nativeElement;
            if (tabContainer.scrollWidth !== tabContainer.offsetWidth) {
                var dir = this._theme.variables.direction;
                var max = tabContainer.scrollWidth - tabContainer.offsetWidth;
                var offsetBefore = dir === Dir.rtl
                    ? max + tab.offsetLeft
                    : tab.offsetLeft;
                var l = offsetBefore + tab.offsetWidth / 2 - tabContainer.offsetWidth / 2;
                var newVal = l >= max ? max : l <= 0 ? 0 : l;
                scrollWithAnimation(this._tabs.tabsRef.nativeElement, newVal, 350, 'x');
            }
        }
    };
    LyTabLabel.prototype.ngAfterViewInit = function () { };
    LyTabLabel.ctorParameters = function () { return [
        { type: ElementRef },
        { type: Renderer2 },
        { type: LyTheme2 },
        { type: NgZone },
        { type: LyRippleService },
        { type: LyFocusState },
        { type: StyleRenderer },
        { type: LyTab, decorators: [{ type: Optional }] },
        { type: LyTabs, decorators: [{ type: Optional }] },
        { type: Platform }
    ]; };
    __decorate([
        Input()
    ], LyTabLabel.prototype, "active", null);
    __decorate([
        ViewChild('rippleContainer', { static: false })
    ], LyTabLabel.prototype, "_rippleContainer", void 0);
    __decorate([
        HostListener('click')
    ], LyTabLabel.prototype, "_onClickTab", null);
    LyTabLabel = __decorate([
        Component({
            selector: 'button[ly-tab-label], a[ly-tab-label]',
            template: "<span [className]=\"classes.content\">\n  <ng-content></ng-content>\n</span>\n<div *ngIf=\"_isBrowser\" #rippleContainer [className]=\"_rippleService.classes.container\"></div>\n",
            inputs: [
                'bg',
                'color',
                'raised',
                'disabled',
                'outlined',
                'elevation',
                'shadowColor',
                'disableRipple'
            ],
            providers: [
                StyleRenderer
            ]
        }),
        __param(7, Optional()),
        __param(8, Optional())
    ], LyTabLabel);
    return LyTabLabel;
}(LyButton));
/** Enforces a style recalculation of a DOM element by computing its styles. */
function enforceStyleRecalculation(element) {
    window.getComputedStyle(element).getPropertyValue('opacity');
}

var LyTabsModule = /** @class */ (function () {
    function LyTabsModule() {
    }
    LyTabsModule = __decorate([
        NgModule({
            imports: [
                LyThemeModule,
                CommonModule,
                LyCommonModule,
                NgTranscludeModule,
                PortalModule
            ],
            exports: [LyCommonModule, LyTabs, LyTab, LyTabLabel, LyTabContent],
            declarations: [LyTabs, LyTab, LyTabLabel, LyTabContent]
        })
    ], LyTabsModule);
    return LyTabsModule;
}());

/**
 * Generated bundle index. Do not edit.
 */

export { LyTab, LyTabLabel, LyTabLabelBase, LyTabLabelMixinBase, LyTabs, LyTabsBase, LyTabsMixinBase, LyTabsModule, STYLES, ɵ0, LyTabContent as ɵa };
//# sourceMappingURL=alyle-ui-tabs.js.map
