import * as i0 from '@angular/core';
import { Injectable, Component, ViewChild, ViewContainerRef, NgModule, Inject } from '@angular/core';
import * as i1 from '@angular/router';
import { NavigationEnd, RouterModule } from '@angular/router';
import { filter } from 'rxjs/operators';
import { Subscription, BehaviorSubject, tap, switchMap, map, combineLatest, take } from 'rxjs';
import * as i5 from 'carbon-components-angular';
import { LoadingModule, ButtonModule, IconModule } from 'carbon-components-angular';
import * as i4 from '@angular/common';
import { CommonModule, DOCUMENT } from '@angular/common';
import * as i2 from '@valtimo/components';
import { MenuRoutingModule, TopbarModule, LeftSidebarModule, RightSidebarModule, PageHeaderModule, AlertModule, PromptModule, MultiInputFormModule, CarbonMultiInputModule, RenderInPageHeaderDirectiveModule, ConfirmationModalModule } from '@valtimo/components';
import { isEqual } from 'lodash';
import * as i1$1 from '@ngx-translate/core';
import { TranslateModule } from '@ngx-translate/core';
import * as i2$1 from '@valtimo/config';
import { ROLE_ADMIN } from '@valtimo/config';
import { AuthGuardService } from '@valtimo/security';

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class LayoutService {
    constructor() {
        this.fullscreen = false;
    }
    get isFullscreen() {
        return this.fullscreen;
    }
    toggleFullscreen() {
        this.fullscreen = !this.fullscreen;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class LayoutPublicComponent {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutPublicComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: LayoutPublicComponent, selector: "valtimo-layout-public", ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<div class=\"public-page-content\">\n  <img src=\"assets/logo.svg\" class=\"logo\" />\n  <router-outlet></router-outlet>\n</div>\n", styles: ["body{background-color:#eee}.public-page-content{background-color:#fff;margin:60px auto;border:1px solid #dee2e6;padding:0 30px 30px}.public-page-content .logo{width:25%;display:block;margin:30px auto}@media (min-width: 768px){.public-page-content{width:50%}}@media (max-width: 767px) and (min-width: 576px){.public-page-content{width:75%}}@media (max-width: 575px){.public-page-content{width:95%}.public-page-content .logo{width:50%}}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"], dependencies: [{ kind: "directive", type: i1.RouterOutlet, selector: "router-outlet", inputs: ["name"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutPublicComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-layout-public', template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<div class=\"public-page-content\">\n  <img src=\"assets/logo.svg\" class=\"logo\" />\n  <router-outlet></router-outlet>\n</div>\n", styles: ["body{background-color:#eee}.public-page-content{background-color:#fff;margin:60px auto;border:1px solid #dee2e6;padding:0 30px 30px}.public-page-content .logo{width:25%;display:block;margin:30px auto}@media (min-width: 768px){.public-page-content{width:50%}}@media (max-width: 767px) and (min-width: 576px){.public-page-content{width:75%}}@media (max-width: 575px){.public-page-content{width:95%}.public-page-content .logo{width:50%}}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"] }]
        }] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class LayoutInternalComponent {
    constructor(layoutService, renderer, userInterfaceService, shellService) {
        this.layoutService = layoutService;
        this.renderer = renderer;
        this.userInterfaceService = userInterfaceService;
        this.shellService = shellService;
        this.showPageHeader$ = this.userInterfaceService.showPageHeader$;
        this.sideBarExpanded$ = this.shellService.sideBarExpanded$;
        this.collapsibleWidescreenMenu$ = this.shellService.collapsibleWidescreenMenu$;
        this.renderer.addClass(document.body, 'be-animate');
    }
    ngAfterViewInit() {
        App.init();
        this.shellService.setContentElement(this.mainContentRef.nativeElement);
        this._observer = new ResizeObserver(() => {
            this.shellService.onMainContentResize();
        });
        this._observer.observe(this.mainContentRef.nativeElement);
    }
    ngOnDestroy() {
        this._observer.disconnect();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutInternalComponent, deps: [{ token: LayoutService }, { token: i0.Renderer2 }, { token: i2.UserInterfaceService }, { token: i2.ShellService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: LayoutInternalComponent, selector: "valtimo-layout-internal", viewQueries: [{ propertyName: "mainContentRef", first: true, predicate: ["mainContent"], descendants: true }], ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<valtimo-topbar></valtimo-topbar>\n<main\n  class=\"cds--content\"\n  [ngClass]=\"{\n    'cds--content--sidebar':\n      (sideBarExpanded$ | async) && (collapsibleWidescreenMenu$ | async) === false,\n  }\"\n  #mainContent\n>\n  <valtimo-left-sidebar [hidden]=\"layoutService.isFullscreen\"></valtimo-left-sidebar>\n  <valtimo-alert></valtimo-alert>\n  <valtimo-page-header [hidden]=\"layoutService.isFullscreen\"></valtimo-page-header>\n  <router-outlet></router-outlet>\n  <valtimo-right-sidebar></valtimo-right-sidebar>\n  <v-prompt></v-prompt>\n</main>\n", styles: ["::ng-deep .cds--content{padding-top:24px!important}@media screen and (max-width: 767px){.be-content{margin-left:0!important}}@media only screen and (min-width: 1056px){.cds--content--sidebar{padding-left:18rem}}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"], dependencies: [{ kind: "directive", type: i1.RouterOutlet, selector: "router-outlet", inputs: ["name"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }, { kind: "component", type: i2.TopbarComponent, selector: "valtimo-topbar" }, { kind: "component", type: i2.LeftSidebarComponent, selector: "valtimo-left-sidebar" }, { kind: "component", type: i2.RightSidebarComponent, selector: "valtimo-right-sidebar" }, { kind: "component", type: i2.PageHeaderComponent, selector: "valtimo-page-header" }, { kind: "component", type: i2.AlertComponent, selector: "valtimo-alert" }, { kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: i2.PromptComponent, selector: "v-prompt", inputs: ["appearingDelayMs", "maxWidthPx"], outputs: ["closeEvent"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutInternalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-layout-internal', template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<valtimo-topbar></valtimo-topbar>\n<main\n  class=\"cds--content\"\n  [ngClass]=\"{\n    'cds--content--sidebar':\n      (sideBarExpanded$ | async) && (collapsibleWidescreenMenu$ | async) === false,\n  }\"\n  #mainContent\n>\n  <valtimo-left-sidebar [hidden]=\"layoutService.isFullscreen\"></valtimo-left-sidebar>\n  <valtimo-alert></valtimo-alert>\n  <valtimo-page-header [hidden]=\"layoutService.isFullscreen\"></valtimo-page-header>\n  <router-outlet></router-outlet>\n  <valtimo-right-sidebar></valtimo-right-sidebar>\n  <v-prompt></v-prompt>\n</main>\n", styles: ["::ng-deep .cds--content{padding-top:24px!important}@media screen and (max-width: 767px){.be-content{margin-left:0!important}}@media only screen and (min-width: 1056px){.cds--content--sidebar{padding-left:18rem}}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"] }]
        }], ctorParameters: () => [{ type: LayoutService }, { type: i0.Renderer2 }, { type: i2.UserInterfaceService }, { type: i2.ShellService }], propDecorators: { mainContentRef: [{
                type: ViewChild,
                args: ['mainContent']
            }] } });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class LayoutComponent {
    constructor(router, route, placeHolderService) {
        this.router = router;
        this.route = route;
        this.placeHolderService = placeHolderService;
        this.layoutType = null;
        this._routerSub = new Subscription();
        this._DEFAULT_LAYOUT = 'internal';
    }
    ngOnInit() {
        this.openRouterSubscription();
    }
    ngAfterViewInit() {
        this.registerCarbonPlaceHolder();
    }
    ngOnDestroy() {
        this._routerSub.unsubscribe();
    }
    registerCarbonPlaceHolder() {
        if (this._carbonPlaceHolder) {
            this.placeHolderService.registerViewContainerRef(this._carbonPlaceHolder);
        }
    }
    openRouterSubscription() {
        this._routerSub.add(this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => {
            const layout = this.route.snapshot.firstChild.data.layout;
            this.layoutType = layout ? layout : this._DEFAULT_LAYOUT;
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutComponent, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }, { token: i5.PlaceholderService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: LayoutComponent, selector: "valtimo-layout", viewQueries: [{ propertyName: "_carbonPlaceHolder", first: true, predicate: ["carbonPlaceHolder"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<div #carbonPlaceHolder class=\"carbon-placeholder\"></div>\n\n<valtimo-layout-public *ngIf=\"layoutType === 'public'\"></valtimo-layout-public>\n<valtimo-layout-internal *ngIf=\"layoutType === 'internal'\"></valtimo-layout-internal>\n", dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: LayoutPublicComponent, selector: "valtimo-layout-public" }, { kind: "component", type: LayoutInternalComponent, selector: "valtimo-layout-internal" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-layout', template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<div #carbonPlaceHolder class=\"carbon-placeholder\"></div>\n\n<valtimo-layout-public *ngIf=\"layoutType === 'public'\"></valtimo-layout-public>\n<valtimo-layout-internal *ngIf=\"layoutType === 'internal'\"></valtimo-layout-internal>\n" }]
        }], ctorParameters: () => [{ type: i1.Router }, { type: i1.ActivatedRoute }, { type: i5.PlaceholderService }], propDecorators: { _carbonPlaceHolder: [{
                type: ViewChild,
                args: ['carbonPlaceHolder', { static: true, read: ViewContainerRef }]
            }] } });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class LayoutModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: LayoutModule, declarations: [LayoutComponent, LayoutPublicComponent, LayoutInternalComponent], imports: [RouterModule,
            MenuRoutingModule,
            TopbarModule,
            LeftSidebarModule,
            RightSidebarModule,
            PageHeaderModule,
            AlertModule,
            CommonModule,
            PromptModule], exports: [LayoutComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutModule, imports: [RouterModule,
            MenuRoutingModule,
            TopbarModule,
            LeftSidebarModule,
            RightSidebarModule,
            PageHeaderModule,
            AlertModule,
            CommonModule,
            PromptModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: LayoutModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [LayoutComponent, LayoutPublicComponent, LayoutInternalComponent],
                    imports: [
                        RouterModule,
                        MenuRoutingModule,
                        TopbarModule,
                        LeftSidebarModule,
                        RightSidebarModule,
                        PageHeaderModule,
                        AlertModule,
                        CommonModule,
                        PromptModule,
                    ],
                    exports: [LayoutComponent],
                }]
        }] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class TranslationManagementComponent {
    constructor(translateService, localizationService, pageHeaderService, document) {
        this.translateService = translateService;
        this.localizationService = localizationService;
        this.pageHeaderService = pageHeaderService;
        this.document = document;
        this.loading$ = new BehaviorSubject(true);
        this.allChangedValuesValid$ = new BehaviorSubject(false);
        this.disabled$ = new BehaviorSubject(false);
        this._languageOptions$ = new BehaviorSubject(undefined);
        this._refreshLocalizations$ = new BehaviorSubject(null);
        this._localizationTranslations$ = this._refreshLocalizations$.pipe(tap(() => this.loading$.next(true)), switchMap(() => this.localizationService.getMergedLocalizations()), tap(() => this.loading$.next(false)));
        this._defaultValues = [];
        this._changedValues$ = new BehaviorSubject(undefined);
        this.showConfirmationModal$ = new BehaviorSubject(false);
        this.valuesChanged$ = this._changedValues$.pipe(map(changedValues => !isEqual(changedValues, this._defaultValues)));
        this.localizationTranslationValues$ = combineLatest([
            this._languageOptions$,
            this._localizationTranslations$,
            this.translateService.stream('key'),
        ]).pipe(map(([languageOptions, localizationTranslations]) => this.mapMergedLocalizationsToMultiInput(languageOptions, localizationTranslations)), tap(defaultValues => {
            this._defaultValues = defaultValues;
        }));
        this.multiInputTiles$ = combineLatest([
            this._languageOptions$,
            this.translateService.stream('key'),
        ]).pipe(map(([languageOptions]) => {
            const objToReturn = {};
            objToReturn[0] = this.translateService.instant('listColumn.key');
            languageOptions.forEach((languageOption, index) => {
                objToReturn[index + 1] = this.translateService.instant(`settings.language.options.${languageOption}`);
            });
            return objToReturn;
        }));
        this.amountOfArbitraryValues$ = this.multiInputTiles$.pipe(map(multiInputTitles => Object.keys(multiInputTitles).length));
        this.compactMode$ = this.pageHeaderService.compactMode$;
    }
    ngOnInit() {
        this.setLanguages();
    }
    validChange(valid) {
        this.allChangedValuesValid$.next(valid);
    }
    valueChange(value) {
        this._changedValues$.next(value);
    }
    saveAndRefresh() {
        this.saveChanges(true);
    }
    saveAndStay() {
        this.saveChanges();
    }
    cancel() {
        this.hideModal();
    }
    showModal() {
        this.showConfirmationModal$.next(true);
    }
    saveChanges(reload = false) {
        this.disable();
        combineLatest([this._changedValues$, this._languageOptions$])
            .pipe(take(1), map(([changedValues, languageOptions]) => this.getLocalizationsForUpdateRequest(changedValues, languageOptions)), switchMap(updatedLocalizations => this.localizationService.updateLocalizations(updatedLocalizations)))
            .subscribe(() => {
            if (reload) {
                this.document?.defaultView?.location?.reload();
            }
            else {
                this._refreshLocalizations$.next(null);
                this.enable();
            }
        });
    }
    setLanguages() {
        this._languageOptions$.next(this.translateService.langs);
    }
    disable() {
        this.disabled$.next(true);
    }
    enable() {
        this.disabled$.next(false);
    }
    hideModal() {
        this.showConfirmationModal$.next(false);
    }
    flattenObject(ob) {
        const toReturn = {};
        for (const i in ob) {
            if (!ob.hasOwnProperty(i))
                continue;
            if (typeof ob[i] == 'object' && ob[i] !== null) {
                const flatObject = this.flattenObject(ob[i]);
                for (const x in flatObject) {
                    if (!flatObject.hasOwnProperty(x))
                        continue;
                    toReturn[i + '.' + x] = flatObject[x];
                }
            }
            else {
                toReturn[i] = ob[i];
            }
        }
        return toReturn;
    }
    unflattenObject(obj, delimiter = '.') {
        return Object.keys(obj).reduce((res, k) => {
            k.split(delimiter).reduce((acc, e, i, keys) => acc[e] ||
                (acc[e] = isNaN(Number(keys[i + 1])) ? (keys.length - 1 === i ? obj[k] : {}) : []), res);
            return res;
        }, {});
    }
    getLocalizationsForUpdateRequest(changedValues, languageOptions) {
        const localizations = [];
        const translationObject = {};
        languageOptions.forEach(languageOption => {
            translationObject[languageOption] = {};
        });
        changedValues.forEach(changedValue => {
            languageOptions.forEach((languageOption, index) => {
                translationObject[languageOption] = {
                    ...translationObject[languageOption],
                    [changedValue[0]]: changedValue[index + 1],
                };
            });
        });
        languageOptions.forEach(languageOption => {
            translationObject[languageOption] = this.unflattenObject(translationObject[languageOption]);
        });
        Object.keys(translationObject).forEach(languageKey => {
            localizations.push({ languageKey, content: translationObject[languageKey] });
        });
        return localizations;
    }
    mapMergedLocalizationsToMultiInput(languageOptions, mergedLocalizations) {
        if (Object.keys(mergedLocalizations).length === 0) {
            return [];
        }
        const firstLanguageOption = languageOptions[0];
        const firstLanguageTranslations = firstLanguageOption && mergedLocalizations[firstLanguageOption];
        const flattenedFirstLanguageTranslations = firstLanguageTranslations && this.flattenObject(firstLanguageTranslations);
        return Object.keys(flattenedFirstLanguageTranslations).map(flattenedTranslationKey => {
            const emptyArbitraryValue = {};
            emptyArbitraryValue['0'] = flattenedTranslationKey;
            languageOptions.forEach((languageOption, index) => {
                emptyArbitraryValue[`${index + 1}`] =
                    this.flattenObject(mergedLocalizations[languageOption])[flattenedTranslationKey] || '';
            });
            return emptyArbitraryValue;
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementComponent, deps: [{ token: i1$1.TranslateService }, { token: i2$1.LocalizationService }, { token: i2.PageHeaderService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: TranslationManagementComponent, selector: "valtimo-translation-management", ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<ng-container\n  *ngIf=\"{\n    localizationTranslationValues: localizationTranslationValues$ | async,\n    loading: loading$ | async,\n    disabled: disabled$ | async,\n    multiInputTitles: multiInputTiles$ | async,\n    amountOfArbitraryValues: amountOfArbitraryValues$ | async,\n    showConfirmationModal: showConfirmationModal$,\n    allChangedValuesValid: allChangedValuesValid$ | async,\n    valuesChanged: valuesChanged$ | async,\n    compactMode: compactMode$ | async,\n  } as obs\"\n>\n  <ng-container *ngIf=\"!obs.loading && obs.localizationTranslationValues; else loading\">\n    <valtimo-carbon-multi-input\n      [disabled]=\"obs.disabled\"\n      [arbitraryAmountTitles]=\"obs.multiInputTitles\"\n      [fullWidth]=\"true\"\n      [minimumAmountOfRows]=\"0\"\n      type=\"arbitraryAmount\"\n      [arbitraryValueAmount]=\"obs.amountOfArbitraryValues\"\n      [defaultValues]=\"obs.localizationTranslationValues\"\n      (allValuesValidEvent)=\"validChange($event)\"\n      (valueChange)=\"valueChange($event)\"\n      addRowTranslationKey=\"translationManagement.add\"\n    ></valtimo-carbon-multi-input>\n  </ng-container>\n\n  <ng-template #loading>\n    <div class=\"loading-container\"><cds-loading></cds-loading></div>\n  </ng-template>\n\n  <valtimo-confirmation-modal\n    [showModalSubject$]=\"obs.showConfirmationModal\"\n    (confirmEvent)=\"saveAndRefresh()\"\n    (optionalEvent)=\"saveAndStay()\"\n    (cancelEvent)=\"cancel()\"\n    [showOptionalButton]=\"true\"\n    cancelButtonType=\"ghost\"\n    optionalButtonType=\"secondary\"\n    confirmButtonTextTranslationKey=\"translationManagement.saveWithReload\"\n    optionalButtonTextTranslationKey=\"translationManagement.saveWithoutReload\"\n    titleTranslationKey=\"translationManagement.modalTitle\"\n    contentTranslationKey=\"translationManagement.modalContent\"\n    [spacerAfterCancelButton]=\"true\"\n  ></valtimo-confirmation-modal>\n\n  <ng-container renderInPageHeader>\n    <ng-template>\n      <button\n        cdsButton=\"primary\"\n        [size]=\"obs.compactMode ? 'sm' : 'md'\"\n        (click)=\"showModal()\"\n        [disabled]=\"!obs.allChangedValuesValid || obs.disabled || !obs.valuesChanged\"\n      >\n        {{ 'interface.save' | translate }}\n\n        <svg class=\"cds--btn__icon\" cdsIcon=\"save\" size=\"16\"></svg>\n      </button>\n    </ng-template>\n  </ng-container>\n</ng-container>\n", styles: [".loading-container{display:flex;width:100%;justify-content:center}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"], dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.CarbonMultiInputComponent, selector: "valtimo-carbon-multi-input", inputs: ["addRowText", "addRowTranslationKey", "arbitraryAmountTitles", "arbitraryValueAmount", "defaultValues", "deleteRowText", "deleteRowTranslationKey", "disabled", "dropdownColumnTitle", "dropdownItems", "dropdownWidth", "fullWidth", "hideAddButton", "hideDeleteButton", "initialAmountOfRows", "keyColumnTitle", "margin", "maxRows", "minimumAmountOfRows", "name", "required", "title", "titleTranslationKey", "tooltip", "type", "valueColumnTitle", "valuePathSelectorDocumentDefinitionName", "valuePathSelectorPrefixes", "valuePathSelectorShowDocumentDefinitionSelector", "valuePathSelectorNotation", "keyColumnFlex", "dropdownColumnFlex", "valueColumnFlex"], outputs: ["valueChange", "allValuesValidEvent"] }, { kind: "component", type: i5.Loading, selector: "cds-loading, ibm-loading", inputs: ["title", "isActive", "size", "overlay"] }, { kind: "directive", type: i2.RenderInPageHeaderDirective, selector: "[renderInPageHeader]", inputs: ["fullWidth"] }, { kind: "directive", type: i5.Button, selector: "[cdsButton], [ibmButton]", inputs: ["ibmButton", "cdsButton", "size", "skeleton", "iconOnly", "isExpressive"] }, { kind: "directive", type: i5.IconDirective, selector: "[cdsIcon], [ibmIcon]", inputs: ["ibmIcon", "cdsIcon", "size", "title", "ariaLabel", "ariaLabelledBy", "ariaHidden", "isFocusable"] }, { kind: "component", type: i2.ConfirmationModalComponent, selector: "valtimo-confirmation-modal", inputs: ["titleTranslationKey", "title", "content", "contentTranslationKey", "confirmButtonText", "confirmButtonTextTranslationKey", "confirmButtonType", "showOptionalButton", "optionalButtonText", "optionalButtonTextTranslationKey", "optionalButtonType", "cancelButtonText", "cancelButtonTextTranslationKey", "cancelButtonType", "showModalSubject$", "outputOnConfirm", "outputOnOptional", "spacerAfterCancelButton"], outputs: ["confirmEvent", "optionalEvent", "cancelEvent"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: i1$1.TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-translation-management', template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<ng-container\n  *ngIf=\"{\n    localizationTranslationValues: localizationTranslationValues$ | async,\n    loading: loading$ | async,\n    disabled: disabled$ | async,\n    multiInputTitles: multiInputTiles$ | async,\n    amountOfArbitraryValues: amountOfArbitraryValues$ | async,\n    showConfirmationModal: showConfirmationModal$,\n    allChangedValuesValid: allChangedValuesValid$ | async,\n    valuesChanged: valuesChanged$ | async,\n    compactMode: compactMode$ | async,\n  } as obs\"\n>\n  <ng-container *ngIf=\"!obs.loading && obs.localizationTranslationValues; else loading\">\n    <valtimo-carbon-multi-input\n      [disabled]=\"obs.disabled\"\n      [arbitraryAmountTitles]=\"obs.multiInputTitles\"\n      [fullWidth]=\"true\"\n      [minimumAmountOfRows]=\"0\"\n      type=\"arbitraryAmount\"\n      [arbitraryValueAmount]=\"obs.amountOfArbitraryValues\"\n      [defaultValues]=\"obs.localizationTranslationValues\"\n      (allValuesValidEvent)=\"validChange($event)\"\n      (valueChange)=\"valueChange($event)\"\n      addRowTranslationKey=\"translationManagement.add\"\n    ></valtimo-carbon-multi-input>\n  </ng-container>\n\n  <ng-template #loading>\n    <div class=\"loading-container\"><cds-loading></cds-loading></div>\n  </ng-template>\n\n  <valtimo-confirmation-modal\n    [showModalSubject$]=\"obs.showConfirmationModal\"\n    (confirmEvent)=\"saveAndRefresh()\"\n    (optionalEvent)=\"saveAndStay()\"\n    (cancelEvent)=\"cancel()\"\n    [showOptionalButton]=\"true\"\n    cancelButtonType=\"ghost\"\n    optionalButtonType=\"secondary\"\n    confirmButtonTextTranslationKey=\"translationManagement.saveWithReload\"\n    optionalButtonTextTranslationKey=\"translationManagement.saveWithoutReload\"\n    titleTranslationKey=\"translationManagement.modalTitle\"\n    contentTranslationKey=\"translationManagement.modalContent\"\n    [spacerAfterCancelButton]=\"true\"\n  ></valtimo-confirmation-modal>\n\n  <ng-container renderInPageHeader>\n    <ng-template>\n      <button\n        cdsButton=\"primary\"\n        [size]=\"obs.compactMode ? 'sm' : 'md'\"\n        (click)=\"showModal()\"\n        [disabled]=\"!obs.allChangedValuesValid || obs.disabled || !obs.valuesChanged\"\n      >\n        {{ 'interface.save' | translate }}\n\n        <svg class=\"cds--btn__icon\" cdsIcon=\"save\" size=\"16\"></svg>\n      </button>\n    </ng-template>\n  </ng-container>\n</ng-container>\n", styles: [".loading-container{display:flex;width:100%;justify-content:center}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"] }]
        }], ctorParameters: () => [{ type: i1$1.TranslateService }, { type: i2$1.LocalizationService }, { type: i2.PageHeaderService }, { type: Document, decorators: [{
                    type: Inject,
                    args: [DOCUMENT]
                }] }] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const routes = [
    {
        path: 'translation-management',
        component: TranslationManagementComponent,
        canActivate: [AuthGuardService],
        data: { title: 'Translations', roles: [ROLE_ADMIN] },
    },
];
class TranslationManagementRoutingModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementRoutingModule, imports: [i1.RouterModule], exports: [RouterModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementRoutingModule, imports: [RouterModule.forChild(routes), RouterModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementRoutingModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [RouterModule.forChild(routes)],
                    exports: [RouterModule],
                }]
        }] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class TranslationManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementModule, declarations: [TranslationManagementComponent], imports: [CommonModule,
            TranslateModule,
            TranslationManagementRoutingModule,
            MultiInputFormModule,
            CarbonMultiInputModule,
            LoadingModule,
            RenderInPageHeaderDirectiveModule,
            ButtonModule,
            IconModule,
            ConfirmationModalModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementModule, imports: [CommonModule,
            TranslateModule,
            TranslationManagementRoutingModule,
            MultiInputFormModule,
            CarbonMultiInputModule,
            LoadingModule,
            RenderInPageHeaderDirectiveModule,
            ButtonModule,
            IconModule,
            ConfirmationModalModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TranslationManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [TranslationManagementComponent],
                    imports: [
                        CommonModule,
                        TranslateModule,
                        TranslationManagementRoutingModule,
                        MultiInputFormModule,
                        CarbonMultiInputModule,
                        LoadingModule,
                        RenderInPageHeaderDirectiveModule,
                        ButtonModule,
                        IconModule,
                        ConfirmationModalModule,
                    ],
                    exports: [],
                }]
        }] });

/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * Public API Surface of layout
 */

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

export { LayoutComponent, LayoutModule, LayoutService, TranslationManagementModule };
//# sourceMappingURL=valtimo-layout.mjs.map
