/** * Shared utilities for flatpickr-based date/time picker components. * Extracts common patterns used across datepicker, daterangepicker, and timepicker. */ import type { Instance } from 'flatpickr/dist/types/instance'; /** * Creates a debounced version of a function that delays execution until * after `wait` milliseconds have elapsed since the last call. */ export declare function debounce unknown>(func: T, wait: number): (...args: Parameters) => void; /** * Generates a random ID with a given prefix. * Used for creating unique IDs for inputs and their associated elements. */ export declare function generateRandomId(prefix: string): string; /** * Parses a date string in Y-m-d format, validating month/day ranges * and rejecting rollover dates (e.g., 2024-02-31 becoming Mar 2). */ export declare function parseDateOnly(dateStr: string): Date | null; /** * Parses a datetime string in Y-m-d H:i or Y-m-d H:i:s format. */ export declare function parseDateTime(dateStr: string): Date | null; /** * Parses a time string (e.g., "14:30", "2:30 PM", "02:30:45") into a Date * object anchored to today. */ export declare function parseTimeString(time: string | number | Date): Date | null; /** * Normalizes a value to a Date object. * Handles Date objects, timestamps, and strings. */ export declare function normalizeToDate(value: string | number | Date | '' | null | undefined, parseDateString?: (str: string) => Date | null): Date | null; /** * Type guard that checks if a value is a valid Date object. * Returns true only if the value is a Date instance with a valid time value. */ export declare function isValidDate(value: unknown): value is Date; /** * Filters an array to only include valid Date objects. * Useful for defensive handling of flatpickr callbacks which may occasionally * pass non-Date values during certain interactions (e.g., time input changes). */ export declare function filterValidDates(dates: unknown[]): Date[]; /** * Checks if a value is empty (null, undefined, empty string, or empty array). */ export declare function isEmptyValue(value: unknown): value is null | undefined | '' | []; /** * Checks if two Date objects represent the same time (hours, minutes, seconds). */ export declare function timesEqual(a: Date | null | undefined, b: Date | null | undefined): boolean; /** * Checks if two Date objects represent the same date (year, month, day). */ export declare function datesEqual(a: Date | null | undefined, b: Date | null | undefined): boolean; /** * Cleans up a flatpickr instance, removing event handlers and destroying it. */ export declare function cleanupFlatpickrInstance(instance: Instance | undefined): void; /** * Type for anchor click handlers stored on flatpickr instance. */ export type AnchorClickHandler = { el: HTMLElement; fn: EventListener; }; /** * Updates the form value for a picker component. */ export declare function updateFormValue(internals: ElementInternals | undefined, inputEl: HTMLInputElement | null): void; /** * Creates a submit listener for form validation. */ export declare function createFormSubmitListener(validateFn: (interacted: boolean, report: boolean) => void, checkValidityFn: () => boolean, requiredCheck: () => boolean): (e: SubmitEvent) => void; export interface ValidationResult { isValid: boolean; validity: ValidityState; validationMessage: string; } export interface ValidationOptions { inputEl: HTMLInputElement; required: boolean; isEmpty: boolean; invalidText: string; defaultErrorMessage: string; hasInteracted: boolean; customValidation?: () => { valid: boolean; message?: string; }; } /** * Performs validation for a picker input. * Returns validation state without modifying component state. */ export declare function validatePickerInput(options: ValidationOptions): ValidationResult; /** * Merges default text strings with custom overrides. */ export declare function mergeTextStrings>(defaults: T, custom?: Partial): T; /** Delay before re-initializing flatpickr after config changes (ms) */ export declare const CONFIG_DEBOUNCE_DELAY = 100; /** Delay before re-initializing flatpickr after window resize (ms) */ export declare const RESIZE_DEBOUNCE_DELAY = 250; /** Interval for checking if a hidden picker becomes visible (ms) */ export declare const VISIBILITY_CHECK_INTERVAL = 250; //# sourceMappingURL=utils.d.ts.map