import { ChangeDetectionStrategy, Component, EventEmitter, HostBinding, Inject, Input, Optional, Output, ViewChild } from '@angular/core';
import { isBoolean, isNull, isNullOrUndefined } from '@ironsource/fusion-ui/utils';
import { BehaviorSubject } from 'rxjs';
import { TableService } from '@ironsource/fusion-ui/components/table/common/services';
import { InputInlineComponent } from '@ironsource/fusion-ui/components/input-inline/v1';
import { CELL_PADDING, DEFAULT_REMOVE_ICON, DEFAULT_REMOVE_TOOLTIP_TEXT, DEFAULT_REMOVE_TOOLTIP_WIDTH, TABLE_OPTIONS_TOKEN, TableRowHeight } from '@ironsource/fusion-ui/components/table/common/entities';
import { ERROR_MESSAGES } from '@ironsource/fusion-ui/components/error-message';
import { LogService } from '@ironsource/fusion-ui/services/log';
import * as i0 from "@angular/core";
import * as i1 from "@ironsource/fusion-ui/components/table/common/services";
import * as i2 from "@ironsource/fusion-ui/services/log";
import * as i3 from "@angular/common";
import * as i4 from "@ironsource/fusion-ui/components/icon/v1";
import * as i5 from "@ironsource/fusion-ui/components/input-inline/v1";
import * as i6 from "@ironsource/fusion-ui/components/loader/v1";
import * as i7 from "@ironsource/fusion-ui/components/checkbox/v1";
import * as i8 from "@ironsource/fusion-ui/components/dynamic-components/v1";
import * as i9 from "@ironsource/fusion-ui/components/tooltip/v1";
import * as i10 from "@ironsource/fusion-ui/components/toggle/v1";
import * as i11 from "@angular/forms";
import * as i12 from "@ironsource/fusion-ui/pipes/not-available";
const _c0 = ["inlineInput"];
const _c1 = ["fusionTableCell", ""];
function TableCellComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 3);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "notAvailable");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵstyleProp("width", ctx_r0.innerElementWidth);
    i0.ɵɵproperty("ngClass", ctx_r0.column.align)("fusionTooltip", ctx_r0.cellStringData);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind2(3, 5, ctx_r0.cellStringData, ctx_r0.notAvailableText), " ");
} }
function TableCellComponent_ng_template_1_div_0_Template(rf, ctx) { if (rf & 1) {
    const _r13 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 9)(1, "fusion-checkbox", 10);
    i0.ɵɵlistener("changed", function TableCellComponent_ng_template_1_div_0_Template_fusion_checkbox_changed_1_listener($event) { i0.ɵɵrestoreView(_r13); const ctx_r12 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r12.selectedChange.emit($event)); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("checked", ctx_r4.isRowChecked())("name", "row_" + ctx_r4.position.x);
} }
function TableCellComponent_ng_template_1_div_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 13);
    i0.ɵɵelement(1, "fusion-loader", 14);
    i0.ɵɵpipe(2, "async");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r14 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance();
    i0.ɵɵproperty("status", i0.ɵɵpipeBind1(2, 1, ctx_r14.isInRequest$));
} }
function TableCellComponent_ng_template_1_div_1_fusion_toggle_3_Template(rf, ctx) { if (rf & 1) {
    const _r17 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "fusion-toggle", 15);
    i0.ɵɵlistener("modelChange", function TableCellComponent_ng_template_1_div_1_fusion_toggle_3_Template_fusion_toggle_modelChange_0_listener($event) { i0.ɵɵrestoreView(_r17); const ctx_r16 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r16.onToggleChanged($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r15 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("model", ctx_r15.data)("isDisabled", ctx_r15.isReadOnly);
} }
function TableCellComponent_ng_template_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵtemplate(1, TableCellComponent_ng_template_1_div_1_div_1_Template, 3, 3, "div", 11);
    i0.ɵɵpipe(2, "async");
    i0.ɵɵtemplate(3, TableCellComponent_ng_template_1_div_1_fusion_toggle_3_Template, 1, 2, "fusion-toggle", 12);
    i0.ɵɵpipe(4, "async");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", i0.ɵɵpipeBind1(2, 2, ctx_r5.isInRequest$));
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", i0.ɵɵpipeBind1(4, 4, ctx_r5.isInRequest$) === false);
} }
function TableCellComponent_ng_template_1_div_2_fusion_input_inline_1_Template(rf, ctx) { if (rf & 1) {
    const _r23 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "fusion-input-inline", 19, 20);
    i0.ɵɵlistener("onSave", function TableCellComponent_ng_template_1_div_2_fusion_input_inline_1_Template_fusion_input_inline_onSave_0_listener($event) { i0.ɵɵrestoreView(_r23); const ctx_r22 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r22.onEndEdit($event)); })("onCancel", function TableCellComponent_ng_template_1_div_2_fusion_input_inline_1_Template_fusion_input_inline_onCancel_0_listener() { i0.ɵɵrestoreView(_r23); const ctx_r24 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r24.onCancel()); });
    i0.ɵɵpipe(2, "async");
    i0.ɵɵpipe(3, "async");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r18 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("type", ctx_r18.column.inputType)("textClass", ctx_r18.customClass && ctx_r18.customClass[ctx_r18.column.key])("formControl", ctx_r18.data)("loading", i0.ɵɵpipeBind1(2, 7, ctx_r18.isInRequest$))("error", i0.ɵɵpipeBind1(3, 9, ctx_r18.inputError$))("readOnly", ctx_r18.isReadOnly)("currencyPipeParameters", ctx_r18.column == null ? null : ctx_r18.column.currencyPipeParameters);
} }
function TableCellComponent_ng_template_1_div_2_ng_template_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtext(0, "\u00A0");
} }
function TableCellComponent_ng_template_1_div_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 16);
    i0.ɵɵtemplate(1, TableCellComponent_ng_template_1_div_2_fusion_input_inline_1_Template, 4, 11, "fusion-input-inline", 17)(2, TableCellComponent_ng_template_1_div_2_ng_template_2_Template, 1, 0, "ng-template", null, 18, i0.ɵɵtemplateRefExtractor);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const _r20 = i0.ɵɵreference(3);
    const ctx_r6 = i0.ɵɵnextContext(2);
    i0.ɵɵstyleProp("min-width", "calc(" + ctx_r6.column.width + " - 1px)");
    i0.ɵɵproperty("ngClass", ctx_r6.column.align);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", !ctx_r6.isRowTotal)("ngIfElse", _r20);
} }
function TableCellComponent_ng_template_1_fusion_dynamic_components_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "fusion-dynamic-components", 21);
} if (rf & 2) {
    const ctx_r7 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("configuration", ctx_r7.customCellData);
} }
function TableCellComponent_ng_template_1_div_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵpipe(1, "currency");
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "currency");
    i0.ɵɵpipe(4, "notAvailable");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵstyleProp("width", ctx_r8.innerElementWidth);
    i0.ɵɵproperty("ngClass", ctx_r8.column.align || "right")("fusionTooltip", i0.ɵɵpipeBind2(1, 5, ctx_r8.data, "USD"));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", !ctx_r8.isNull(ctx_r8.data) ? i0.ɵɵpipeBind4(3, 8, ctx_r8.data, (ctx_r8.column == null ? null : ctx_r8.column.currencyPipeParameters == null ? null : ctx_r8.column.currencyPipeParameters.currencyCode) || undefined, (ctx_r8.column == null ? null : ctx_r8.column.currencyPipeParameters == null ? null : ctx_r8.column.currencyPipeParameters.display) || ((ctx_r8.column == null ? null : ctx_r8.column.currencyPipeParameters) ? undefined : "$ "), (ctx_r8.column == null ? null : ctx_r8.column.currencyPipeParameters == null ? null : ctx_r8.column.currencyPipeParameters.digitsInfo) || undefined) : i0.ɵɵpipeBind2(4, 13, ctx_r8.data, ctx_r8.notAvailableText), " ");
} }
function TableCellComponent_ng_template_1_div_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵpipe(1, "number");
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "number");
    i0.ɵɵpipe(4, "notAvailable");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵstyleProp("width", ctx_r9.innerElementWidth);
    i0.ɵɵproperty("ngClass", ctx_r9.column.align || "right")("fusionTooltip", i0.ɵɵpipeBind2(1, 5, ctx_r9.data, ctx_r9.column.pipeOptions));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", !ctx_r9.isNull(ctx_r9.data) ? i0.ɵɵpipeBind2(3, 8, ctx_r9.data, ctx_r9.column.pipeOptions) : i0.ɵɵpipeBind2(4, 11, ctx_r9.data, ctx_r9.notAvailableText), " ");
} }
function TableCellComponent_ng_template_1_div_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵpipe(1, "number");
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "number");
    i0.ɵɵpipe(4, "notAvailable");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r10 = i0.ɵɵnextContext(2);
    i0.ɵɵstyleProp("width", ctx_r10.innerElementWidth);
    i0.ɵɵpropertyInterpolate1("fusionTooltip", "", i0.ɵɵpipeBind2(1, 6, ctx_r10.data, ctx_r10.column.pipeOptions), " %");
    i0.ɵɵproperty("ngClass", ctx_r10.column.align || "right");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate2(" ", !ctx_r10.isNull(ctx_r10.data) ? i0.ɵɵpipeBind2(3, 9, ctx_r10.data, ctx_r10.column.pipeOptions) : i0.ɵɵpipeBind2(4, 12, ctx_r10.data, ctx_r10.notAvailableText), " ", !ctx_r10.isNullOrUndefined(ctx_r10.data) ? "%" : null, " ");
} }
function TableCellComponent_ng_template_1_div_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 22);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "date");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r11 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", ctx_r11.data ? ctx_r11.isAsDate(ctx_r11.data) ? i0.ɵɵpipeBind3(2, 1, ctx_r11.data, ctx_r11.getDateFormat(ctx_r11.column.dateFormat), ctx_r11.getDateUTCFormat(ctx_r11.column.ignoreTimeZone)) : ctx_r11.data : !ctx_r11.isRowTotal ? "No " + ctx_r11.column.title : "", " ");
} }
function TableCellComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtemplate(0, TableCellComponent_ng_template_1_div_0_Template, 2, 2, "div", 4)(1, TableCellComponent_ng_template_1_div_1_Template, 5, 6, "div", 2)(2, TableCellComponent_ng_template_1_div_2_Template, 4, 5, "div", 5)(3, TableCellComponent_ng_template_1_fusion_dynamic_components_3_Template, 1, 1, "fusion-dynamic-components", 6)(4, TableCellComponent_ng_template_1_div_4_Template, 5, 16, "div", 7)(5, TableCellComponent_ng_template_1_div_5_Template, 5, 14, "div", 7)(6, TableCellComponent_ng_template_1_div_6_Template, 5, 15, "div", 7)(7, TableCellComponent_ng_template_1_div_7_Template, 3, 5, "div", 8);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeCheckbox(ctx_r1.column) && ctx_r1.isBoolean(ctx_r1.data));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeToggleButton(ctx_r1.column) && ctx_r1.isBoolean(ctx_r1.data));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeInputEdit(ctx_r1.column) && ctx_r1.data);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeComponent(ctx_r1.column));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeCurrency(ctx_r1.column));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeNumber(ctx_r1.column));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypePercent(ctx_r1.column));
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.tableService.isTypeDate(ctx_r1.column));
} }
function TableCellComponent_ng_container_3_fusion_icon_1_Template(rf, ctx) { if (rf & 1) {
    const _r28 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "fusion-icon", 25);
    i0.ɵɵlistener("click", function TableCellComponent_ng_container_3_fusion_icon_1_Template_fusion_icon_click_0_listener() { i0.ɵɵrestoreView(_r28); const ctx_r27 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r27.remove.emit()); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r25 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("name", ctx_r25.getRemoveIconName())("fusionTooltip", ctx_r25.getRemoveIconTooltipText())("tooltipWidth", ctx_r25.getRemoveIconTooltipWidth());
} }
function TableCellComponent_ng_container_3_fusion_icon_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "fusion-icon", 26);
} if (rf & 2) {
    const ctx_r26 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("fusionTooltip", ctx_r26.infoIconTooltip);
} }
function TableCellComponent_ng_container_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, TableCellComponent_ng_container_3_fusion_icon_1_Template, 1, 3, "fusion-icon", 23)(2, TableCellComponent_ng_container_3_fusion_icon_2_Template, 1, 1, "fusion-icon", 24);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r3.isRemove && !ctx_r3.isReadOnly);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r3.infoIconTooltip);
} }
export class TableCellComponent {
    set data(value) {
        this._data = value;
    }
    get isCellEditable() {
        return this.tableService.isTypeInputEdit(this.column);
    }
    get sticky() {
        return this.column.sticky;
    }
    get stickyLeft() {
        return this.column.stickyLeftMargin;
    }
    get data() {
        if (!isNull(this._data) && this.tableService.isTypeComponent(this.column) && typeof this._data === 'object') {
            this._data['cellPosition'] = this.position;
        }
        return this._data;
    }
    get cellStringData() {
        if (typeof this.data === 'string' || typeof this.data === 'number') {
            return this.data;
        }
        else if (this.isRowTotal && !isNullOrUndefined(this.data)) {
            this.logService.error(new Error(`Expected data type String for cell in total row with type "totalRowTypeAsString" for column key:${this.column.key}`));
            return ' ';
        }
        else if (this.isRowTotal && isNullOrUndefined(this.data)) {
            return ' '; // for total row cell as string if data not arrive
        }
        return isNull(this.data) ? null : undefined;
    }
    get isRowTotal() {
        return !isNullOrUndefined(this.options.hasTotalsRow) && this.options.hasTotalsRow && this.position.x === 0;
    }
    get isSmallActionButton() {
        return !!this.options && !!this.options.rowHeight && this.options.rowHeight === TableRowHeight.Small;
    }
    get nativeElement() {
        return this.column && typeof this.column.renderNativeElement === 'function'
            ? this.column.renderNativeElement(this.data, this.position, this.row)
            : null;
    }
    constructor(tableService, tableModuleOptions, logService) {
        this.tableService = tableService;
        this.tableModuleOptions = tableModuleOptions;
        this.logService = logService;
        this.options = null;
        this.customClass = {};
        this.selectedChange = new EventEmitter();
        this.dataChange = new EventEmitter();
        this.remove = new EventEmitter();
        this.cellBorders = true;
        this.isInlineRemovable = false;
        this.isInRequest$ = new BehaviorSubject(false);
        this.cellLRPadding = CELL_PADDING;
        this.innerElementWidth = '';
        this.isInEditMode = false;
        this.inputError$ = new BehaviorSubject('');
        this.isNull = isNull;
        this.isNullOrUndefined = isNullOrUndefined;
        this.inlineInputViewOnlyText = '';
    }
    ngOnInit() {
        this.cellBorders =
            isNullOrUndefined(this.options.cellBorders) || this.tableService.isTypeCheckbox(this.column) ? true : this.options.cellBorders;
        this.innerElementWidth = this.column.width ? `calc(${this.column.width} - ${this.cellLRPadding})` : '';
        this.notAvailableText = this.options ? this.options.notAvailableText : null;
    }
    ngOnChanges(changes) {
        this.isInlineRemovable = this.isRemove;
        if (this.tableService.isTypeInputEdit(this.column) && changes?.data?.currentValue && !changes.data.firstChange) {
            this._setInputData();
        }
        if (this.tableService.isTypeComponent(this.column) && (changes?.data?.currentValue || changes?.column?.currentValue)) {
            this.renderCustomElement();
        }
        if (changes?.data?.firstChange && changes?.data?.currentValue?.value?.viewOnlyText) {
            this.inlineInputViewOnlyText = changes.data.currentValue.value.viewOnlyText;
        }
    }
    _setInputData() {
        this.initInputData = !isNullOrUndefined(this.column.dataParser)
            ? this.column.dataParser(this.data.value)
            : this.data.value;
    }
    getRemoveIconName() {
        return this.options && this.options.remove && this.options.remove.icon ? this.options.remove.icon : DEFAULT_REMOVE_ICON;
    }
    getRemoveIconTooltipText() {
        return this.options && this.options.remove && this.options.remove.tooltip && this.options.remove.tooltip.text
            ? this.options.remove.tooltip.text
            : DEFAULT_REMOVE_TOOLTIP_TEXT;
    }
    getRemoveIconTooltipWidth() {
        return this.options && this.options.remove && this.options.remove.tooltip && this.options.remove.tooltip.width
            ? this.options.remove.tooltip.width
            : DEFAULT_REMOVE_TOOLTIP_WIDTH;
    }
    isBoolean(variable) {
        return isBoolean(variable);
    }
    isRowChecked() {
        return this.options.isGroupedTable ? this.data : this.isRowSelected;
    }
    isAsDate(date) {
        return !isNaN(Date.parse(date.toString()));
    }
    onToggleChanged(newValue) {
        // set waiter for cell
        this.isInRequest$.next(true);
        this.dataChange.emit({
            newValue,
            onCellRequestDone: (isSuccess, error, stayInEditMode = false) => {
                if (isSuccess) {
                    this.data = newValue;
                }
                else {
                    this.data = !newValue;
                }
                this.isInRequest$.next(false);
            }
        });
    }
    onEndEdit(valuesOptions) {
        const formControl = this.data;
        if (formControl.valid) {
            this.isInEditMode = false;
            const newValue = !isNullOrUndefined(this.column.dataParser) ? this.column.dataParser(formControl.value) : formControl.value;
            const prevValue = valuesOptions.currentValue;
            const inlineInputComponent = this.inlineInputEdit;
            if (newValue !== this.initInputData) {
                this.initInputData = newValue;
                // set waiter for cell
                this.isInRequest$.next(true);
                this.dataChange.emit({
                    newValue,
                    prevValue,
                    onCellRequestDone: (isSuccess, error, stayInEditMode = false) => {
                        if (!isSuccess) {
                            if (stayInEditMode) {
                                inlineInputComponent.setEditMode$.next(newValue);
                            }
                            else {
                                this.inputError$.next(error && error.message);
                            }
                            this.initInputData = prevValue;
                        }
                        else if (this.initInputData === '') {
                            this.inputError$.next('');
                            this.initInputData = formControl.value;
                        }
                        else {
                            this.inputError$.next('');
                            const newInputValue = this.inlineInputViewOnlyText
                                ? {
                                    value: newValue,
                                    viewOnlyText: this.inlineInputViewOnlyText
                                }
                                : newValue;
                            formControl.setValue(newInputValue, {
                                emitEvent: false
                            });
                        }
                        this.isInRequest$.next(false);
                    }
                });
            }
        }
        else {
            const allErrors = formControl.errors || {};
            Object.keys(allErrors).forEach(errorKey => {
                this.inputError$.next(this._getMessage(errorKey, this.column.customErrorMapping[errorKey] || {}));
            });
        }
    }
    onCancel() {
        this.inputError$.next('');
        this.isInEditMode = false;
    }
    getDateFormat(dateFormat) {
        return dateFormat || 'd MMM yyyy';
    }
    getDateUTCFormat(ignoreTimeZone) {
        return ignoreTimeZone ? null : 'UTC';
    }
    renderCustomElement() {
        if (this.column) {
            this.customCellData = {
                component: {
                    type: this.column.component,
                    data: this.data
                },
                element: this.nativeElement
            };
        }
    }
    _getMessage(errorKey, { errorMessageKey = '', textMapping = [] }) {
        const tableModuleOptions = !isNullOrUndefined(this.tableModuleOptions) ? this.tableModuleOptions : { errorMessages: ERROR_MESSAGES };
        if (!tableModuleOptions.errorMessages) {
            tableModuleOptions.errorMessages = ERROR_MESSAGES;
        }
        let errorMessage = tableModuleOptions.errorMessages[errorMessageKey] || tableModuleOptions.errorMessages[errorKey];
        if (errorMessage) {
            errorMessage = errorMessage.replace('{NAME}', this.column.title);
            errorMessage = errorMessage.replace('{INNER-NAME}', this.column.title);
            if (textMapping && textMapping.length > 0) {
                textMapping.forEach(mappObj => {
                    errorMessage = errorMessage.replace(`{${mappObj.key}}`, mappObj.value);
                });
            }
        }
        return errorMessage;
    }
    static { this.ɵfac = function TableCellComponent_Factory(t) { return new (t || TableCellComponent)(i0.ɵɵdirectiveInject(i1.TableService), i0.ɵɵdirectiveInject(TABLE_OPTIONS_TOKEN, 8), i0.ɵɵdirectiveInject(i2.LogService)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TableCellComponent, selectors: [["", "fusionTableCell", ""]], viewQuery: function TableCellComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.inlineInputEdit = _t.first);
        } }, hostVars: 10, hostBindings: function TableCellComponent_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵstyleProp("left", ctx.stickyLeft);
            i0.ɵɵclassProp("cell-borders", ctx.cellBorders)("is-inline-removable", ctx.isInlineRemovable)("is-editable", ctx.isCellEditable)("sticky-left", ctx.sticky);
        } }, inputs: { data: "data", column: "column", row: "row", options: "options", position: "position", infoIconTooltip: "infoIconTooltip", isRemove: "isRemove", isRowSelected: "isRowSelected", isLastColumn: "isLastColumn", customClass: "customClass", isReadOnly: "isReadOnly" }, outputs: { selectedChange: "selectedChange", dataChange: "dataChange", remove: "remove" }, features: [i0.ɵɵNgOnChangesFeature], attrs: _c1, decls: 4, vars: 3, consts: [[4, "ngIf", "ngIfElse"], ["notStringColumnType", ""], [4, "ngIf"], [1, "truncate", "centerVertical", 3, "ngClass", "fusionTooltip"], ["class", "checkbox-cell", 4, "ngIf"], ["class", "inputType", 3, "min-width", "ngClass", 4, "ngIf"], [3, "configuration", 4, "ngIf"], ["class", "truncate centerVertical", 3, "ngClass", "width", "fusionTooltip", 4, "ngIf"], ["class", "truncate centerVertical", 4, "ngIf"], [1, "checkbox-cell"], ["title", "select / un-select row", 1, "is-regular", 3, "checked", "name", "changed"], ["class", "loader-holder", 4, "ngIf"], ["size", "small", 3, "model", "isDisabled", "modelChange", 4, "ngIf"], [1, "loader-holder"], ["size", "small", 3, "status"], ["size", "small", 3, "model", "isDisabled", "modelChange"], [1, "inputType", 3, "ngClass"], [3, "type", "textClass", "formControl", "loading", "error", "readOnly", "currencyPipeParameters", "onSave", "onCancel", 4, "ngIf", "ngIfElse"], ["noEditCell", ""], [3, "type", "textClass", "formControl", "loading", "error", "readOnly", "currencyPipeParameters", "onSave", "onCancel"], ["inlineInput", ""], [3, "configuration"], [1, "truncate", "centerVertical"], ["class", "removeRowIcon", 3, "name", "fusionTooltip", "tooltipWidth", "click", 4, "ngIf"], ["class", "infoRowIcon", "name", "info-tooltip", 3, "fusionTooltip", 4, "ngIf"], [1, "removeRowIcon", 3, "name", "fusionTooltip", "tooltipWidth", "click"], ["name", "info-tooltip", 1, "infoRowIcon", 3, "fusionTooltip"]], template: function TableCellComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, TableCellComponent_ng_container_0_Template, 4, 8, "ng-container", 0)(1, TableCellComponent_ng_template_1_Template, 8, 8, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor)(3, TableCellComponent_ng_container_3_Template, 3, 2, "ng-container", 2);
        } if (rf & 2) {
            const _r2 = i0.ɵɵreference(2);
            i0.ɵɵproperty("ngIf", ctx.isRowTotal && ctx.tableService.isInTotalTypeString(ctx.column) || ctx.tableService.isTypeString(ctx.column))("ngIfElse", _r2);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngIf", !ctx.isRowTotal);
        } }, dependencies: [i3.NgClass, i3.NgIf, i4.IconComponent, i5.InputInlineComponent, i6.LoaderComponent, i7.CheckboxComponent, i8.DynamicComponentsComponent, i9.TooltipDirective, i10.ToggleComponent, i11.NgControlStatus, i11.FormControlDirective, i3.AsyncPipe, i3.DecimalPipe, i3.CurrencyPipe, i3.DatePipe, i12.NotAvailablePipe], styles: [".v1[_nghost-%COMP%], .v1   [_nghost-%COMP%]{font-size:13px;font-family:var(--regular-font-family, \"Open Sans\");font-weight:400}tr.is-with-totals[_nghost-%COMP%], tr.is-with-totals   [_nghost-%COMP%]{font-size:12px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:700}.v2[_nghost-%COMP%], .v2   [_nghost-%COMP%]{font-size:12px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:400}[_nghost-%COMP%]   .truncate[_ngcontent-%COMP%]{width:100%;display:inline-block;white-space:nowrap;overflow:hidden!important;text-overflow:ellipsis}.is-inline-removable[_nghost-%COMP%]   fusion-icon.delete[_ngcontent-%COMP%]{margin-top:0!important;position:absolute;top:50%;transform:translateY(-50%)}[_nghost-%COMP%]{position:relative;padding:0 10px;color:var(--dark-color-300, #172D4C);word-break:break-all;max-width:350px;border-top:1px solid var(--light-color, #E1E6EB);border-bottom:1px solid var(--light-color, #E1E6EB)}[_nghost-%COMP%]:first-child{border-left:none}[_nghost-%COMP%]:last-child{border-right:none}[_nghost-%COMP%]   fusion-icon[_ngcontent-%COMP%]{display:block;padding-top:5px;padding-left:5px}.cell-borders[_nghost-%COMP%]{border:1px solid var(--light-color, #E1E6EB)}.is-inline-removable[_nghost-%COMP%]   fusion-icon.close[_ngcontent-%COMP%]{visibility:hidden;position:absolute;right:25px;top:6px;cursor:pointer}.is-inline-removable[_nghost-%COMP%]   fusion-icon.close[_ngcontent-%COMP%]:hover     svg *{fill:var(--primary-color, #3091F6)}.is-inline-removable[_nghost-%COMP%]   fusion-icon.close[_ngcontent-%COMP%]     svg{width:8px;height:8px}.is-inline-removable[_nghost-%COMP%]   fusion-icon.close[_ngcontent-%COMP%]     svg *{fill:var(--light-color-800, #678099)}.is-inline-removable[_nghost-%COMP%]   fusion-icon.delete[_ngcontent-%COMP%]{visibility:hidden;right:8px;cursor:pointer;top:calc(50% - 2px)}.is-inline-removable[_nghost-%COMP%]   fusion-icon.delete[_ngcontent-%COMP%]     svg{width:13px;height:13px}.is-inline-removable[_nghost-%COMP%]   fusion-icon.delete[_ngcontent-%COMP%]     svg *{fill:var(--light-color-900, #52677B)}.is-inline-removable[_nghost-%COMP%]:hover   fusion-icon.delete[_ngcontent-%COMP%]     svg{width:13px;height:13px}.is-inline-removable[_nghost-%COMP%]:hover   fusion-icon.delete[_ngcontent-%COMP%]     svg *{fill:var(--primary-color, #3091F6)}[_nghost-%COMP%]   fusion-icon.info-tooltip[_ngcontent-%COMP%]{visibility:hidden;position:absolute;right:25px;top:8px}[_nghost-%COMP%]   fusion-icon.info-tooltip[_ngcontent-%COMP%]     svg{width:11px;height:11px}[_nghost-%COMP%]   fusion-icon.info-tooltip[_ngcontent-%COMP%]     svg *{fill:var(--light-color-800, #678099)}[_nghost-%COMP%]   .is-ellipsis-rows-2[_ngcontent-%COMP%]{overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.is-editable[_nghost-%COMP%]{padding:0}.is-editable[_nghost-%COMP%]   fusion-input-inline[_ngcontent-%COMP%]{display:block;padding:0 10px}[_nghost-%COMP%] > div[_ngcontent-%COMP%]{vertical-align:middle}[_nghost-%COMP%] > div.right[_ngcontent-%COMP%]{text-align:right;float:none}[_nghost-%COMP%] > div.center[_ngcontent-%COMP%]{text-align:center}[_nghost-%COMP%] > div.checkbox-cell[_ngcontent-%COMP%]{margin:0 auto;text-align:center}[_nghost-%COMP%]   .loader-holder[_ngcontent-%COMP%]{position:relative;top:2px;width:20px}.v1[_nghost-%COMP%], .v1   [_nghost-%COMP%]{height:55px}.v2[_nghost-%COMP%], .v2   [_nghost-%COMP%]{height:43px}tr:hover.is-inline-removable[_nghost-%COMP%]   fusion-icon.removeRowIcon[_ngcontent-%COMP%], tr:hover   .is-inline-removable[_nghost-%COMP%]   fusion-icon.removeRowIcon[_ngcontent-%COMP%]{visibility:visible}tr:hover[_nghost-%COMP%]   fusion-icon.infoRowIcon[_ngcontent-%COMP%], tr:hover   [_nghost-%COMP%]   fusion-icon.infoRowIcon[_ngcontent-%COMP%]{visibility:visible}tr.is-row-in-request[_nghost-%COMP%]   fusion-toggle[_ngcontent-%COMP%], tr.is-row-in-request   [_nghost-%COMP%]   fusion-toggle[_ngcontent-%COMP%]{opacity:.5}tr.is-with-totals[_nghost-%COMP%], tr.is-with-totals   [_nghost-%COMP%]{height:25px;letter-spacing:.5px;background-color:var(--light-color-100, #F9FAFB);border:none;border-bottom:solid 1px var(--light-color-700, #95A6B8)}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TableCellComponent, [{
        type: Component,
        args: [{ selector: '[fusionTableCell]', changeDetection: ChangeDetectionStrategy.OnPush, template: "\n    <ng-container\n        *ngIf=\"(isRowTotal && tableService.isInTotalTypeString(column)) || tableService.isTypeString(column); else notStringColumnType\"\n    >\n        <!--String Cell-->\n        <div class=\"truncate centerVertical\" [ngClass]=\"column.align\" [style.width]=\"innerElementWidth\" [fusionTooltip]=\"cellStringData\">\n            {{ cellStringData | notAvailable: notAvailableText }}\n        </div>\n    </ng-container>\n\n    <ng-template #notStringColumnType>\n        <!--Checkbox Cell-->\n        <div *ngIf=\"tableService.isTypeCheckbox(column) && isBoolean(data)\" class=\"checkbox-cell\">\n            <fusion-checkbox\n                class=\"is-regular\"\n                title=\"select / un-select row\"\n                [checked]=\"isRowChecked()\"\n                (changed)=\"selectedChange.emit($event)\"\n                [name]=\"'row_' + position.x\"\n            ></fusion-checkbox>\n        </div>\n        <!--ToggleButton Cell-->\n        <div *ngIf=\"tableService.isTypeToggleButton(column) && isBoolean(data)\">\n            <div class=\"loader-holder\" *ngIf=\"isInRequest$ | async\">\n                <fusion-loader [status]=\"isInRequest$ | async\" size=\"small\"></fusion-loader>\n            </div>\n            <fusion-toggle\n                *ngIf=\"(isInRequest$ | async) === false\"\n                [model]=\"data\"\n                [isDisabled]=\"isReadOnly\"\n                size=\"small\"\n                (modelChange)=\"onToggleChanged($event)\"\n            ></fusion-toggle>\n        </div>\n        <!--InputEdit Cell-->\n        <div\n            *ngIf=\"tableService.isTypeInputEdit(column) && data\"\n            [style.min-width]=\"'calc(' + column.width + ' - 1px)'\"\n            class=\"inputType\"\n            [ngClass]=\"column.align\"\n        >\n            <fusion-input-inline\n                #inlineInput\n                *ngIf=\"!isRowTotal; else noEditCell\"\n                [type]=\"column.inputType\"\n                (onSave)=\"onEndEdit($event)\"\n                (onCancel)=\"onCancel()\"\n                [textClass]=\"customClass && customClass[column.key]\"\n                [formControl]=\"data\"\n                [loading]=\"isInRequest$ | async\"\n                [error]=\"inputError$ | async\"\n                [readOnly]=\"isReadOnly\"\n                [currencyPipeParameters]=\"column?.currencyPipeParameters\"\n            ></fusion-input-inline>\n            <ng-template #noEditCell>&nbsp;</ng-template>\n        </div>\n        <!--DynamicComponent Cell-->\n        <fusion-dynamic-components\n            *ngIf=\"tableService.isTypeComponent(column)\"\n            [configuration]=\"customCellData\"\n        >\n        </fusion-dynamic-components>\n        <!--Currency Cell-->\n        <div\n            *ngIf=\"tableService.isTypeCurrency(column)\"\n            class=\"truncate centerVertical\"\n            [ngClass]=\"column.align || 'right'\"\n            [style.width]=\"innerElementWidth\"\n            [fusionTooltip]=\"$any(data) | currency: 'USD'\"\n        >\n            {{\n                !isNull(data)\n                    ? ($any(data)\n                      | currency\n                          : column?.currencyPipeParameters?.currencyCode || undefined\n                          : column?.currencyPipeParameters?.display || (column?.currencyPipeParameters ? undefined : '$ ')\n                          : column?.currencyPipeParameters?.digitsInfo || undefined)\n                    : (data | notAvailable: notAvailableText)\n            }}\n        </div>\n        <!--Number Cell-->\n        <div\n            *ngIf=\"tableService.isTypeNumber(column)\"\n            class=\"truncate centerVertical\"\n            [ngClass]=\"column.align || 'right'\"\n            [style.width]=\"innerElementWidth\"\n            [fusionTooltip]=\"$any(data) | number: column.pipeOptions\"\n        >\n            {{ !isNull(data) ? ($any(data) | number: column.pipeOptions) : (data | notAvailable: notAvailableText) }}\n        </div>\n        <!--Percent Cell-->\n        <div\n            *ngIf=\"tableService.isTypePercent(column)\"\n            class=\"truncate centerVertical\"\n            [ngClass]=\"column.align || 'right'\"\n            [style.width]=\"innerElementWidth\"\n            fusionTooltip=\"{{ $any(data) | number: column.pipeOptions }} %\"\n        >\n            {{ !isNull(data) ? ($any(data) | number: column.pipeOptions) : (data | notAvailable: notAvailableText) }}\n            {{ !isNullOrUndefined(data) ? '%' : null }}\n        </div>\n        <!--Date Cell-->\n        <div *ngIf=\"tableService.isTypeDate(column)\" class=\"truncate centerVertical\">\n            {{\n                data\n                    ? isAsDate(data)\n                        ? ($any(data) | date: getDateFormat(column.dateFormat):getDateUTCFormat(column.ignoreTimeZone))\n                        : data\n                    : !isRowTotal\n                    ? 'No ' + column.title\n                    : ''\n            }}\n        </div>\n    </ng-template>\n\n    <!--Row utility Cell icons and buttons-->\n    <ng-container *ngIf=\"!isRowTotal\">\n        <fusion-icon\n            *ngIf=\"isRemove && !isReadOnly\"\n            class=\"removeRowIcon\"\n            [name]=\"getRemoveIconName()\"\n            (click)=\"remove.emit()\"\n            [fusionTooltip]=\"getRemoveIconTooltipText()\"\n            [tooltipWidth]=\"getRemoveIconTooltipWidth()\"\n        ></fusion-icon>\n\n        <fusion-icon *ngIf=\"infoIconTooltip\" class=\"infoRowIcon\" name=\"info-tooltip\" [fusionTooltip]=\"infoIconTooltip\"></fusion-icon>\n\n    </ng-container>\n", styles: [":host-context(.v1){font-size:13px;font-family:var(--regular-font-family, \"Open Sans\");font-weight:400}:host-context(tr.is-with-totals){font-size:12px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:700}:host-context(.v2){font-size:12px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:400}:host .truncate{width:100%;display:inline-block;white-space:nowrap;overflow:hidden!important;text-overflow:ellipsis}:host.is-inline-removable fusion-icon.delete{margin-top:0!important;position:absolute;top:50%;transform:translateY(-50%)}:host{position:relative;padding:0 10px;color:var(--dark-color-300, #172D4C);word-break:break-all;max-width:350px;border-top:1px solid var(--light-color, #E1E6EB);border-bottom:1px solid var(--light-color, #E1E6EB)}:host:first-child{border-left:none}:host:last-child{border-right:none}:host fusion-icon{display:block;padding-top:5px;padding-left:5px}:host.cell-borders{border:1px solid var(--light-color, #E1E6EB)}:host.is-inline-removable fusion-icon.close{visibility:hidden;position:absolute;right:25px;top:6px;cursor:pointer}:host.is-inline-removable fusion-icon.close:hover ::ng-deep svg *{fill:var(--primary-color, #3091F6)}:host.is-inline-removable fusion-icon.close ::ng-deep svg{width:8px;height:8px}:host.is-inline-removable fusion-icon.close ::ng-deep svg *{fill:var(--light-color-800, #678099)}:host.is-inline-removable fusion-icon.delete{visibility:hidden;right:8px;cursor:pointer;top:calc(50% - 2px)}:host.is-inline-removable fusion-icon.delete ::ng-deep svg{width:13px;height:13px}:host.is-inline-removable fusion-icon.delete ::ng-deep svg *{fill:var(--light-color-900, #52677B)}:host.is-inline-removable:hover fusion-icon.delete ::ng-deep svg{width:13px;height:13px}:host.is-inline-removable:hover fusion-icon.delete ::ng-deep svg *{fill:var(--primary-color, #3091F6)}:host fusion-icon.info-tooltip{visibility:hidden;position:absolute;right:25px;top:8px}:host fusion-icon.info-tooltip ::ng-deep svg{width:11px;height:11px}:host fusion-icon.info-tooltip ::ng-deep svg *{fill:var(--light-color-800, #678099)}:host .is-ellipsis-rows-2{overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}:host.is-editable{padding:0}:host.is-editable fusion-input-inline{display:block;padding:0 10px}:host>div{vertical-align:middle}:host>div.right{text-align:right;float:none}:host>div.center{text-align:center}:host>div.checkbox-cell{margin:0 auto;text-align:center}:host .loader-holder{position:relative;top:2px;width:20px}:host-context(.v1){height:55px}:host-context(.v2){height:43px}:host-context(tr:hover).is-inline-removable fusion-icon.removeRowIcon{visibility:visible}:host-context(tr:hover) fusion-icon.infoRowIcon{visibility:visible}:host-context(tr.is-row-in-request) fusion-toggle{opacity:.5}:host-context(tr.is-with-totals){height:25px;letter-spacing:.5px;background-color:var(--light-color-100, #F9FAFB);border:none;border-bottom:solid 1px var(--light-color-700, #95A6B8)}\n"] }]
    }], () => [{ type: i1.TableService }, { type: undefined, decorators: [{
                type: Optional
            }, {
                type: Inject,
                args: [TABLE_OPTIONS_TOKEN]
            }] }, { type: i2.LogService }], { data: [{
            type: Input
        }], column: [{
            type: Input
        }], row: [{
            type: Input
        }], options: [{
            type: Input
        }], position: [{
            type: Input
        }], infoIconTooltip: [{
            type: Input
        }], isRemove: [{
            type: Input
        }], isRowSelected: [{
            type: Input
        }], isLastColumn: [{
            type: Input
        }], customClass: [{
            type: Input
        }], isReadOnly: [{
            type: Input
        }], selectedChange: [{
            type: Output
        }], dataChange: [{
            type: Output
        }], remove: [{
            type: Output
        }], inlineInputEdit: [{
            type: ViewChild,
            args: ['inlineInput']
        }], cellBorders: [{
            type: HostBinding,
            args: ['class.cell-borders']
        }], isInlineRemovable: [{
            type: HostBinding,
            args: ['class.is-inline-removable']
        }], isCellEditable: [{
            type: HostBinding,
            args: ['class.is-editable']
        }], sticky: [{
            type: HostBinding,
            args: ['class.sticky-left']
        }], stickyLeft: [{
            type: HostBinding,
            args: ['style.left']
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(TableCellComponent, { className: "TableCellComponent", filePath: "components/table-cell/table-cell.component.ts", lineNumber: 48 }); })();
//# sourceMappingURL=data:application/json;base64, 