import { Pipe, PipeTransform } from '@angular/core';
import { format } from 'date-fns';

@Pipe({
  name: 'customDate',
})
export class CustomDatePipe implements PipeTransform {
  transform(value: unknown, dateFormat: string = 'yyyy-MM-dd'): string {
    if (!value) {
      return '';
    }
    try {
      const date =
        typeof value === 'string' || typeof value === 'number'
          ? new Date(value)
          : value;
      return format(date as Date, dateFormat);
    } catch (error) {
      console.error('Error formatting date:', error);
      return '';
    }
  }
}
