import {ICellRendererAngularComp} from 'ag-grid-angular';
import {Component} from '@angular/core';
import {ICellRendererParams} from 'ag-grid-community';
import * as moment from 'moment';

@Component({
    selector: 'editor-datetime-renderer',
    template: `{{ display }}`,
})
export class DatetimeRendererComponent implements ICellRendererAngularComp {
    public params: ICellRendererParams;
    public format = 'YYYY-MM-DD h:mm a';

    agInit(params: ICellRendererParams): void {
        this.params = params;
        // @ts-ignore
        this.format = params.colDef.additionalData.format;
    }

    public get display() {
        if ( !this.params.value ) {
            return '';
        }
        return moment(this.params.value).format(this.format);
    }

    refresh(params: any): boolean {
        return false;
    }
}
