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O;AACT;AAEA,SAAS,8CAAwB,KAAe;IAC9C,IAAI,iBAAiB,MACnB,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,cAAc,OACvB,OAAO;QACL,MAAM;QACN,OAAO;QACP,KAAK;QACL,MAAM;QACN,QAAQ;QACR,UAAU,MAAM,QAAQ;QACxB,cAAc;IAChB;SACK,IAAI,UAAU,SAAS,UAAU,OACtC,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,UAAU,OACnB,OAAO;QAAC,WAAW;IAAO;SAE1B,OAAO;QAAC,WAAW;IAAM;AAE7B;AAEA,SAAS,mCAAa,KAAW;IAC/B,IAAI,OAAO,CAAA,GAAA,kCAAI,EAAE,CAAA,GAAA,6CAAe;IAEhC,OAAO,CAAA,GAAA,+CAAiB,EAAE,MAAM;AAClC","sources":["packages/@adobe/react-spectrum/src/labeledvalue/LabeledValue.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 */\n\nimport {\n  CalendarDate,\n  CalendarDateTime,\n  getLocalTimeZone,\n  Time,\n  toCalendarDateTime,\n  today,\n  ZonedDateTime\n} from '@internationalized/date';\nimport {classNames} from '../utils/classNames';\nimport type {\n  DOMProps,\n  DOMRef,\n  RangeValue,\n  SpectrumLabelableProps,\n  StyleProps\n} from '@react-types/shared';\nimport {Field} from '../label/Field';\nimport {filterDOMProps} from 'react-aria/filterDOMProps';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport React, {ReactElement, ReactNode, useEffect} from 'react';\nimport {useDateFormatter} from 'react-aria/useDateFormatter';\nimport {useDOMRef} from '../utils/useDOMRef';\nimport {useListFormatter} from 'react-aria/useListFormatter';\nimport {useNumberFormatter} from 'react-aria/useNumberFormatter';\n\n// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.\n\nexport interface LabeledValueBaseProps\n  extends\n    DOMProps,\n    StyleProps,\n    Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>,\n    DOMProps {\n  /** The content to display as the label. */\n  label: ReactNode;\n}\n\ntype NumberValue = number | RangeValue<number>;\ninterface NumberProps<T extends NumberValue> {\n  /** The value to display. */\n  value: T;\n  /** Formatting options for the value. */\n  formatOptions?: Intl.NumberFormatOptions;\n}\n\nexport type DateTime = Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time;\ntype RangeDateTime = RangeValue<DateTime>;\ntype DateTimeValue = DateTime | RangeDateTime;\ninterface DateProps<T extends DateTimeValue> {\n  /** The value to display. */\n  value: T;\n  /** Formatting options for the value. */\n  formatOptions?: Intl.DateTimeFormatOptions;\n}\n\ninterface StringProps<T extends string> {\n  /** The value to display. */\n  value: T;\n  /** Formatting options for the value. */\n  formatOptions?: never;\n}\n\ninterface StringListProps<T extends string[]> {\n  /** The value to display. */\n  value: T;\n  /** Formatting options for the value. */\n  formatOptions?: Intl.ListFormatOptions;\n}\n\ninterface ReactElementProps<T extends ReactElement> {\n  /** The value to display. */\n  value: T;\n  /** Formatting options for the value. */\n  formatOptions?: never;\n}\n\ntype LabeledValueProps<T> = T extends NumberValue\n  ? NumberProps<T>\n  : T extends DateTimeValue\n    ? DateProps<T>\n    : T extends string[]\n      ? StringListProps<T>\n      : T extends string\n        ? StringProps<T>\n        : T extends ReactElement\n          ? ReactElementProps<T>\n          : never;\n\ntype SpectrumLabeledValueTypes =\n  | string[]\n  | string\n  | Date\n  | CalendarDate\n  | CalendarDateTime\n  | ZonedDateTime\n  | Time\n  | number\n  | RangeValue<number>\n  | RangeValue<DateTime>\n  | ReactElement;\nexport type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;\n\n/**\n * A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and\n * lists according to the user's locale.\n */\nexport const LabeledValue = React.forwardRef(function LabeledValue<\n  T extends SpectrumLabeledValueTypes\n>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {\n  let {value, formatOptions} = props;\n  let domRef = useDOMRef(ref);\n\n  useEffect(() => {\n    if (\n      domRef?.current &&\n      domRef.current.querySelectorAll('input, [contenteditable], textarea').length > 0\n    ) {\n      throw new Error('LabeledValue cannot contain an editable value.');\n    }\n  }, [domRef]);\n\n  let children;\n  if (Array.isArray(value)) {\n    children = (\n      <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />\n    );\n  }\n\n  if (\n    typeof value === 'object' &&\n    'start' in value &&\n    typeof value.start === 'number' &&\n    typeof value.end === 'number'\n  ) {\n    children = (\n      <FormattedNumber\n        value={value as NumberValue}\n        formatOptions={formatOptions as Intl.NumberFormatOptions}\n      />\n    );\n  }\n\n  if (\n    typeof value === 'object' &&\n    'start' in value &&\n    typeof value.start !== 'number' &&\n    typeof value.end !== 'number'\n  ) {\n    children = (\n      <FormattedDate\n        value={value as DateTimeValue}\n        formatOptions={formatOptions as Intl.DateTimeFormatOptions}\n      />\n    );\n  }\n\n  if (typeof value === 'number') {\n    children = (\n      <FormattedNumber value={value} formatOptions={formatOptions as Intl.NumberFormatOptions} />\n    );\n  }\n\n  if (\n    (typeof value === 'object' && ('calendar' in value || 'hour' in value)) ||\n    value instanceof Date\n  ) {\n    children = (\n      <FormattedDate value={value} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />\n    );\n  }\n\n  if (typeof value === 'string') {\n    children = value;\n  }\n\n  if (React.isValidElement(value)) {\n    children = value;\n  }\n\n  return (\n    <Field\n      {...(props as any)}\n      wrapperProps={filterDOMProps(props as any)}\n      ref={domRef}\n      elementType=\"span\"\n      wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>\n      <span>{children}</span>\n    </Field>\n  );\n});\n\nfunction FormattedStringList<T extends string[]>(props: StringListProps<T>) {\n  let stringFormatter = useListFormatter(props.formatOptions);\n\n  return <>{stringFormatter.format(props.value)}</>;\n}\n\nfunction FormattedNumber<T extends NumberValue>(props: NumberProps<T>) {\n  let numberFormatter = useNumberFormatter(props.formatOptions);\n  let value = props.value;\n\n  if (typeof value === 'object') {\n    return <>{numberFormatter.formatRange(value.start, value.end)}</>;\n  }\n\n  return <>{numberFormatter.format(value)}</>;\n}\n\nfunction FormattedDate<T extends DateTimeValue>(props: DateProps<T>) {\n  let {value, formatOptions} = props;\n  if (!formatOptions) {\n    formatOptions = getDefaultFormatOptions('start' in value ? value.start : value);\n  }\n\n  let dateFormatter = useDateFormatter(formatOptions);\n  let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone();\n  let final: Date;\n\n  if ('start' in value && 'end' in value) {\n    let start = value.start;\n    let end = value.end;\n\n    start = convertDateTime(start, timeZone);\n    end = convertDateTime(end, timeZone);\n\n    return <>{dateFormatter.formatRange(start, end)}</>;\n  }\n\n  final = convertDateTime(value, timeZone);\n  return <>{dateFormatter.format(final)}</>;\n}\n\nfunction convertDateTime(value: DateTime, timeZone: any) {\n  if ('timeZone' in value) {\n    return value.toDate();\n  } else if ('calendar' in value) {\n    return value.toDate(timeZone);\n  } else if (!(value instanceof Date)) {\n    return convertValue(value).toDate(timeZone);\n  }\n\n  return value;\n}\n\nfunction getDefaultFormatOptions(value: DateTime): Intl.DateTimeFormatOptions {\n  if (value instanceof Date) {\n    return {dateStyle: 'long', timeStyle: 'short'};\n  } else if ('timeZone' in value) {\n    return {\n      year: 'numeric',\n      month: 'long',\n      day: 'numeric',\n      hour: 'numeric',\n      minute: 'numeric',\n      timeZone: value.timeZone,\n      timeZoneName: 'short'\n    };\n  } else if ('hour' in value && 'year' in value) {\n    return {dateStyle: 'long', timeStyle: 'short'};\n  } else if ('hour' in value) {\n    return {timeStyle: 'short'};\n  } else {\n    return {dateStyle: 'long'};\n  }\n}\n\nfunction convertValue(value: Time) {\n  let date = today(getLocalTimeZone());\n\n  return toCalendarDateTime(date, value);\n}\n"],"names":[],"version":3,"file":"LabeledValue.cjs.map"}