import { Component, Input } from '@angular/core';
import { HtmlHelper } from '@tilde-nlp/ngx-common';
import * as i0 from "@angular/core";
import * as i1 from "./services/translation-system-picker.service";
import * as i2 from "../../tld-common/services";
import * as i3 from "../../tld-document/services";
import * as i4 from "../../tld-text/services";
import * as i5 from "@angular/common";
import * as i6 from "@ngbracket/ngx-layout/flex";
import * as i7 from "@ngbracket/ngx-layout/extended";
import * as i8 from "@tilde-nlp/ngx-common";
import * as i9 from "@angular/material/tooltip";
import * as i10 from "@angular/material/button";
import * as i11 from "@ngx-translate/core";
export class TranslationSystemPickerComponent {
    systemPickerService;
    tldSystem;
    file;
    text;
    config;
    isCollectionsActivated;
    get isSourceOpened() { return this.systemPickerService.isSourceOpened; }
    get isTargetOpened() { return this.systemPickerService.isTargetOpened; }
    get canSwap() {
        return this.tldSystem.canSwapLanguages && !this.isFileTranslating;
    }
    get sourceLanguage() {
        return this.activeData?.sourceLang;
    }
    get targetLanguage() {
        return this.activeData?.targetLang;
    }
    get isDataLoaded() {
        return this.activeData;
    }
    get collectionsVisible() {
        return this.isCollectionsActivated && this.isTerminologySupported && this.config.coreConfig.isAuth;
    }
    get isFileTranslating() {
        return this.file.translationStarted;
    }
    get translatedText() {
        return this.text.translatedText;
    }
    get isTranslating() {
        return this.text.isTranslating;
    }
    get isFileView() {
        return this.file.fileNames.length > 0;
    }
    sourceAriaLabel = "SYSTEM_PICKER.OPEN_SOURCE_ARIA_LABEL";
    targetAriaLabel = "SYSTEM_PICKER.OPEN_TARGET_ARIA_LABEL";
    domainLength = 0;
    activeDomainKey;
    activeDomainLocalizationKey;
    isTargetReselected = false;
    isTerminologySupported;
    subscription;
    activeData;
    system;
    constructor(systemPickerService, tldSystem, file, text, config) {
        this.systemPickerService = systemPickerService;
        this.tldSystem = tldSystem;
        this.file = file;
        this.text = text;
        this.config = config;
    }
    ngOnInit() {
        this.subscribeToActiveData();
    }
    sourceClick(event) {
        if (this.isFileTranslating) {
            return;
        }
        // stop propagation necessary so that click outside directive works as intended otherwise click event goes up through parents and click outside gets called and closes dropdown.
        event.stopPropagation();
        this.systemPickerService.sourceLanguageClicked();
    }
    targetClick(event) {
        if (this.isFileTranslating) {
            return;
        }
        this.isTargetReselected = false;
        // stop propagation necessary so that click outside directive works as intended otherwise click event goes up through parents and click outside gets called and closes dropdown.
        event.stopPropagation();
        this.systemPickerService.targetLanguageClicked();
    }
    swap() {
        if (this.isFileTranslating) {
            return;
        }
        this.tldSystem.swapSystemLanguages();
    }
    ngOnDestroy() {
        this.subscription.unsubscribe();
    }
    subscribeToActiveData() {
        let lastTargetLanguage;
        this.subscription = this.tldSystem.getActiveData().subscribe((activeData) => {
            if (!activeData) {
                return;
            }
            if (activeData.targetLang.lang !== lastTargetLanguage) {
                if (lastTargetLanguage) {
                    this.isTargetReselected = true;
                }
                lastTargetLanguage = activeData.targetLang.lang;
            }
            this.system = { systemId: activeData.systemId, sourceLanguageCode: activeData?.system?.detectedLanguage ?? activeData.sourceLang.lang, targetLanguageCode: activeData.targetLang.lang, detectedLanguage: activeData.system.detectedLanguage };
            this.activeData = activeData;
            this.activeDomainKey = this.activeData.domains?.active?.title;
            this.activeDomainLocalizationKey = HtmlHelper.getLocalizationKey(this.activeDomainKey);
            this.domainLength = this.activeData.domains?.domains?.length ?? 0;
            this.isTerminologySupported = this.tldSystem.isTerminologySupported(this.activeData.system);
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TranslationSystemPickerComponent, deps: [{ token: i1.TranslationSystemPickerService }, { token: i2.TldTranslateSystemManagementService }, { token: i3.TldTranslateFileService }, { token: i4.TldTranslateTextService }, { token: i2.TldTranslateConfigService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: TranslationSystemPickerComponent, selector: "tld-translation-system-picker", inputs: { isCollectionsActivated: "isCollectionsActivated" }, ngImport: i0, template: "<div fxFlex fxLayout=\"row\">\r\n  <ng-container *ngIf=\"isDataLoaded\">\r\n    <div fxFlex fxLayoutAlign=\"space-between center\" fxLayoutAlign.lt-sm=\"space-evenly center\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"languageDropdownTrigger; context: { language: sourceLanguage, localizationKey: 'SYSTEM_PICKER.SOURCE', isOpened: isSourceOpened, isSource: true, ariaLabelCode: sourceAriaLabel }\">\r\n      </ng-container>\r\n      <button [disabled]=\"!canSwap\" class=\"swap-languages-button\" mat-icon-button (click)=\"swap()\"\r\n        aria-label=\"swap languages\" color=\"primary\" matTooltip=\"{{'TOOLTIPS.SWAP_LANGUAGES' | translate}}\">\r\n        <span class=\"material-icons\" aria-hidden=\"false\"\r\n          [attr.aria-label]=\"'ARIA_LABELS.SWAP_LANGUAGES' | translate\">swap_horiz</span>\r\n      </button>\r\n    </div>\r\n    <div fxFlex fxLayoutAlign=\"space-between center\"  fxLayoutAlign.lt-sm=\"space-evenly center\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"languageDropdownTrigger; context: { language: targetLanguage, localizationKey: 'SYSTEM_PICKER.TARGET', isOpened: isTargetOpened, isSource: false,  ariaLabelCode: targetAriaLabel}\">\r\n      </ng-container>\r\n\r\n      <div fxFlex fxLayoutAlign=\"end center\">\r\n        <div *ngIf=\"collectionsVisible\" #collectionWrapper class=\"terminology-wrapper\">\r\n          <lib-terminology [system]=\"system\"></lib-terminology>\r\n        </div>\r\n      </div>\r\n    </div>\r\n  </ng-container>\r\n</div>\r\n\r\n<ng-template #languageName let-language=\"language\" let-showDomain=\"showDomain\" let-detectedLanguage=\"detectedLanguage\">\r\n  <span>{{ (detectedLanguage && !showDomain ? detectedLanguage : language.lang) | languageTranslate }}</span>\r\n  <span fxHide.lt-md *ngIf=\"detectedLanguage && !showDomain\"> - {{'SYSTEM_PICKER.DETECTED' | translate}}</span>\r\n  <ng-container *ngIf=\"showDomain && domainLength>1\">\r\n    <span class=\"domain\">({{('DOMAINS.'+(activeDomainLocalizationKey | uppercase)) | translate: {default: activeDomainKey | titlecase} }})</span>\r\n  </ng-container>\r\n</ng-template>\r\n\r\n<ng-template #openedDropdown let-localizationKey=\"localizationKey\">\r\n  {{localizationKey | translate}}\r\n</ng-template>\r\n\r\n<!--Template for language dropdown trigger. Same as for target and source with different params-->\r\n<ng-template #languageDropdownTrigger let-language=\"language\" let-isOpened=\"isOpened\" let-placeholder=\"localizationKey\"\r\n  let-isSource=\"isSource\" let-ariaLabelCode=\"ariaLabelCode\">\r\n  <lib-open-close-button [disabled]=\"isFileTranslating\" class=\"system-picker-button\" [ngClass]=\"isSource? 'source': 'target'\"\r\n    [ngClass.lt-sm]=\"'system-picker-button-mobile'\" (click)=\"isSource ? sourceClick($event) : targetClick($event)\"\r\n    [disableFocusOnAction]=\"true\" [isOpened]=\"isOpened\" [class.opened]=\"isOpened\" [ariaLabelCode]=\"ariaLabelCode\">\r\n    <span [ngClass.lt-sm]=\"'mobile-domain-container'\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"isOpened && isSource || isOpened && !isSource && !isTargetReselected ? openedDropdown : languageName; context: { language: language, localizationKey: placeholder, showDomain: !isSource, detectedLanguage: system.detectedLanguage }\">\r\n      </ng-container>\r\n    </span>\r\n  </lib-open-close-button>\r\n</ng-template>\r\n", styles: [":host{display:flex}.swap-languages-button{color:var(--base-30)!important}.source{margin-left:.3em}.system-picker-button.system-picker-button-mobile{margin-left:.2em}.target{margin-left:8px}:host ::ng-deep .open-close-button-content{color:var(--base-30)}.mobile-domain-container{display:flex}.mobile-domain-container .domain{display:none}.domain{display:inline-block;max-width:250px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:bottom}.terminology-wrapper{margin-right:.3rem}:host ::ng-deep .system-picker-button-mobile{display:flex;align-items:center;max-height:46px;height:100%;max-width:120px;width:100%;background-color:var(--base-95)!important;border-radius:8px}:host ::ng-deep .system-picker-button-mobile span{font-size:12px;text-align:center;line-height:16px}:host ::ng-deep .system-picker-button-mobile .material-icons{display:none!important}:host ::ng-deep .opened .open-close-button-content,.opened button{color:var(--accent)!important}:host ::ng-deep .open-close-button-content{white-space:nowrap;overflow:hidden}:host ::ng-deep .system-picker-button-mobile span{white-space:wrap;overflow:hidden;text-align:center;max-height:46px}\n"], dependencies: [{ kind: "directive", type: i5.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i6.DefaultLayoutDirective, selector: "  [fxLayout], [fxLayout.xs], [fxLayout.sm], [fxLayout.md],  [fxLayout.lg], [fxLayout.xl], [fxLayout.lt-sm], [fxLayout.lt-md],  [fxLayout.lt-lg], [fxLayout.lt-xl], [fxLayout.gt-xs], [fxLayout.gt-sm],  [fxLayout.gt-md], [fxLayout.gt-lg]", inputs: ["fxLayout", "fxLayout.xs", "fxLayout.sm", "fxLayout.md", "fxLayout.lg", "fxLayout.xl", "fxLayout.lt-sm", "fxLayout.lt-md", "fxLayout.lt-lg", "fxLayout.lt-xl", "fxLayout.gt-xs", "fxLayout.gt-sm", "fxLayout.gt-md", "fxLayout.gt-lg"] }, { kind: "directive", type: i6.DefaultLayoutAlignDirective, selector: "  [fxLayoutAlign], [fxLayoutAlign.xs], [fxLayoutAlign.sm], [fxLayoutAlign.md],  [fxLayoutAlign.lg], [fxLayoutAlign.xl], [fxLayoutAlign.lt-sm], [fxLayoutAlign.lt-md],  [fxLayoutAlign.lt-lg], [fxLayoutAlign.lt-xl], [fxLayoutAlign.gt-xs], [fxLayoutAlign.gt-sm],  [fxLayoutAlign.gt-md], [fxLayoutAlign.gt-lg]", inputs: ["fxLayoutAlign", "fxLayoutAlign.xs", "fxLayoutAlign.sm", "fxLayoutAlign.md", "fxLayoutAlign.lg", "fxLayoutAlign.xl", "fxLayoutAlign.lt-sm", "fxLayoutAlign.lt-md", "fxLayoutAlign.lt-lg", "fxLayoutAlign.lt-xl", "fxLayoutAlign.gt-xs", "fxLayoutAlign.gt-sm", "fxLayoutAlign.gt-md", "fxLayoutAlign.gt-lg"] }, { kind: "directive", type: i6.DefaultFlexDirective, selector: "  [fxFlex], [fxFlex.xs], [fxFlex.sm], [fxFlex.md],  [fxFlex.lg], [fxFlex.xl], [fxFlex.lt-sm], [fxFlex.lt-md],  [fxFlex.lt-lg], [fxFlex.lt-xl], [fxFlex.gt-xs], [fxFlex.gt-sm],  [fxFlex.gt-md], [fxFlex.gt-lg]", inputs: ["fxFlex", "fxFlex.xs", "fxFlex.sm", "fxFlex.md", "fxFlex.lg", "fxFlex.xl", "fxFlex.lt-sm", "fxFlex.lt-md", "fxFlex.lt-lg", "fxFlex.lt-xl", "fxFlex.gt-xs", "fxFlex.gt-sm", "fxFlex.gt-md", "fxFlex.gt-lg"] }, { kind: "directive", type: i7.DefaultShowHideDirective, selector: "  [fxShow], [fxShow.print],  [fxShow.xs], [fxShow.sm], [fxShow.md], [fxShow.lg], [fxShow.xl],  [fxShow.lt-sm], [fxShow.lt-md], [fxShow.lt-lg], [fxShow.lt-xl],  [fxShow.gt-xs], [fxShow.gt-sm], [fxShow.gt-md], [fxShow.gt-lg],  [fxHide], [fxHide.print],  [fxHide.xs], [fxHide.sm], [fxHide.md], [fxHide.lg], [fxHide.xl],  [fxHide.lt-sm], [fxHide.lt-md], [fxHide.lt-lg], [fxHide.lt-xl],  [fxHide.gt-xs], [fxHide.gt-sm], [fxHide.gt-md], [fxHide.gt-lg]", inputs: ["fxShow", "fxShow.print", "fxShow.xs", "fxShow.sm", "fxShow.md", "fxShow.lg", "fxShow.xl", "fxShow.lt-sm", "fxShow.lt-md", "fxShow.lt-lg", "fxShow.lt-xl", "fxShow.gt-xs", "fxShow.gt-sm", "fxShow.gt-md", "fxShow.gt-lg", "fxHide", "fxHide.print", "fxHide.xs", "fxHide.sm", "fxHide.md", "fxHide.lg", "fxHide.xl", "fxHide.lt-sm", "fxHide.lt-md", "fxHide.lt-lg", "fxHide.lt-xl", "fxHide.gt-xs", "fxHide.gt-sm", "fxHide.gt-md", "fxHide.gt-lg"] }, { kind: "directive", type: i7.DefaultClassDirective, selector: "  [ngClass], [ngClass.xs], [ngClass.sm], [ngClass.md], [ngClass.lg], [ngClass.xl],  [ngClass.lt-sm], [ngClass.lt-md], [ngClass.lt-lg], [ngClass.lt-xl],  [ngClass.gt-xs], [ngClass.gt-sm], [ngClass.gt-md], [ngClass.gt-lg]", inputs: ["ngClass", "ngClass.xs", "ngClass.sm", "ngClass.md", "ngClass.lg", "ngClass.xl", "ngClass.lt-sm", "ngClass.lt-md", "ngClass.lt-lg", "ngClass.lt-xl", "ngClass.gt-xs", "ngClass.gt-sm", "ngClass.gt-md", "ngClass.gt-lg"] }, { kind: "component", type: i8.OpenCloseButtonComponent, selector: "lib-open-close-button", inputs: ["disableFocusOnAction", "disabled", "isIcon", "ariaLabelCode", "isOpened"] }, { kind: "component", type: i8.TerminologyComponent, selector: "lib-terminology", inputs: ["selectedCollectionId", "system", "disabled", "storeSelectedInLocalStorage", "setSelectedFromLocalStorage", "showMenuIconOnMobile"], outputs: ["glossarySelectEvent", "menuToggleEvent"] }, { kind: "directive", type: i9.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: i10.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "pipe", type: i5.UpperCasePipe, name: "uppercase" }, { kind: "pipe", type: i5.TitleCasePipe, name: "titlecase" }, { kind: "pipe", type: i11.TranslatePipe, name: "translate" }, { kind: "pipe", type: i8.LanguageTranslatePipe, name: "languageTranslate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TranslationSystemPickerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'tld-translation-system-picker', template: "<div fxFlex fxLayout=\"row\">\r\n  <ng-container *ngIf=\"isDataLoaded\">\r\n    <div fxFlex fxLayoutAlign=\"space-between center\" fxLayoutAlign.lt-sm=\"space-evenly center\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"languageDropdownTrigger; context: { language: sourceLanguage, localizationKey: 'SYSTEM_PICKER.SOURCE', isOpened: isSourceOpened, isSource: true, ariaLabelCode: sourceAriaLabel }\">\r\n      </ng-container>\r\n      <button [disabled]=\"!canSwap\" class=\"swap-languages-button\" mat-icon-button (click)=\"swap()\"\r\n        aria-label=\"swap languages\" color=\"primary\" matTooltip=\"{{'TOOLTIPS.SWAP_LANGUAGES' | translate}}\">\r\n        <span class=\"material-icons\" aria-hidden=\"false\"\r\n          [attr.aria-label]=\"'ARIA_LABELS.SWAP_LANGUAGES' | translate\">swap_horiz</span>\r\n      </button>\r\n    </div>\r\n    <div fxFlex fxLayoutAlign=\"space-between center\"  fxLayoutAlign.lt-sm=\"space-evenly center\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"languageDropdownTrigger; context: { language: targetLanguage, localizationKey: 'SYSTEM_PICKER.TARGET', isOpened: isTargetOpened, isSource: false,  ariaLabelCode: targetAriaLabel}\">\r\n      </ng-container>\r\n\r\n      <div fxFlex fxLayoutAlign=\"end center\">\r\n        <div *ngIf=\"collectionsVisible\" #collectionWrapper class=\"terminology-wrapper\">\r\n          <lib-terminology [system]=\"system\"></lib-terminology>\r\n        </div>\r\n      </div>\r\n    </div>\r\n  </ng-container>\r\n</div>\r\n\r\n<ng-template #languageName let-language=\"language\" let-showDomain=\"showDomain\" let-detectedLanguage=\"detectedLanguage\">\r\n  <span>{{ (detectedLanguage && !showDomain ? detectedLanguage : language.lang) | languageTranslate }}</span>\r\n  <span fxHide.lt-md *ngIf=\"detectedLanguage && !showDomain\"> - {{'SYSTEM_PICKER.DETECTED' | translate}}</span>\r\n  <ng-container *ngIf=\"showDomain && domainLength>1\">\r\n    <span class=\"domain\">({{('DOMAINS.'+(activeDomainLocalizationKey | uppercase)) | translate: {default: activeDomainKey | titlecase} }})</span>\r\n  </ng-container>\r\n</ng-template>\r\n\r\n<ng-template #openedDropdown let-localizationKey=\"localizationKey\">\r\n  {{localizationKey | translate}}\r\n</ng-template>\r\n\r\n<!--Template for language dropdown trigger. Same as for target and source with different params-->\r\n<ng-template #languageDropdownTrigger let-language=\"language\" let-isOpened=\"isOpened\" let-placeholder=\"localizationKey\"\r\n  let-isSource=\"isSource\" let-ariaLabelCode=\"ariaLabelCode\">\r\n  <lib-open-close-button [disabled]=\"isFileTranslating\" class=\"system-picker-button\" [ngClass]=\"isSource? 'source': 'target'\"\r\n    [ngClass.lt-sm]=\"'system-picker-button-mobile'\" (click)=\"isSource ? sourceClick($event) : targetClick($event)\"\r\n    [disableFocusOnAction]=\"true\" [isOpened]=\"isOpened\" [class.opened]=\"isOpened\" [ariaLabelCode]=\"ariaLabelCode\">\r\n    <span [ngClass.lt-sm]=\"'mobile-domain-container'\">\r\n      <ng-container\r\n        *ngTemplateOutlet=\"isOpened && isSource || isOpened && !isSource && !isTargetReselected ? openedDropdown : languageName; context: { language: language, localizationKey: placeholder, showDomain: !isSource, detectedLanguage: system.detectedLanguage }\">\r\n      </ng-container>\r\n    </span>\r\n  </lib-open-close-button>\r\n</ng-template>\r\n", styles: [":host{display:flex}.swap-languages-button{color:var(--base-30)!important}.source{margin-left:.3em}.system-picker-button.system-picker-button-mobile{margin-left:.2em}.target{margin-left:8px}:host ::ng-deep .open-close-button-content{color:var(--base-30)}.mobile-domain-container{display:flex}.mobile-domain-container .domain{display:none}.domain{display:inline-block;max-width:250px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:bottom}.terminology-wrapper{margin-right:.3rem}:host ::ng-deep .system-picker-button-mobile{display:flex;align-items:center;max-height:46px;height:100%;max-width:120px;width:100%;background-color:var(--base-95)!important;border-radius:8px}:host ::ng-deep .system-picker-button-mobile span{font-size:12px;text-align:center;line-height:16px}:host ::ng-deep .system-picker-button-mobile .material-icons{display:none!important}:host ::ng-deep .opened .open-close-button-content,.opened button{color:var(--accent)!important}:host ::ng-deep .open-close-button-content{white-space:nowrap;overflow:hidden}:host ::ng-deep .system-picker-button-mobile span{white-space:wrap;overflow:hidden;text-align:center;max-height:46px}\n"] }]
        }], ctorParameters: () => [{ type: i1.TranslationSystemPickerService }, { type: i2.TldTranslateSystemManagementService }, { type: i3.TldTranslateFileService }, { type: i4.TldTranslateTextService }, { type: i2.TldTranslateConfigService }], propDecorators: { isCollectionsActivated: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 