import { __classPrivateFieldSet, __classPrivateFieldGet, __awaiter } from 'tslib';
import { filter, take, debounceTime, map } from 'rxjs/operators';
import { ɵɵdefineInjectable, ɵɵinject, Injectable, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, ElementRef, ViewChild, HostListener, Injector, Compiler, Pipe, Directive, NgModule } from '@angular/core';
import { BehaviorSubject, Subscription, of } from 'rxjs';
import { SdNotifyService } from '@sd-angular/core/notify';
import { moveItemInArray, DragDropModule } from '@angular/cdk/drag-drop';
import { RoutesRecognized, NavigationEnd, Router, ActivatedRoute, RouterLinkWithHref, RouterModule } from '@angular/router';
import hash from 'object-hash';
import { CommonModule } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';

var _tab;
class SdTabBase {
    constructor(tab) {
        _tab.set(this, void 0);
        __classPrivateFieldSet(this, _tab, tab);
    }
    get tab() {
        return __classPrivateFieldGet(this, _tab);
    }
}
_tab = new WeakMap();
class SdTabActivated extends SdTabBase {
}
class SdTabDeactivated extends SdTabBase {
}

var _currentTab, _componentBuilders;
class SdTabRouterService {
    constructor(notifyService) {
        this.notifyService = notifyService;
        this.events = new BehaviorSubject(new SdTabBase(null));
        this.actions = new BehaviorSubject(null);
        this.builders = new BehaviorSubject([]);
        this.currentTabChanges = new BehaviorSubject(null);
        this.newTabs = new BehaviorSubject(null);
        _currentTab.set(this, null);
        _componentBuilders.set(this, []);
        this.addBuilder = (builder) => {
            if (!__classPrivateFieldGet(this, _componentBuilders).some(e => e.component === builder.component)) {
                __classPrivateFieldGet(this, _componentBuilders).push(builder);
                this.builders.next(__classPrivateFieldGet(this, _componentBuilders));
            }
        };
        // select = (tabOrKey: string | SdTab): void => {
        //   const tab = this.#tabs.find(e => {
        //     if (typeof (tabOrKey) === 'string') {
        //       return e.key === tabOrKey;
        //     }
        //     return e.key === tabOrKey?.key;
        //   });
        //   if (tab) {
        //     this.#currentTab = tab;
        //   }
        // }
        // add = (tab: SdTab): void => {
        //   if (!tab.key) {
        //     this.notifyService.notify.warning('Tab key is required');
        //   }
        //   if (!tab.component) {
        //     this.notifyService.notify.warning('Tab component is required');
        //   }
        //   const existedTab = this.#tabs.find(e => e.key === tab.key);
        //   if (!existedTab) {
        //     this.#tabs.push(tab);
        //     this.select(tab);
        //   } else {
        //     this.select(existedTab);
        //   }
        // }
        // remove = (tabOrKey: string | SdTab): void => {
        //   this.#tabs = this.#tabs.filter(e => {
        //     if (typeof (tabOrKey) === 'string') {
        //       return e.key !== tabOrKey;
        //     }
        //     return e.key !== tabOrKey?.key;
        //   });
        // }
        this.setCurrentTab = (tab) => {
            __classPrivateFieldSet(this, _currentTab, tab);
            this.currentTabChanges.next(tab);
        };
        this.pushEvent = (tab, Event) => {
            this.events.next(new Event(tab));
        };
        this.setOptions = () => { };
        this.close = (tab) => {
            if (tab) {
                this.actions.next({
                    type: 'close',
                    tab,
                });
            }
            else if (__classPrivateFieldGet(this, _currentTab)) {
                this.actions.next({
                    type: 'close',
                    tab: __classPrivateFieldGet(this, _currentTab),
                });
            }
        };
    }
    get currentTab() {
        return __classPrivateFieldGet(this, _currentTab);
    }
    get key() {
        var _a;
        return ((_a = __classPrivateFieldGet(this, _currentTab)) === null || _a === void 0 ? void 0 : _a.key) || null;
    }
}
_currentTab = new WeakMap(), _componentBuilders = new WeakMap();
SdTabRouterService.ɵprov = ɵɵdefineInjectable({ factory: function SdTabRouterService_Factory() { return new SdTabRouterService(ɵɵinject(SdNotifyService)); }, token: SdTabRouterService, providedIn: "root" });
SdTabRouterService.decorators = [
    { type: Injectable, args: [{
                providedIn: 'root',
            },] }
];
SdTabRouterService.ctorParameters = () => [
    { type: SdNotifyService }
];

class SdTabDecoratorService {
    constructor(tabRouterService) {
        SdTabDecoratorService.tabRouterService.next(tabRouterService);
    }
}
SdTabDecoratorService.tabRouterService = new BehaviorSubject(undefined);
SdTabDecoratorService.ɵprov = ɵɵdefineInjectable({ factory: function SdTabDecoratorService_Factory() { return new SdTabDecoratorService(ɵɵinject(SdTabRouterService)); }, token: SdTabDecoratorService, providedIn: "root" });
SdTabDecoratorService.decorators = [
    { type: Injectable, args: [{
                providedIn: 'root'
            },] }
];
SdTabDecoratorService.ctorParameters = () => [
    { type: SdTabRouterService }
];

function SdTabComponent(builder) {
    return (constructor) => {
        SdTabDecoratorService.tabRouterService.pipe(filter(service => service !== undefined && service !== null), take(1)).subscribe(service => {
            service.addBuilder(builder);
        });
    };
}

var _subsctiption;
class SdTabRouterItemComponent {
    constructor(cdRef, tabRouterService) {
        this.cdRef = cdRef;
        this.tabRouterService = tabRouterService;
        _subsctiption.set(this, new Subscription());
        this.close = (event) => {
            event.preventDefault();
            event.stopPropagation();
            this.tabRouterService.close(this.tab);
        };
    }
    ngOnInit() {
        __classPrivateFieldGet(this, _subsctiption).add(this.tabRouterService.events.pipe(debounceTime(100)).subscribe(() => {
            this.cdRef.markForCheck();
        }));
    }
    ngOnDestroy() {
        __classPrivateFieldGet(this, _subsctiption).unsubscribe();
    }
}
_subsctiption = new WeakMap();
SdTabRouterItemComponent.decorators = [
    { type: Component, args: [{
                selector: "sd-tab-router-item",
                template: "<a [routerLink]=\"[tab.url]\" [queryParams]=\"tab.queryParams\" [state]=\"{ switchTab: true }\"\r\n  class=\"tab-router__item d-flex align-items-center\" [ngClass]=\"{\r\n    'tab-router__item--active': tab.isActive\r\n  }\">\r\n  <ng-container *ngIf=\"tab.overrideTabInfo | sdTabInfo:tab | async as tabInfo\">\r\n    <div class=\"\r\n    tab-router__icon\r\n    mr-8\r\n  \" [ngStyle]=\"{\r\n    'background-color': tabInfo.color\r\n  }\" [matTooltip]=\"tabInfo.tooltip || tabInfo.name\" matTooltipPosition=\"below\" matTooltipShowDelay=\"1000\">\r\n      {{ tabInfo.initialName || 'SD' }}\r\n    </div>\r\n    <div class=\"flex-1 overflow-hidden\">\r\n      <div class=\"tab-router__name\" [matTooltip]=\"tabInfo.tooltip || tabInfo.name\" matTooltipPosition=\"below\"\r\n        matTooltipShowDelay=\"1000\">\r\n        {{ tabInfo.name }}\r\n      </div>\r\n    </div>\r\n    <button aria-hidden=\"true\" type=\"button\"\r\n      class=\"tab-router__close d-flex align-items-center justify-content-center ml-4\" (click)=\"close($event)\"\r\n      (mousedown)=\"$event.stopPropagation()\">\r\n      <mat-icon aria-hidden=\"true\">close</mat-icon>\r\n    </button>\r\n  </ng-container>\r\n</a>",
                changeDetection: ChangeDetectionStrategy.OnPush,
                styles: [":host{display:block;flex:1 1 64px;max-width:240px;overflow:hidden;position:relative}:host:after{background:#dde0e5;bottom:0;content:\"\";height:16px;margin:auto;position:absolute;right:0;top:0;width:1px}:host:last-child:after{content:none}.flex-1{flex:1}.tab-router__icon{background-color:#5c6bc0;border-radius:2px;color:#fff;font-size:10px;height:16px;line-height:16px;text-align:center;text-transform:uppercase;width:16px}.tab-router__icon .mat-icon{font-size:10px;height:10px;width:10px}.tab-router__close{background:none;border:0;border-radius:50%;color:#757575;height:16px;outline:none;width:16px}.tab-router__close:hover{background-color:rgba(0,0,0,.12)}.tab-router__close .mat-icon{font-size:12px;height:12px;width:12px}.tab-router__item{background:#f2f3f4;color:inherit;font-size:12px;line-height:16px;overflow:hidden;padding:16px 16px 8px;text-decoration:none}.tab-router__item:hover{background-color:#fff}.tab-router__name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tab-router__item--active{background-color:#fff;border-radius:8px 8px 0 0}"]
            },] }
];
SdTabRouterItemComponent.ctorParameters = () => [
    { type: ChangeDetectorRef },
    { type: SdTabRouterService }
];
SdTabRouterItemComponent.propDecorators = {
    tab: [{ type: Input }]
};

class SdTabRouterNavComponent {
    constructor(cdRef, elementRef) {
        this.cdRef = cdRef;
        this.elementRef = elementRef;
        this.mode = 'default';
        this.checkUI = () => {
            const width = this.tabRouterNav.nativeElement.clientWidth;
            const nameWidth = (width - this.tabs.length * 68) / this.tabs.length;
            if (nameWidth <= 20) {
                this.mode = 'compact';
            }
            else {
                this.mode = 'default';
            }
            this.cdRef.markForCheck();
        };
        this.onDrop = (event) => {
            moveItemInArray(this.tabs, event.previousIndex, event.currentIndex);
        };
    }
    onResize(event) {
        this.checkUI();
    }
}
SdTabRouterNavComponent.decorators = [
    { type: Component, args: [{
                selector: 'sd-tab-router-nav',
                template: "<div\r\n  #tabRouterNav\r\n  cdkDropList\r\n  cdkDropListLockAxis=\"x\"\r\n  cdkDropListOrientation=\"horizontal\"\r\n  (cdkDropListDropped)=\"onDrop($event)\"\r\n  class=\"tab-router__nav tab-router__nav--{{ mode }} d-flex align-items-center flex-nowrap\"\r\n  [class.d-none]=\"tabs?.length > 1\"\r\n>\r\n  <ng-container *ngFor=\"let tab of tabs\">\r\n    <sd-tab-router-item [tab]=\"tab\" cdkDrag [cdkDragBoundary]=\"elementRef?.nativeElement\"></sd-tab-router-item>\r\n  </ng-container>\r\n</div>\r\n",
                changeDetection: ChangeDetectionStrategy.OnPush,
                styles: [".tab-router__nav{background:#f9f9f9;overflow:hidden}.tab-router__nav--compact::ng-deep .tab-router__name{display:none}.tab-router__nav--compact::ng-deep .tab-router__icon{margin:0!important}.tab-router__nav--compact::ng-deep .tab-router__item--active{min-width:240px}.tab-router__nav--compact::ng-deep .tab-router__item--active .tab-router__icon{margin-right:8px!important}.tab-router__nav--compact::ng-deep .tab-router__item--active .tab-router__name{display:-webkit-box}"]
            },] }
];
SdTabRouterNavComponent.ctorParameters = () => [
    { type: ChangeDetectorRef },
    { type: ElementRef }
];
SdTabRouterNavComponent.propDecorators = {
    tabRouterNav: [{ type: ViewChild, args: ['tabRouterNav',] }],
    tabs: [{ type: Input }],
    onResize: [{ type: HostListener, args: ['window:resize', ['$event'],] }]
};

var _rootRoute, _subscription, _firstLoad, _closeTab, _activeRoute, _getActivatedRouteSnapshot, _getActivatedRoute;
class SdTabRouterOutletComponent {
    constructor(router, activatedRoute, cd, injector, compiler, tabDecoratorService, // KHÔNG XÓA
    tabRouterService, sdNotifyService) {
        this.router = router;
        this.activatedRoute = activatedRoute;
        this.cd = cd;
        this.injector = injector;
        this.compiler = compiler;
        this.tabDecoratorService = tabDecoratorService;
        this.tabRouterService = tabRouterService;
        this.sdNotifyService = sdNotifyService;
        this.tabs = [];
        _rootRoute.set(this, void 0);
        _subscription.set(this, new Subscription());
        _firstLoad.set(this, true);
        this.tabTrackBy = (index, tab) => {
            return tab.key;
        };
        _closeTab.set(this, (tab) => {
            var _a;
            const { isActive, key: activeKey } = tab;
            if (isActive) {
                const activeIndex = this.tabs.findIndex(({ key }) => key === activeKey);
                const nextTab = this.tabs[activeIndex + 1] || this.tabs[activeIndex - 1];
                if (nextTab) {
                    const { url: nextUrl } = nextTab;
                    const nextQueryParams = Object.assign({}, (nextTab.queryParams || {}));
                    this.tabs = this.tabs.filter(({ key }) => key !== activeKey);
                    this.router.navigate([nextUrl], {
                        queryParams: nextQueryParams,
                        state: {
                            switchTab: true,
                        },
                    });
                }
                else {
                    this.tabs = this.tabs.filter(({ key }) => key !== activeKey);
                    this.router.navigateByUrl('/', {
                        state: {
                            switchTab: true,
                        },
                    });
                }
            }
            else {
                this.tabs = this.tabs.filter(({ key }) => key !== tab.key);
                (_a = this.tabRouterNav) === null || _a === void 0 ? void 0 : _a.checkUI();
                this.cd.markForCheck();
            }
        });
        _activeRoute.set(this, (fullUrl, route) => __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j;
            if (!(route === null || route === void 0 ? void 0 : route.component)) {
                return;
            }
            const component = route.component;
            const queryParams = Object.assign({}, (route.queryParams || {}));
            const params = Object.assign({}, (route.params || {}));
            const data = Object.assign({}, (route.data || {}));
            const [url] = fullUrl.split('?');
            const key = hash({ url, queryParams });
            let existedIndex = -1;
            let activatedIndex = -1;
            this.tabs.forEach((tab, index) => {
                if (tab.key === key) {
                    tab.isActive = true;
                    existedIndex = index;
                }
                else {
                    if (tab.isActive) {
                        activatedIndex = index;
                        this.tabRouterService.pushEvent(tab, SdTabDeactivated);
                    }
                    tab.isActive = false;
                }
            });
            const currentNavigation = this.router.getCurrentNavigation();
            // Switch tab sẽ ko re-render lại trang
            const switchTab = (_b = (_a = currentNavigation === null || currentNavigation === void 0 ? void 0 : currentNavigation.extras) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.switchTab;
            // Replace tab sẽ close trang hiện tại
            const replaceTab = (_d = (_c = currentNavigation === null || currentNavigation === void 0 ? void 0 : currentNavigation.extras) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.replaceTab;
            if (existedIndex >= 0) {
                const existedTab = this.tabs[existedIndex];
                if (replaceTab && activatedIndex >= 0) {
                    if (activatedIndex >= 0) {
                        this.tabs.splice(activatedIndex, 1);
                    }
                }
                if (switchTab) {
                    this.tabRouterService.setCurrentTab(existedTab);
                    this.tabRouterService.pushEvent(existedTab, SdTabActivated);
                }
                else {
                    if (typeof ((_f = (_e = route === null || route === void 0 ? void 0 : route.parent) === null || _e === void 0 ? void 0 : _e.routeConfig) === null || _f === void 0 ? void 0 : _f.loadChildren) === 'function') {
                        const module = yield route.parent.routeConfig.loadChildren();
                        const factory = yield this.compiler.compileModuleAsync(module);
                        const injector = factory.create(this.injector);
                        const activatedRoute = __classPrivateFieldGet(this, _getActivatedRoute).call(this, __classPrivateFieldGet(this, _rootRoute), component);
                        const tab = {
                            key,
                            component,
                            injector: new SdOutletInjector(activatedRoute, injector),
                            isActive: true,
                            name: url,
                            url,
                            params,
                            queryParams,
                            data
                        };
                        this.tabs[this.tabs.indexOf(existedTab)] = tab;
                    }
                }
            }
            else {
                if (typeof ((_h = (_g = route === null || route === void 0 ? void 0 : route.parent) === null || _g === void 0 ? void 0 : _g.routeConfig) === null || _h === void 0 ? void 0 : _h.loadChildren) === 'function') {
                    const module = yield route.parent.routeConfig.loadChildren();
                    const factory = yield this.compiler.compileModuleAsync(module);
                    const injector = factory.create(this.injector);
                    const activatedRoute = __classPrivateFieldGet(this, _getActivatedRoute).call(this, __classPrivateFieldGet(this, _rootRoute), component);
                    const tab = {
                        key,
                        component,
                        injector: new SdOutletInjector(activatedRoute, injector),
                        isActive: true,
                        name: url,
                        url,
                        params,
                        queryParams,
                        data
                    };
                    this.tabRouterService.setCurrentTab(tab);
                    if (activatedIndex >= 0 && replaceTab) {
                        this.tabs.splice(activatedIndex, 1);
                    }
                    this.tabs.push(tab);
                    // if (existedIndex >= 0 && !switchTab) {
                    //   this.tabs[existedIndex] = tab;
                    // } else {
                    //   this.tabs.push(tab);
                    // }
                }
                (_j = this.tabRouterNav) === null || _j === void 0 ? void 0 : _j.checkUI();
                if (this.tabs.length > 10) {
                    this.sdNotifyService.notify.warning('Bạn đã mở quá nhiều tab. Vui lòng tắt các tab không dùng để hệ thống hoạt động tốt hơn.');
                }
                if (this.tabs.length > 15) {
                    this.tabs.splice(0, this.tabs.length - 10);
                }
            }
            // if (existedIndex >= 0 && switchTab) {
            //   const existedTab = this.tabs[existedIndex];
            //   this.tabRouterService.setCurrentTab(existedTab);
            //   this.tabRouterService.pushEvent(existedTab, SdTabActivated);
            // } else {
            //   if (typeof route?.parent?.routeConfig?.loadChildren === 'function') {
            //     const module = await route.parent.routeConfig.loadChildren();
            //     const factory = await this.compiler.compileModuleAsync(module);
            //     const injector = factory.create(this.injector);
            //     const activatedRoute = this.#getActivatedRoute(
            //       this.#rootRoute,
            //       component
            //     );
            //     const tab = {
            //       key,
            //       component,
            //       injector: new SdOutletInjector(activatedRoute, injector),
            //       isActive: true,
            //       name: url,
            //       url,
            //       params,
            //       queryParams,
            //       data
            //     };
            //     this.tabRouterService.setCurrentTab(tab);
            //     if (activatedIndex >= 0 && replaceTab) {
            //       this.tabs.splice(activatedIndex, 1);
            //     }
            //     if (existedIndex >= 0 && !switchTab) {
            //       this.tabs[existedIndex] = tab;
            //     } else {
            //       this.tabs.push(tab);
            //     }
            //   }
            //   this.tabRouterNav?.checkUI();
            //   if (this.tabs.length > 10) {
            //     this.sdNotifyService.notify.warning(
            //       'Bạn đã mở quá nhiều tab. Vui lòng tắt các tab không dùng để hệ thống hoạt động tốt hơn.'
            //     );
            //   }
            //   if (this.tabs.length > 15) {
            //     this.tabs.splice(0, this.tabs.length - 10);
            //   }
            // }
            this.cd.markForCheck();
        }));
        _getActivatedRouteSnapshot.set(this, (activatedRouteSnapshot) => {
            if (!activatedRouteSnapshot) {
                return null;
            }
            while (activatedRouteSnapshot.firstChild) {
                activatedRouteSnapshot = activatedRouteSnapshot.firstChild;
            }
            return activatedRouteSnapshot;
        });
        _getActivatedRoute.set(this, (activatedRoute, component) => {
            if (!activatedRoute) {
                return null;
            }
            if (activatedRoute.component && activatedRoute.component === component) {
                return activatedRoute;
            }
            while (activatedRoute.firstChild) {
                activatedRoute = activatedRoute.firstChild;
                if (activatedRoute.component && activatedRoute.component === component) {
                    return activatedRoute;
                }
            }
            return null;
        });
        __classPrivateFieldGet(this, _subscription).add(router.events
            .pipe(filter((event) => event instanceof RoutesRecognized ||
            event instanceof NavigationEnd))
            .subscribe((event) => __awaiter(this, void 0, void 0, function* () {
            if (__classPrivateFieldGet(this, _firstLoad) && event instanceof NavigationEnd) {
                __classPrivateFieldSet(this, _firstLoad, false);
                const route = __classPrivateFieldGet(this, _getActivatedRouteSnapshot).call(this, this.activatedRoute.snapshot);
                __classPrivateFieldSet(this, _rootRoute, this.router.routerState.root);
                yield __classPrivateFieldGet(this, _activeRoute).call(this, event.urlAfterRedirects || event.url, route);
                return;
            }
            if (!__classPrivateFieldGet(this, _firstLoad) && event instanceof RoutesRecognized) {
                const route = __classPrivateFieldGet(this, _getActivatedRouteSnapshot).call(this, event.state.root);
                __classPrivateFieldSet(this, _rootRoute, this.router.routerState.root);
                yield __classPrivateFieldGet(this, _activeRoute).call(this, event.urlAfterRedirects || event.url, route);
            }
        })));
        __classPrivateFieldGet(this, _subscription).add(tabRouterService.actions.subscribe((event) => {
            if (event && event.type === 'close') {
                __classPrivateFieldGet(this, _closeTab).call(this, event.tab);
            }
        }));
    }
    ngOnDestroy() {
        __classPrivateFieldGet(this, _subscription).unsubscribe();
    }
}
_rootRoute = new WeakMap(), _subscription = new WeakMap(), _firstLoad = new WeakMap(), _closeTab = new WeakMap(), _activeRoute = new WeakMap(), _getActivatedRouteSnapshot = new WeakMap(), _getActivatedRoute = new WeakMap();
SdTabRouterOutletComponent.decorators = [
    { type: Component, args: [{
                selector: 'sd-tab-router-outlet',
                template: "<sd-tab-router-nav [tabs]=\"tabs\" #tabRouterNav></sd-tab-router-nav>\r\n\r\n<div class=\"tab-router__list\">\r\n  <ng-container *ngFor=\"let tab of tabs;trackBy:tabTrackBy\">\r\n    <div class=\"tab-router__pane\" [class.active]=\"tab.isActive\" [id]=\"tab.key\">\r\n      <div class=\"tab-router__content\">\r\n        <ng-container\r\n          *ngComponentOutlet=\"tab.component; injector: tab.injector\"\r\n        ></ng-container>\r\n      </div>\r\n    </div>\r\n  </ng-container>\r\n</div>\r\n",
                styles: [":host{display:flex;flex-direction:column;height:calc(100vh - 64px);width:100%}:host ::ng-deep .sd-loading{max-height:100%;max-width:100%}::ng-deep page-layout{height:100%!important}.tab-router__list{flex:1}.tab-router__pane{display:none;height:100%;position:relative;width:100%}.tab-router__pane.active{display:block}.tab-router__content{bottom:0;height:100%;left:0;overflow:auto;position:absolute;right:0;top:0;width:100%}"]
            },] }
];
SdTabRouterOutletComponent.ctorParameters = () => [
    { type: Router },
    { type: ActivatedRoute },
    { type: ChangeDetectorRef },
    { type: Injector },
    { type: Compiler },
    { type: SdTabDecoratorService },
    { type: SdTabRouterService },
    { type: SdNotifyService }
];
SdTabRouterOutletComponent.propDecorators = {
    tabRouterNav: [{ type: ViewChild, args: ['tabRouterNav',] }]
};
class SdOutletInjector {
    constructor(route, 
    // private childContexts: ChildrenOutletContexts,
    parent) {
        this.route = route;
        this.parent = parent;
    }
    get(token, notFoundValue) {
        if (token === ActivatedRoute && this.route) {
            return this.route;
        }
        // if (token === ChildrenOutletContexts) {
        //   return this.childContexts;
        // }
        return this.parent.get(token, notFoundValue);
    }
}

class SdTabInfoPipe {
    constructor(tabRouterService) {
        this.tabRouterService = tabRouterService;
    }
    transform(tabInfo, tab) {
        if (tabInfo) {
            return of(tabInfo);
        }
        return this.tabRouterService.builders.pipe(map(builders => {
            const builder = builders.find(e => e.component === tab.component);
            if (builder) {
                const { url, params, queryParams, data } = tab;
                tab.tabInfo = {
                    name: typeof (builder.name) === 'function' ?
                        builder.name({ url, params, queryParams, data }) : builder.name,
                    initialName: typeof (builder.initialName) === 'function' ?
                        builder.initialName({ url, params, queryParams }) : builder.initialName,
                    tooltip: typeof (builder.tooltip) === 'function' ?
                        builder.tooltip({ url, params, queryParams }) : builder.tooltip,
                    color: typeof (builder.color) === 'function' ?
                        builder.color({ url, params, queryParams }) : builder.color
                };
                return tab.tabInfo;
            }
            tab.tabInfo = {
                name: tab.url,
                initialName: null,
            };
            return tab.tabInfo;
        }));
    }
}
SdTabInfoPipe.decorators = [
    { type: Pipe, args: [{
                name: 'sdTabInfo'
            },] }
];
SdTabInfoPipe.ctorParameters = () => [
    { type: SdTabRouterService }
];

class RouterLinkMouseDownDirective extends RouterLinkWithHref {
    onMouseDown(button, ctrlKey, shiftKey, altKey, metaKey) {
        return this.onClick(button, ctrlKey, shiftKey, altKey, metaKey);
    }
}
RouterLinkMouseDownDirective.decorators = [
    { type: Directive, args: [{
                selector: "a[routerLink],area[routerLink]",
            },] }
];
RouterLinkMouseDownDirective.propDecorators = {
    onMouseDown: [{ type: HostListener, args: ["mousedown", [
                    "$event.button",
                    "$event.ctrlKey",
                    "$event.shiftKey",
                    "$event.altKey",
                    "$event.metaKey",
                ],] }]
};

class SdTabRouterModule {
}
SdTabRouterModule.decorators = [
    { type: NgModule, args: [{
                declarations: [
                    SdTabRouterItemComponent,
                    SdTabRouterNavComponent,
                    SdTabRouterOutletComponent,
                    SdTabInfoPipe,
                    RouterLinkMouseDownDirective,
                ],
                imports: [
                    RouterModule,
                    CommonModule,
                    MatIconModule,
                    MatTooltipModule,
                    DragDropModule
                ],
                exports: [
                    SdTabRouterItemComponent,
                    SdTabRouterNavComponent,
                    SdTabRouterOutletComponent,
                ],
                providers: [],
            },] }
];

/*
 * Public API Surface of superdev-angular-core
 */

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

export { SdTabActivated, SdTabBase, SdTabComponent, SdTabDeactivated, SdTabDecoratorService, SdTabRouterItemComponent, SdTabRouterModule, SdTabRouterNavComponent, SdTabRouterOutletComponent, SdTabRouterService, SdTabInfoPipe as ɵa, RouterLinkMouseDownDirective as ɵb };
//# sourceMappingURL=sd-angular-core-tab-router.js.map
