export const USER_ROLE_OPTIONS = [
    { value: "admin", label: "Admin" },
    { value: "operator", label: "Operator" },
    { value: "viewer", label: "Viewer" }
];
export const EQUIPMENT_STATUS_OPTIONS = [
    { value: "active", label: "Aktywne" },
    { value: "service", label: "W serwisie" },
    { value: "retired", label: "Wyłączone" }
];
export const addDays = (date, days) => {
    const base = new Date(`${date}T12:00:00.000Z`);
    base.setUTCDate(base.getUTCDate() + days);
    return base.toISOString().slice(0, 10);
};
export const BOOKING_TIME_PATTERN = /^([01]\d|2[0-3]):[0-5]\d$/;
export const DEFAULT_BOOKING_START_TIME = "00:00";
export const DEFAULT_BOOKING_END_TIME = "23:59";
export const normalizeBookingTime = (value) => {
    if (!value || typeof value !== "string") {
        return null;
    }
    const trimmed = value.trim().slice(0, 5);
    return BOOKING_TIME_PATTERN.test(trimmed) ? trimmed : null;
};
const toUtcStamp = (date, time) => new Date(`${date}T${time}:00.000Z`).getTime();
export const getBookingStartStamp = (booking) => toUtcStamp(booking.startDate, normalizeBookingTime(booking.startTime) ?? DEFAULT_BOOKING_START_TIME);
export const getBookingEndStamp = (booking) => toUtcStamp(booking.endDate, normalizeBookingTime(booking.endTime) ?? DEFAULT_BOOKING_END_TIME);
export const bookingIntervalsOverlap = (left, right) => getBookingStartStamp(left) < getBookingEndStamp(right) && getBookingEndStamp(left) > getBookingStartStamp(right);
export const bookingConflictOnDay = (left, right, day) => {
    if (!bookingIntervalsOverlap(left, right)) {
        return false;
    }
    const dayStart = toUtcStamp(day, "00:00");
    const dayEnd = toUtcStamp(addDays(day, 1), "00:00");
    const overlapStart = Math.max(getBookingStartStamp(left), getBookingStartStamp(right), dayStart);
    const overlapEnd = Math.min(getBookingEndStamp(left), getBookingEndStamp(right), dayEnd);
    return overlapStart < overlapEnd;
};
export const enumerateDays = (from, to) => {
    const dates = [];
    let current = from;
    while (current <= to) {
        dates.push(current);
        current = addDays(current, 1);
    }
    return dates;
};
export const dayDiffInclusive = (from, to) => {
    const start = new Date(`${from}T12:00:00.000Z`).getTime();
    const end = new Date(`${to}T12:00:00.000Z`).getTime();
    return Math.floor((end - start) / 86_400_000) + 1;
};
export const roundCurrency = (value) => Math.round(value * 100) / 100;
export const calculateBookingTotalPrice = (startDate, endDate, dayRate) => {
    if (typeof dayRate !== "number" || !Number.isFinite(dayRate)) {
        return null;
    }
    return roundCurrency(dayDiffInclusive(startDate, endDate) * dayRate);
};
export const bookingHasManualTotalPrice = (booking) => {
    if (typeof booking.totalPrice !== "number" || !Number.isFinite(booking.totalPrice)) {
        return false;
    }
    const computedTotal = calculateBookingTotalPrice(booking.startDate, booking.endDate, booking.dayRate);
    if (computedTotal === null) {
        return true;
    }
    return Math.abs(booking.totalPrice - computedTotal) > 0.009;
};
