{"version":3,"file":"RelativeTime.shared.cjs","names":["getFormatLocales"],"sources":["../../../src/components/variables/RelativeTime.shared.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { getFormatLocales } from '../../hooks/utils/getFormatLocales';\n\n// Pure compute logic shared by the hook-based and RSC implementations. This\n// module must stay free of hook/context imports so it can be reached from the\n// components-rsc entrypoint.\n\ntype RelativeTimeProps = {\n  date?: Date | null | undefined;\n  children?: Date | null | undefined;\n  name?: string;\n  value?: number;\n  unit?: Intl.RelativeTimeFormatUnit;\n  baseDate?: Date;\n  locales?: string[];\n  options?: Intl.RelativeTimeFormatOptions;\n  _locale?: string;\n  _enableI18n?: boolean;\n};\n\ntype ResolvedRelativeTimeProps = RelativeTimeProps & {\n  _locale: string;\n  _enableI18n: boolean;\n};\n\nfunction computeRelativeTime({\n  _enableI18n,\n  _locale,\n  date,\n  children,\n  value,\n  unit,\n  baseDate,\n  locales: localesProp = [],\n  options = {},\n}: ResolvedRelativeTimeProps): string | null {\n  const locales = getFormatLocales({\n    locale: _locale,\n    enableI18n: _enableI18n,\n    localesProp,\n  });\n  const gt = getI18nConfig().getGTClass();\n  const resolvedDate = date ?? children;\n\n  if (process.env.NODE_ENV === 'development' && value !== undefined && !unit) {\n    // eslint-disable-next-line no-console\n    console.warn(\n      '<RelativeTime>: `value` was provided without `unit`. The `value` prop will be ignored.'\n    );\n  }\n\n  if (value !== undefined && unit) {\n    return gt.formatRelativeTime(value, unit, {\n      locales,\n      numeric: options.numeric,\n      style: options.style,\n      localeMatcher: options.localeMatcher,\n    });\n  }\n\n  if (resolvedDate != null) {\n    return gt.formatRelativeTimeFromDate(resolvedDate, {\n      locales,\n      baseDate: baseDate ?? new Date(),\n      numeric: options.numeric,\n      style: options.style,\n      localeMatcher: options.localeMatcher,\n    });\n  }\n\n  return null;\n}\n\nexport { computeRelativeTime };\nexport type { RelativeTimeProps, ResolvedRelativeTimeProps };\n"],"mappings":"4IAyBA,SAAS,EAAoB,CAC3B,cACA,UACA,OACA,WACA,QACA,OACA,WACA,QAAS,EAAc,EAAE,CACzB,UAAU,EAAE,EAC+B,CAC3C,IAAM,EAAUA,EAAAA,iBAAiB,CAC/B,OAAQ,EACR,WAAY,EACZ,cACD,CAAC,CACI,GAAA,EAAA,EAAA,gBAAoB,CAAC,YAAY,CACjC,EAAe,GAAQ,EA4B7B,OA1BI,QAAQ,IAAI,WAAa,eAAiB,IAAU,IAAA,IAAa,CAAC,GAEpE,QAAQ,KACN,yFACD,CAGC,IAAU,IAAA,IAAa,EAClB,EAAG,mBAAmB,EAAO,EAAM,CACxC,UACA,QAAS,EAAQ,QACjB,MAAO,EAAQ,MACf,cAAe,EAAQ,cACxB,CAAC,CAGA,GAAgB,KAUb,KATE,EAAG,2BAA2B,EAAc,CACjD,UACA,SAAU,GAAY,IAAI,KAC1B,QAAS,EAAQ,QACjB,MAAO,EAAQ,MACf,cAAe,EAAQ,cACxB,CAAC"}