import { NgIf } from '@angular/common';
import { Component, ElementRef, Optional, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CellRendererContext, Permissions, C8yTranslatePipe, IconDirective } from '@c8y/ngx-components';
import { TranslationEditorComponent } from '../translation-editor/translation-editor.component';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "../translation-editor/translation-editor.component";
import * as i3 from "@angular/forms";
export class ManageTranslationCellRendererComponent {
    constructor(context, permissions, grid) {
        this.context = context;
        this.permissions = permissions;
        this.grid = grid;
        this.FOCUS_RENDER_WAIT_TIME_IN_MS = 100;
        this.isCellEditable = false;
        this.cellValue = '';
        this.isCreateDisabled = false;
    }
    ngOnInit() {
        this.isCreateDisabled = !this.permissions.hasRole('ROLE_APPLICATION_MANAGEMENT_ADMIN');
    }
    async save() {
        this.isCellEditable = false;
        const cellValueTrimed = this.cellValue.trim();
        this.context.value = cellValueTrimed;
        this.context.item[this.context.property.path] = cellValueTrimed;
        this.grid?.valueChanged();
    }
    cancel() {
        this.isCellEditable = false;
    }
    editCell() {
        this.cellValue = this.context.value;
        this.isCellEditable = true;
        // Focuses the input box after the input text box is visible
        setTimeout(() => {
            this.cellInput.nativeElement.focus();
        }, this.FOCUS_RENDER_WAIT_TIME_IN_MS);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ManageTranslationCellRendererComponent, deps: [{ token: i1.CellRendererContext }, { token: i1.Permissions }, { token: i2.TranslationEditorComponent, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ManageTranslationCellRendererComponent, isStandalone: true, selector: "c8y-manage-translation-cell-renderer", viewQueries: [{ propertyName: "cellInput", first: true, predicate: ["cellInput"], descendants: true }], ngImport: i0, template: "<div\n  class=\"text-truncate pointer d-flex\"\n  title=\"{{ context.value }}\"\n  data-cy=\"c8y-manage-translation-cell-renderer--edit\"\n  (click)=\"!isCreateDisabled ? editCell() : ''\"\n  *ngIf=\"!isCellEditable\"\n>\n  <span\n    class=\"text-truncate\"\n    *ngIf=\"!isCellEditable && context.value !== ''\"\n  >\n    {{ context.value }}\n  </span>\n  <span\n    class=\"text-truncate\"\n    title=\"{{ 'Add translation' | translate }}\"\n    *ngIf=\"!isCellEditable && context.value === ''\"\n  >\n    <em class=\"text-muted\">{{ 'Add translation' | translate }}</em>\n  </span>\n  <i\n    class=\"showOnHover text-primary m-l-4\"\n    c8yIcon=\"pencil\"\n    title=\"{{ 'Edit translation' | translate }}\"\n    *ngIf=\"!isCreateDisabled\"\n  ></i>\n</div>\n\n<div\n  class=\"input-group input-group-sm\"\n  *ngIf=\"isCellEditable && !isCreateDisabled\"\n>\n  <input\n    class=\"form-control\"\n    placeholder=\"{{ 'Add translation' | translate }}\"\n    type=\"text\"\n    #cellInput\n    data-cy=\"c8y-manage-translation-cell-renderer--input\"\n    [(ngModel)]=\"cellValue\"\n  />\n  <div class=\"input-group-btn\">\n    <button\n      class=\"btn btn-clean\"\n      title=\"{{ 'Cancel' | translate }}\"\n      type=\"button\"\n      (click)=\"cancel()\"\n      data-cy=\"c8y-manage-translation-cell-renderer--cancel\"\n    >\n      <i\n        class=\"text-danger\"\n        c8yIcon=\"times\"\n      ></i>\n    </button>\n    <button\n      class=\"btn btn-clean\"\n      title=\"{{ 'Save' | translate }}\"\n      type=\"button\"\n      (click)=\"save()\"\n      data-cy=\"c8y-manage-translation-cell-renderer--save\"\n    >\n      <i\n        class=\"text-primary\"\n        c8yIcon=\"check\"\n      ></i>\n    </button>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ManageTranslationCellRendererComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-manage-translation-cell-renderer', standalone: true, imports: [NgIf, C8yTranslatePipe, IconDirective, FormsModule], template: "<div\n  class=\"text-truncate pointer d-flex\"\n  title=\"{{ context.value }}\"\n  data-cy=\"c8y-manage-translation-cell-renderer--edit\"\n  (click)=\"!isCreateDisabled ? editCell() : ''\"\n  *ngIf=\"!isCellEditable\"\n>\n  <span\n    class=\"text-truncate\"\n    *ngIf=\"!isCellEditable && context.value !== ''\"\n  >\n    {{ context.value }}\n  </span>\n  <span\n    class=\"text-truncate\"\n    title=\"{{ 'Add translation' | translate }}\"\n    *ngIf=\"!isCellEditable && context.value === ''\"\n  >\n    <em class=\"text-muted\">{{ 'Add translation' | translate }}</em>\n  </span>\n  <i\n    class=\"showOnHover text-primary m-l-4\"\n    c8yIcon=\"pencil\"\n    title=\"{{ 'Edit translation' | translate }}\"\n    *ngIf=\"!isCreateDisabled\"\n  ></i>\n</div>\n\n<div\n  class=\"input-group input-group-sm\"\n  *ngIf=\"isCellEditable && !isCreateDisabled\"\n>\n  <input\n    class=\"form-control\"\n    placeholder=\"{{ 'Add translation' | translate }}\"\n    type=\"text\"\n    #cellInput\n    data-cy=\"c8y-manage-translation-cell-renderer--input\"\n    [(ngModel)]=\"cellValue\"\n  />\n  <div class=\"input-group-btn\">\n    <button\n      class=\"btn btn-clean\"\n      title=\"{{ 'Cancel' | translate }}\"\n      type=\"button\"\n      (click)=\"cancel()\"\n      data-cy=\"c8y-manage-translation-cell-renderer--cancel\"\n    >\n      <i\n        class=\"text-danger\"\n        c8yIcon=\"times\"\n      ></i>\n    </button>\n    <button\n      class=\"btn btn-clean\"\n      title=\"{{ 'Save' | translate }}\"\n      type=\"button\"\n      (click)=\"save()\"\n      data-cy=\"c8y-manage-translation-cell-renderer--save\"\n    >\n      <i\n        class=\"text-primary\"\n        c8yIcon=\"check\"\n      ></i>\n    </button>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.CellRendererContext }, { type: i1.Permissions }, { type: i2.TranslationEditorComponent, decorators: [{
                    type: Optional
                }] }], propDecorators: { cellInput: [{
                type: ViewChild,
                args: ['cellInput']
            }] } });
//# sourceMappingURL=data:application/json;base64, 