{"version":3,"sources":["../src/use-chart-reference-line.ts"],"sourcesContent":["import type { CSSUIObject, RequiredPropGetter } from \"@yamada-ui/core\"\nimport type { Dict } from \"@yamada-ui/utils\"\nimport type * as Recharts from \"recharts\"\nimport type { ReferenceLineProps } from \"./chart.types\"\nimport { getCSS, getVar, useTheme } from \"@yamada-ui/core\"\nimport { cx, isObject } from \"@yamada-ui/utils\"\nimport { useCallback, useMemo } from \"react\"\nimport { getComponentProps } from \"./chart-utils\"\nimport { referenceLineProperties } from \"./rechart-properties\"\n\nexport interface UseChartReferenceLineOptions {\n  /**\n   * Reference lines that should be displayed on the chart.\n   */\n  referenceLineProps?: ReferenceLineProps[]\n}\n\ninterface UseChartReferenceLineProps extends UseChartReferenceLineOptions {\n  styles: Dict<CSSUIObject | undefined>\n}\n\nexport const useChartReferenceLine = ({\n  styles,\n  referenceLineProps = [],\n}: UseChartReferenceLineProps) => {\n  const { theme } = useTheme()\n  const styleClassName = getCSS(styles.referenceLine)(theme)\n  const propList = useMemo(\n    () =>\n      referenceLineProps.map((props, index) => {\n        const [{ label: labelProp, ...rest }, propClassName] =\n          getComponentProps(\n            [props, referenceLineProperties],\n            styleClassName,\n          )(theme)\n\n        const color = getVar(`reference-line-${index}`)(theme)\n        const label: Recharts.ReferenceLineProps[\"label\"] = {\n          fill: color,\n          position: \"insideBottomLeft\",\n          value: labelProp as string,\n          ...(isObject(labelProp) ? labelProp : {}),\n        }\n\n        return { color, label, propClassName, ...rest }\n      }),\n    [referenceLineProps, styleClassName, theme],\n  )\n\n  const getReferenceLineProps: RequiredPropGetter<\n    { index: number } & Partial<Recharts.ReferenceLineProps>,\n    Omit<Recharts.ReferenceLineProps, \"ref\">\n  > = useCallback(\n    ({ className, index, ...props }, ref = null) => {\n      const { color, label, propClassName, ...rest } = propList[index] ?? {}\n\n      return {\n        ref,\n        className: cx(className, propClassName),\n        label,\n        stroke: color,\n        ...(props as Recharts.ReferenceLineProps),\n        ...rest,\n      }\n    },\n    [propList],\n  )\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