'use strict';

require('../../../../../../@date-fns_tz@1.4.1/node_modules/@date-fns/tz/date/mini.cjs');
const toTimeZone = require('./toTimeZone.cjs');
const typeguards = require('./typeguards.cjs');

function toZoneNoon(date, timeZone, noonSafe) {
    return toTimeZone.toTimeZone(date, timeZone);
}
function convertMatcher(matcher, timeZone, noonSafe) {
    if (typeof matcher === "boolean" || typeof matcher === "function") {
        return matcher;
    }
    if (matcher instanceof Date) {
        return toZoneNoon(matcher, timeZone);
    }
    if (Array.isArray(matcher)) {
        return matcher.map((value) => value instanceof Date ? toZoneNoon(value, timeZone) : value);
    }
    if (typeguards.isDateRange(matcher)) {
        return {
            ...matcher,
            from: matcher.from ? toTimeZone.toTimeZone(matcher.from, timeZone) : matcher.from,
            to: matcher.to ? toTimeZone.toTimeZone(matcher.to, timeZone) : matcher.to,
        };
    }
    if (typeguards.isDateInterval(matcher)) {
        return {
            before: toZoneNoon(matcher.before, timeZone),
            after: toZoneNoon(matcher.after, timeZone),
        };
    }
    if (typeguards.isDateAfterType(matcher)) {
        return {
            after: toZoneNoon(matcher.after, timeZone),
        };
    }
    if (typeguards.isDateBeforeType(matcher)) {
        return {
            before: toZoneNoon(matcher.before, timeZone),
        };
    }
    return matcher;
}
/**
 * Convert any {@link Matcher} or array of matchers to the specified time zone.
 *
 * @param matchers - The matcher or matchers to convert.
 * @param timeZone - The target IANA time zone.
 * @returns The converted matcher(s).
 * @group Utilities
 */
function convertMatchersToTimeZone(matchers, timeZone, noonSafe) {
    if (!matchers) {
        return matchers;
    }
    if (Array.isArray(matchers)) {
        return matchers.map((matcher) => convertMatcher(matcher, timeZone));
    }
    return convertMatcher(matchers, timeZone);
}

exports.convertMatchersToTimeZone = convertMatchersToTimeZone;
