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AS,uCAAiB,KAAK;IAC7B,IAAI,OAAO,WAAW,aACpB,OAAO;IAET,IAAI,aAAa,UAAU,UAAU,MAAM;IAC3C,IAAI,MAAM,UAAU,UAAU,KAAK;IACnC,IAAI,iBAAiB,UAAU,UAAU,KAAK;IAC9C,OAAO,KAAK,KAAK,CAAC,AAAC,CAAA,OAAO,UAAU,GAAG,iBAAiB,CAAA,IAAM,CAAA,aAAa,GAAE;AAC/E;AAEO,SAAS,0CAAmB,GAA8B;IAC/D,IAAI,SAAS,CAAA,GAAA,mBAAK,EAAsB;IACxC,CAAA,GAAA,gCAAkB,EAAE,KAAK,IAAO,CAAA;YAC9B,GAAG,CAAA,GAAA,sCAAW,EAAE,OAAO;YACvB;gBACE,CAAA,GAAA,yDAAiB,EAAE,QAAQ,UAAU,CAAC;oBAAC,UAAU;gBAAI;YACvD;QACF,CAAA;IACA,OAAO;AACT;AAEO,SAAS,0CAAsB,KAA6F;IACjI,IAAI,SAAS,CAAA,GAAA,sCAAQ,KAAK;IAC1B,IAAI,cAAc,IAAI;IACtB,IAAI,eAAe,MAAM,gBAAgB,CAAC,QAAQ;QAAC,yBAAyB;IAAI,GAAG,MAAM,CAAC;IAC1F,IAAI,kBAAmB,aAAa,MAAM;IAE1C,+CAA+C;IAC/C,8EAA8E;IAC9E,mFAAmF;IACnF,iEAAiE;IACjE,OAAQ,kBAAkB,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,kBAAkB,IAAI;AACtE","sources":["packages/@adobe/react-spectrum/src/datepicker/utils.tsx"],"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 */\nimport {createDOMRef} from '../utils/useDOMRef';\n\nimport {createFocusManager} from 'react-aria/private/focus/FocusScope';\nimport {DateFormatter} from '@internationalized/date';\nimport {FocusableRef} from '@react-types/shared';\nimport {FormatterOptions} from 'react-stately/private/datepicker/utils';\nimport React, {ReactNode, useImperativeHandle, useMemo, useRef, useState} from 'react';\nimport {SpectrumDatePickerBase} from './DatePicker';\nimport {useDateFormatter} from 'react-aria/useDateFormatter';\nimport {useDisplayNames} from 'react-aria/private/datepicker/useDisplayNames';\nimport {useLayoutEffect} from 'react-aria/private/utils/useLayoutEffect';\nimport {useLocale} from 'react-aria/I18nProvider';\nimport {useProvider} from '../provider/Provider';\n\nexport function useFormatHelpText(props: Pick<SpectrumDatePickerBase<any>, 'description' | 'showFormatHelpText'>): ReactNode {\n  let formatter = useDateFormatter({dateStyle: 'short'});\n  let displayNames = useDisplayNames();\n  return useMemo(() => {\n    if (props.description) {\n      return props.description;\n    }\n\n    if (props.showFormatHelpText) {\n      return (\n        formatter.formatToParts(new Date()).map((s, i) => {\n          if (s.type === 'literal' || s.type === 'unknown' || (s.type as string) === 'yearName') {\n            return <span key={i}>{` ${s.value} `}</span>;\n          }\n\n          let type = s.type as string === 'relatedYear' ? 'year' : s.type;\n          return <span key={i} style={{unicodeBidi: 'embed', direction: 'ltr'}}>{displayNames.of(type)}</span>;\n        })\n      );\n    }\n\n    return '';\n  }, [props.description, props.showFormatHelpText, formatter, displayNames]);\n}\n\nexport function useVisibleMonths(maxVisibleMonths: number): number {\n  let {scale} = useProvider()!;\n  let [visibleMonths, setVisibleMonths] = useState(getVisibleMonths(scale));\n  useLayoutEffect(() => {\n    let onResize = () => setVisibleMonths(getVisibleMonths(scale));\n    onResize();\n\n    window.addEventListener('resize', onResize);\n    return () => {\n      window.removeEventListener('resize', onResize);\n    };\n  }, [scale]);\n\n  return Math.max(1, Math.min(visibleMonths, maxVisibleMonths, 3));\n}\n\nfunction getVisibleMonths(scale) {\n  if (typeof window === 'undefined') {\n    return 1;\n  }\n  let monthWidth = scale === 'large' ? 336 : 280;\n  let gap = scale === 'large' ? 30 : 24;\n  let popoverPadding = scale === 'large' ? 32 : 48;\n  return Math.floor((window.innerWidth - popoverPadding * 2) / (monthWidth + gap));\n}\n\nexport function useFocusManagerRef(ref: FocusableRef<HTMLElement>): React.RefObject<HTMLElement | null> {\n  let domRef = useRef<HTMLElement | null>(null);\n  useImperativeHandle(ref, () => ({\n    ...createDOMRef(domRef),\n    focus() {\n      createFocusManager(domRef).focusFirst({tabbable: true});\n    }\n  }));\n  return domRef;\n}\n\nexport function useFormattedDateWidth(state: {getDateFormatter: (locale: string, formatOptions: FormatterOptions) => DateFormatter}): number {\n  let locale = useLocale()?.locale;\n  let currentDate = new Date();\n  let formatedDate = state.getDateFormatter(locale, {shouldForceLeadingZeros: true}).format(currentDate);\n  let totalCharacters =  formatedDate.length;\n\n  // The max of two is for times with only hours.\n  // As the length of a date grows we need to proportionally increase the width.\n  // We use the character count with 'ch' units and add extra padding to accomate for\n  // dates with months and time dashes, which are wider characters.\n  return (totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2));\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}