import {Component} from '@angular/core';
import {GridRendererComponent} from '../../grid-renderer-component';
import {AgGridComponentConst} from '../../../components/ag-grid-component-const';
import {isNull} from 'util';

@Component({
    selector: 'app-grid-text-renderer',
    templateUrl: './grid-text-renderer.component.html',
    styleUrls: ['./grid-text-renderer.component.scss']
})

export class GridTextRendererComponent extends GridRendererComponent {
    /**
     * Initialize cell renderer (gets called on cell rendering and after editing / refresh)
     * @param params
     */
    agInit(params: any): void {
        super.agInit(params);
        if (this.cellParams != undefined) {
            // Replace "." with "," for display purpose
            if (this.cellParams.type == AgGridComponentConst.CELL_VALUE_TYPE_FLOAT) {
                this.value = isNaN(this.value) || isNull(this.value) ? '' : this.value = parseFloat(parseFloat(this.value).toFixed(2)).toLocaleString('de-DE');
            }
            if (this.cellParams.type == AgGridComponentConst.CELL_VALUE_TYPE_INT) {
                this.value = isNaN(this.value) || isNull(this.value) ? '' : this.value = parseInt(parseInt(this.value).toFixed(2)).toLocaleString('de-DE');
            }
        }
    }
}
