import { LOCALE_ID, Inject, Injectable } from '@angular/core';
import { CalendarEventTitleFormatter, CalendarEvent } from 'angular-calendar';
import { DatePipe } from '@angular/common';
import { TrainingSession } from 'src/app/models/training-session.model';

@Injectable()
export class CustomEventTitleFormatter extends CalendarEventTitleFormatter {
  constructor(@Inject(LOCALE_ID) private locale: string) {
    super();
  }

  month(event: CalendarEvent): string {
    return `<b>${new DatePipe(this.locale).transform(
      event.start,
      'h:m a',
      this.locale
    )}</b> ${event.title}`;
  }

  week(event: CalendarEvent): string {
    return (`
      <span class="type">`
        + (event.meta.ts.training_workout_id ? '<i class="icon-dumbbell"></i>' : '') +
        `${event.title}
      </span>
      <span class="time">${new DatePipe(this.locale).transform(event.start, 'HH:mm')} - ${new DatePipe(this.locale).transform(event.end, 'HH:mm')}</span>
    `);
  }

  day(event: CalendarEvent): string {
    return (`
      <span class="type">`
        + (event.meta.ts.training_workout_id ? '<i class="icon-dumbbell"></i>' : '') +
        `${event.title}
      </span>
      <span class="time">${new DatePipe(this.locale).transform(event.start, 'HH:mm')} - ${new DatePipe(this.locale).transform(event.end, 'HH:mm')}</span>
    `);
  }

  dayTooltip(event: CalendarEvent): string {
    if(!event.meta.ts.training_type_id) return "Sin tipo";
    if(!event.meta.ts.training_workout_id && event.meta.ts.training_type.slug!="open") return "Sin workout";
    return;
  }

  weekTooltip(event): string {
    if(!event.meta.ts.training_type_id) return "Sin tipo";
    if(!event.meta.ts.training_workout_id && event.meta.ts.training_type.slug!="open") return "Sin workout";
    return;
  }
}