import { Component, ViewEncapsulation, ChangeDetectionStrategy, Inject } from '@angular/core';
import { UxEuLanguages } from '@eui/base';
import { DYNAMIC_COMPONENT_CONFIG } from '../../../services/eui-dynamic-component.service';
import { EuiDialogService } from '../../../components/eui-dialog';
import * as i0 from "@angular/core";
import * as i1 from "../../../components/eui-dialog";
import * as i2 from "@angular/common";
import * as i3 from "../../../components/eui-button/eui-button.component";
function EuiModalSelectorComponent_h4_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "h4");
    i0.ɵɵtext(1, "EU official languages");
    i0.ɵɵelementEnd();
} }
function EuiModalSelectorComponent_div_1_div_1_Template(rf, ctx) { if (rf & 1) {
    const _r7 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 4);
    i0.ɵɵelementStart(1, "button", 5);
    i0.ɵɵlistener("click", function EuiModalSelectorComponent_div_1_div_1_Template_button_click_1_listener() { i0.ɵɵrestoreView(_r7); const language_r5 = ctx.$implicit; const ctx_r6 = i0.ɵɵnextContext(2); return ctx_r6.selectLanguage(language_r5); });
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const language_r5 = ctx.$implicit;
    const ctx_r4 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("euiSecondary", language_r5.code !== ctx_r4.config.selectedLanguage.code)("euiPrimary", language_r5.code === ctx_r4.config.selectedLanguage.code);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate2(" ", language_r5.label, " (", language_r5.code, ") ");
} }
function EuiModalSelectorComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 2);
    i0.ɵɵtemplate(1, EuiModalSelectorComponent_div_1_div_1_Template, 3, 4, "div", 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const row_r3 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", row_r3);
} }
function EuiModalSelectorComponent_ng_container_2_div_4_div_1_Template(rf, ctx) { if (rf & 1) {
    const _r13 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 4);
    i0.ɵɵelementStart(1, "button", 5);
    i0.ɵɵlistener("click", function EuiModalSelectorComponent_ng_container_2_div_4_div_1_Template_button_click_1_listener() { i0.ɵɵrestoreView(_r13); const language_r11 = ctx.$implicit; const ctx_r12 = i0.ɵɵnextContext(3); return ctx_r12.selectLanguage(language_r11); });
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const language_r11 = ctx.$implicit;
    const ctx_r10 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("euiSecondary", language_r11.code !== ctx_r10.config.selectedLanguage.code)("euiPrimary", language_r11.code === ctx_r10.config.selectedLanguage.code);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate2(" ", language_r11.label, " (", language_r11.code, ") ");
} }
function EuiModalSelectorComponent_ng_container_2_div_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 7);
    i0.ɵɵtemplate(1, EuiModalSelectorComponent_ng_container_2_div_4_div_1_Template, 3, 4, "div", 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const row_r9 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", row_r9);
} }
function EuiModalSelectorComponent_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelement(1, "br");
    i0.ɵɵelementStart(2, "h4");
    i0.ɵɵtext(3, "Non-EU Languages");
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(4, EuiModalSelectorComponent_ng_container_2_div_4_Template, 2, 1, "div", 6);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("ngForOf", ctx_r2.additionaLanguageRows);
} }
export class EuiModalSelectorComponent {
    constructor(euiDialogService, config) {
        this.euiDialogService = euiDialogService;
        this.config = config;
        this.languageRows = [];
        this.additionaLanguageRows = [];
    }
    ngOnInit() {
        this.languageRows = this.prepareLanguageRows(UxEuLanguages.filterEULanguages(this.config.languages));
        this.additionaLanguageRows = this.prepareLanguageRows(UxEuLanguages.filterNonEULanguages(this.config.languages));
    }
    selectLanguage(languageCode) {
        var _a;
        if (((_a = this.selectedLanguage) === null || _a === void 0 ? void 0 : _a.code) !== languageCode.code) {
            for (const language of this.config.languages) {
                if (language.code === languageCode.code) {
                    this.selectedLanguage = language;
                    break;
                }
            }
        }
        this.config.languageChanged(languageCode);
        this.euiDialogService.closeDialog(this.config.matDialogRef);
    }
    prepareLanguageRows(languages) {
        let rows = [];
        let row = [];
        for (let i = 0; i < languages.length; i++) {
            if (i % 4 === 0) {
                if (row.length > 0) {
                    rows.push(row);
                    row = [];
                }
            }
            row.push(languages[i]);
        }
        if (row.length > 0) {
            rows.push(row);
        }
        return rows;
    }
}
/** @nocollapse */ EuiModalSelectorComponent.ɵfac = function EuiModalSelectorComponent_Factory(t) { return new (t || EuiModalSelectorComponent)(i0.ɵɵdirectiveInject(i1.EuiDialogService), i0.ɵɵdirectiveInject(DYNAMIC_COMPONENT_CONFIG)); };
/** @nocollapse */ EuiModalSelectorComponent.ɵcmp = i0.ɵɵdefineComponent({ type: EuiModalSelectorComponent, selectors: [["eui-modal-selector"]], decls: 3, vars: 3, consts: [[4, "ngIf"], ["id", "eu_languages", "class", "row", 4, "ngFor", "ngForOf"], ["id", "eu_languages", 1, "row"], ["class", "col-md-6 mb-2", 4, "ngFor", "ngForOf"], [1, "col-md-6", "mb-2"], ["euiButton", "", "euiBlockButton", "", 3, "euiSecondary", "euiPrimary", "click"], ["id", "extra_languages", "class", "row", 4, "ngFor", "ngForOf"], ["id", "extra_languages", 1, "row"]], template: function EuiModalSelectorComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, EuiModalSelectorComponent_h4_0_Template, 2, 0, "h4", 0);
        i0.ɵɵtemplate(1, EuiModalSelectorComponent_div_1_Template, 2, 1, "div", 1);
        i0.ɵɵtemplate(2, EuiModalSelectorComponent_ng_container_2_Template, 5, 1, "ng-container", 0);
    } if (rf & 2) {
        i0.ɵɵproperty("ngIf", (ctx.additionaLanguageRows == null ? null : ctx.additionaLanguageRows.length) > 0);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngForOf", ctx.languageRows);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", (ctx.additionaLanguageRows == null ? null : ctx.additionaLanguageRows.length) > 0);
    } }, directives: [i2.NgIf, i2.NgForOf, i3.EuiButtonComponent], styles: [".eui-language-selector{align-items:center;cursor:pointer;display:inline-flex;position:relative}.eui-language-selector:not(.eui-app-toolbar__language-selector){margin-top:var(--eui-spacing-xs)}.eui-language-selector.eui-app-toolbar__language-selector{padding:var(--eui-spacing-m) var(--eui-spacing-m) var(--eui-spacing-m) 0}.eui-language-selector-link{align-items:center;display:flex;justify-content:center;position:relative;width:100%}.eui-language-selector-link__icon{color:var(--eui-color-primary);font-size:calc(var(--eui-font-size-4xl) + var(--eui-spacing-xs))}.eui-language-selector-link__language-code{align-items:center;color:var(--eui-color-white);display:flex;font-size:var(--eui-font-size-s);font-style:normal;font-weight:700;position:absolute;text-transform:uppercase;top:0;transform:translateY(35%)}.eui-language-selector:hover a.eui-language-selector-link{text-decoration:none}.eui-language-selector:active,.eui-language-selector:focus{border-color:var(--eui-color-accessible-focus)!important;box-shadow:inset 0 0 0 1px var(--eui-color-accessible-focus),inset 0 0 0 2px var(--eui-color-grey-lightester);outline:none;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}.eui-language-selector-menu-language-item{border-bottom:1px solid var(--eui-color-grey-lightest);cursor:pointer;padding:var(--eui-spacing-m);text-align:center}.eui-language-selector-menu-language-item:hover{background:var(--eui-color-grey-lightester)}.mat-menu-panel{min-width:4rem!important}.eui-language-selector--empty{display:none}.eui-language-selector--inverted .eui-language-selector-link__icon{color:#fff}.eui-language-selector--inverted .eui-language-selector-link__language-code{color:var(--eui-color-font)}"], encapsulation: 2 });
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(EuiModalSelectorComponent, [{
        type: Component,
        args: [{
                selector: 'eui-modal-selector',
                templateUrl: './modal-selector.component.html',
                styleUrls: ['../_styles/_index.scss'],
                changeDetection: ChangeDetectionStrategy.Default,
                encapsulation: ViewEncapsulation.None,
            }]
    }], function () { return [{ type: i1.EuiDialogService }, { type: undefined, decorators: [{
                type: Inject,
                args: [DYNAMIC_COMPONENT_CONFIG]
            }] }]; }, null); })();
//# sourceMappingURL=data:application/json;base64, 