import { Pipe, PipeTransform } from '@angular/core';

import { DateTimeFormat } from '../models/date-time-format';
import { DateTimeFormatterService } from '../services/date-time-formatter.service';

@Pipe({
  name: 'appDateTime',
  standalone: true,
  pure: true
})
export class AppDateTimePipe implements PipeTransform {
  constructor(private readonly dateTimeFormatter: DateTimeFormatterService) {}

  transform(
    value: string | number | Date | null | undefined,
    format?: DateTimeFormat,
    timeZone?: string,
    locale?: string,
    fallback?: string
  ): string {
    return this.dateTimeFormatter.format(value, {
      format,
      timeZone,
      locale,
      fallback
    });
  }
}
