/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Shared constants and utilities for DateCalendar, DateRangeCalendar,
 * DatePicker, and DateRangePicker.
 */

/** Fallback year range for the month/year dropdown when no min/max is provided. */
export const DEFAULT_FROM_YEAR = new Date().getFullYear() - 10;
export const DEFAULT_TO_YEAR = new Date().getFullYear() + 10;

/**
 * Builds the `disabled` matcher array for react-day-picker from optional
 * min/max date constraints. Dates before min or after max are disabled.
 */
export function buildDisabledMatchers(min, max) {
  const matchers = [];
  if (min != null) {
    matchers.push({
      before: min
    });
  }
  if (max != null) {
    matchers.push({
      after: max
    });
  }
  return matchers;
}

/**
 * Stable click handler that stops event propagation. Used on date inputs
 * inside Popover.Trigger to prevent the trigger's click handler from
 * toggling the popover closed when the user clicks the already-open input.
 */
export const stopPropagation = e => {
  e.stopPropagation();
  // Base UI chains its trigger handler after this click handler. When focus or
  // pointer-down already opened the popover, suppress that handler so the same
  // click does not immediately toggle the popover closed again.
  const preventBaseUIHandler = e.preventBaseUIHandler;
  preventBaseUIHandler?.();
};
//# sourceMappingURL=calendarShared.js.map