{"version":3,"file":"NameTime.cjs","sources":["../../../../src/lib/Name/NameTime.tsx"],"sourcesContent":["import {forwardRef, useMemo} from 'react';\nimport classNames from 'classnames';\n\nimport type {DataAttributes, LibraryProps} from '@/internal/LibraryAPI';\nimport {useBrowserLocale} from '@/internal/locale';\nimport type {Locale} from '@/internal/locale';\n\nimport type {Styles, TimePeriods} from './types.ts';\nimport classes from './Name.module.css';\n\nexport type Props = DataAttributes &\n    LibraryProps & {\n        /**\n         * Provide a string with a BCP 47 language tag or an Intl.Locale instance,\n         * or an array of such locale identifiers. Defaults to user setting\n         * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#locales\n         */\n        locale?: Locale;\n        /**\n         * Select the formatting style to use.\n         * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#style\n         */\n        style?: keyof typeof Styles;\n        /**\n         * Define a time period name to localize\n         */\n        timePeriod: keyof typeof TimePeriods;\n    };\n\nexport const NameTime = forwardRef<HTMLDivElement, Props>(\n    ({className, locale: localeProp, timePeriod, style, ...nativeProps}, ref) => {\n        const userLocale = useBrowserLocale();\n        const locale = localeProp ? localeProp : userLocale;\n        const formattedValue = useMemo(\n            () => new Intl.DisplayNames(locale, {type: 'dateTimeField', style}).of(timePeriod),\n            [timePeriod, locale, style]\n        );\n\n        return (\n            <span {...nativeProps} className={classNames(classes.name, className)} ref={ref}>\n                {formattedValue}\n            </span>\n        );\n    }\n);\n\nNameTime.displayName = 'NameTime';\n"],"names":["NameTime","forwardRef","className","localeProp","timePeriod","style","nativeProps","ref","userLocale","useBrowserLocale","locale","formattedValue","useMemo","jsx","classNames","classes"],"mappings":"wQA6BaA,EAAWC,EAAAA,WACpB,CAAC,CAAC,UAAAC,EAAW,OAAQC,EAAY,WAAAC,EAAY,MAAAC,EAAO,GAAGC,CAAA,EAAcC,IAAQ,CACzE,MAAMC,EAAaC,EAAAA,iBAAA,EACbC,EAASP,GAA0BK,EACnCG,EAAiBC,EAAAA,QACnB,IAAM,IAAI,KAAK,aAAaF,EAAQ,CAAC,KAAM,gBAAiB,MAAAL,CAAA,CAAM,EAAE,GAAGD,CAAU,EACjF,CAACA,EAAYM,EAAQL,CAAK,CAAA,EAG9B,OACIQ,EAAAA,IAAC,OAAA,CAAM,GAAGP,EAAa,UAAWQ,EAAWC,UAAQ,KAAMb,CAAS,EAAG,IAAAK,EAClE,SAAAI,CAAA,CACL,CAER,CACJ,EAEAX,EAAS,YAAc"}