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vC,YACE,cACA,gBAAgB,CAAA,GAAA,4CAAiB,EAAE,MAAM,YAAY,IAAI,MAAM,gBAAgB;YAInF,aAAa,OAAO,CAAC;QACvB;yBACA;QACA,WAAW;QACX,aAAY,MAAM,EAAE,YAAY;YAC9B,IAAI,CAAC,WACH,OAAO;YAGT,IAAI,gBAAgB,CAAA,GAAA,0CAAe,EAAE,cAAc;YACnD,IAAI,YAAY,IAAI,CAAA,GAAA,0CAAY,EAAE,QAAQ;YAC1C,OAAO,UAAU,MAAM,CAAC;QAC1B;QACA,kBAAiB,MAAM,EAAE,aAA+B;YACtD,IAAI,aAAa;gBAAC,GAAG,UAAU;gBAAE,GAAG,aAAa;YAAA;YACjD,IAAI,mBAAmB,CAAA,GAAA,0CAAe,EAAE,CAAC,GAAG;YAC5C,OAAO,IAAI,CAAA,GAAA,0CAAY,EAAE,QAAQ;QACnC;IACF;AACF","sources":["packages/react-stately/src/datepicker/useDatePickerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CalendarDate,\n DateFormatter,\n toCalendarDate,\n toCalendarDateTime\n} from '@internationalized/date';\nimport {DatePickerProps, DateValue, Granularity, MappedDateValue, TimeValue} from './types';\nimport {\n FieldOptions,\n FormatterOptions,\n getFormatOptions,\n getPlaceholderTime,\n getValidationResult,\n useDefaultProps\n} from './utils';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface DatePickerStateOptions<T extends DateValue> extends DatePickerProps<T> {\n /**\n * Determines whether the date picker popover should close automatically when a date is selected.\n *\n * @default true\n */\n shouldCloseOnSelect?: boolean | (() => boolean);\n}\n\nexport interface DatePickerState extends OverlayTriggerState, FormValidationState {\n /** The currently selected date. */\n value: DateValue | null;\n /** The default date. */\n defaultValue: DateValue | null;\n /** Sets the selected date. */\n setValue(value: DateValue | null): void;\n /**\n * The date portion of the value. This may be set prior to `value` if the user has\n * selected a date but has not yet selected a time.\n */\n dateValue: DateValue | null;\n /** Sets the date portion of the value. */\n setDateValue(value: DateValue): void;\n /**\n * The time portion of the value. This may be set prior to `value` if the user has\n * selected a time but has not yet selected a date.\n */\n timeValue: TimeValue | null;\n /** Sets the time portion of the value. */\n setTimeValue(value: TimeValue): void;\n /** The granularity for the field, based on the `granularity` prop and current value. */\n granularity: Granularity;\n /**\n * Whether the date picker supports selecting a time, according to the `granularity` prop and\n * current value.\n */\n hasTime: boolean;\n /** Whether the calendar popover is currently open. */\n isOpen: boolean;\n /** Sets whether the calendar popover is open. */\n setOpen(isOpen: boolean): void;\n /**\n * The current validation state of the date picker, based on the `validationState`, `minValue`,\n * and `maxValue` props.\n *\n * @deprecated Use `isInvalid` instead.\n */\n validationState: ValidationState | null;\n /** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */\n isInvalid: boolean;\n /** Formats the selected value using the given options. */\n formatValue(locale: string, fieldOptions: FieldOptions): string;\n /** Gets a formatter based on state's props. */\n getDateFormatter(locale: string, formatOptions: FormatterOptions): DateFormatter;\n}\n\n/**\n * Provides state management for a date picker component. A date picker combines a DateField and a\n * Calendar popover to allow users to enter or select a date and time value.\n */\nexport function useDatePickerState<T extends DateValue = DateValue>(\n props: DatePickerStateOptions<T>\n): DatePickerState {\n let overlayState = useOverlayTriggerState(props);\n let [value, setValue] = useControlledState<DateValue | null, MappedDateValue<T> | null>(\n props.value,\n props.defaultValue || null,\n props.onChange\n );\n let [initialValue] = useState(value);\n\n let v = value || props.placeholderValue || null;\n let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);\n let dateValue = value != null ? value.toDate(defaultTimeZone ?? 'UTC') : null;\n let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';\n let shouldCloseOnSelect = props.shouldCloseOnSelect ?? true;\n\n let [selectedDate, setSelectedDate] = useState<DateValue | null>(null);\n let [selectedTime, setSelectedTime] = useState<TimeValue | null>(null);\n\n if (value) {\n selectedDate = value;\n if ('hour' in value) {\n selectedTime = value;\n }\n }\n\n // props.granularity must actually exist in the value if one is provided.\n if (v && !(granularity in v)) {\n throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());\n }\n\n let showEra = value?.calendar.identifier === 'gregory' && value.era === 'BC';\n let formatOpts = useMemo(\n () => ({\n granularity,\n timeZone: defaultTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros,\n showEra\n }),\n [\n granularity,\n props.hourCycle,\n props.shouldForceLeadingZeros,\n defaultTimeZone,\n props.hideTimeZone,\n showEra\n ]\n );\n\n let {minValue, maxValue, isDateUnavailable} = props;\n let builtinValidation = useMemo(\n () => getValidationResult(value, minValue, maxValue, isDateUnavailable, formatOpts),\n [value, minValue, maxValue, isDateUnavailable, formatOpts]\n );\n\n let validation = useFormValidationState({\n ...props,\n value: value as MappedDateValue<T> | null,\n builtinValidation\n });\n\n let isValueInvalid = validation.displayValidation.isInvalid;\n let validationState: ValidationState | null =\n props.validationState || (isValueInvalid ? 'invalid' : null);\n\n let commitValue = (date: DateValue, time: TimeValue) => {\n setValue('timeZone' in time ? time.set(toCalendarDate(date)) : toCalendarDateTime(date, time));\n setSelectedDate(null);\n setSelectedTime(null);\n validation.commitValidation();\n };\n\n // Intercept setValue to make sure the Time section is not changed by date selection in Calendar\n let selectDate = (newValue: CalendarDate) => {\n let shouldClose =\n typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;\n if (hasTime) {\n if (selectedTime || shouldClose) {\n commitValue(\n newValue,\n selectedTime || getPlaceholderTime(props.defaultValue || props.placeholderValue)\n );\n } else {\n setSelectedDate(newValue);\n }\n } else {\n setValue(newValue);\n validation.commitValidation();\n }\n\n if (shouldClose) {\n overlayState.setOpen(false);\n }\n };\n\n let selectTime = (newValue: TimeValue) => {\n if (selectedDate && newValue) {\n commitValue(selectedDate, newValue);\n } else {\n setSelectedTime(newValue);\n }\n };\n\n return {\n ...validation,\n value,\n defaultValue: props.defaultValue ?? initialValue,\n setValue,\n dateValue: selectedDate,\n timeValue: selectedTime,\n setDateValue: selectDate,\n setTimeValue: selectTime,\n granularity,\n hasTime,\n ...overlayState,\n setOpen(isOpen) {\n // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.\n // If only the time was set and not the date, don't commit. The state will be preserved until\n // the user opens the popover again.\n if (!isOpen && !value && selectedDate && hasTime) {\n commitValue(\n selectedDate,\n selectedTime || getPlaceholderTime(props.defaultValue || props.placeholderValue)\n );\n }\n\n overlayState.setOpen(isOpen);\n },\n validationState,\n isInvalid: isValueInvalid,\n formatValue(locale, fieldOptions) {\n if (!dateValue) {\n return '';\n }\n\n let formatOptions = getFormatOptions(fieldOptions, formatOpts);\n let formatter = new DateFormatter(locale, formatOptions);\n return formatter.format(dateValue);\n },\n getDateFormatter(locale, formatOptions: FormatterOptions) {\n let newOptions = {...formatOpts, ...formatOptions};\n let newFormatOptions = getFormatOptions({}, newOptions);\n return new DateFormatter(locale, newFormatOptions);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDatePickerState.cjs.map"}