import { Component, Input } from '@angular/core';
import { Interval, isWithinInterval } from 'date-fns';
import { interval, map, startWith } from 'rxjs';

@Component({
    selector: 'dks-time-per-tour-kpi',
    templateUrl: './time-per-tour-kpi.component.html',
    styleUrls: ['./time-per-tour-kpi.component.css'],
    standalone: false
})
export class TimePerTourKPIComponent {
  @Input() text = '';
  @Input() kpis: {
    interval: Interval;
    kpi: {
      value: number;
      meta: {
        availableTime: number;
        tourAmount: number;
        breakEven: number;
      };
    };
  }[] = [];

  currentTimeSlot$ = interval(60000).pipe(
    startWith(0),
    map(() =>
      this.kpis.findIndex((kpi) =>
        isWithinInterval(new Date(), {
          start: new Date(kpi.interval.start),
          end: new Date(kpi.interval.end),
        })
      )
    )
  );
}
