import {Component} from '@angular/core';
import {isNull, isUndefined} from 'util';
import {GridRendererComponent} from '../../grid-renderer-component';

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

export class GridDateRendererComponent extends GridRendererComponent {

    public displayedValue: string;

    /**
     * Initialize cell renderer (gets called on cell rendering and after editing / refresh)
     * @param params
     */
    agInit(params: any): void {
        super.agInit(params);
        let tempValue: string[] = [];
        if (isNull(this.value) || isUndefined(this.value)) {
            this.displayedValue = '';
        } else {
            tempValue = this.value.split('-');
            this.displayedValue = tempValue[2] + '.' + tempValue[1] + '.' + tempValue[0];
        }
    }
}
