import { CalendarDate } from '../../../helpers/calendar';
import stateBackgroundColorFormatter from '../../../helpers/formatter/state-formatter/state-background-color-formatter';
import { isBackgroundColorTokenType } from '../../../types/type-guard';
export var DateDirection;
(function (DateDirection) {
  DateDirection["PREVIOUS"] = "-1";
  DateDirection["NEXT"] = "1";
})(DateDirection || (DateDirection = {}));
/**
 * The function `getTimeIndex` calculates the index of a given time string based on a specified time unit.
 *
 * @param {string} timeString - A string representing a time in the format "HH:MM", where HH is the hour and MM is the minutes.
 * @param {number} [unit=15] - The `unit` parameter in the `getTimeIndex` function is used to specify
 * the interval in minutes for dividing the day. By default, it is set to 15 minutes, meaning that the
 * day will be divided into 15-minute intervals.
 * @returns {number} the index of the given time string based on the specified time unit.
 */
export function getTimeIndex(timeString, unit = 15) {
  const [hour, minutes] = timeString.split(':');
  return Math.round((Number(hour) * 60 + Number(minutes)) / unit);
}
/**
 * Returns a string that includes the event key for a calendar event slot.
 *
 * @param {string} eventKey - represents the key or identifier of a calendar event.
 * @returns {string} a string that is a concatenation of 'vega-calendar-event-slot-' and the eventKey parameter.
 */
export function getCalendarEventSlotName(eventKey) {
  return 'vega-calendar-event-slot-' + eventKey;
}
/**
 * Returns the closest workday to a given calendar date based on a specified direction.
 *
 * @param {Date} date - The starting date from which you want to find the closest workday.
 * @param {'-1' | '1'} [direction=1] - Determines whether to find the closest workday in the past or future. It can have two possible values:
 * @returns {CalendarDate} The closest workday to the input date
 */
export function getClosestWorkday(date, direction = DateDirection.NEXT) {
  const day = date.toDate().getDay();
  if (day === 0 || day === 6) {
    let nextWorkdayGap = day === 0 ? 1 : 2;
    if (direction === DateDirection.PREVIOUS) {
      nextWorkdayGap = day === 0 ? -2 : -1;
    }
    return CalendarDate.from(new Date(date.year, date.month - 1, date.date + nextWorkdayGap));
  }
  return date;
}
/**
 * Get event status background color.
 *
 * @param {Nullable<string | BackgroundColorsTokenType>} color the background color
 * @returns {string} background color style string
 */
export function getEventStatusBgColorStyle(color = 'bg-accent6-primary') {
  if (isBackgroundColorTokenType(color)) {
    return `.event-bg-color{${stateBackgroundColorFormatter.formatToken(color)}}`;
  }
  else {
    return `.event-bg-color{background-color:${color}}`;
  }
}
