import { Pipe, PipeTransform } from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';
import * as moment from 'moment';
import { DATE_FORMAT } from '../helpers';
import { DayChangeModel } from './../models-legacy';
@Pipe({
    name: 'dayChange',
})
export class DayChangePipe implements PipeTransform {
    constructor(private translate: TranslatePipe) {}

    transform(model?: DayChangeModel, date?: string | Date): string {
        const $day = this.translate.transform('SHARED.DAY');

        switch (model?.value) {
            case -1:
            case 1: {
                return $day;
            }
            case 0:
            case undefined: {
                return '';
            }
        }

        return this.handleDate(date);
    }

    private handleDate(date?: string | Date) {
        if (!date) {
            return '';
        }

        return moment.parseZone(date).local(true).format(DATE_FORMAT)
    }
}
