import AreaChart, {
  type Props as RawProps,
} from '$src/lib/visualizations/raw/charts/AreaChart'
import { type QueryRequestProps } from '$src/data'
import useQuery from '$src/lib/internal/shared/useQuery'

type Props = Omit<RawProps, 'data' | 'isLodaing' | 'error' | 'download'> &
  QueryRequestProps & {
    download?: boolean
  }

function QueryAreaChart({
  queryPath,
  params,
  download = false,
  tanstaskQueryOptions,
  ...rest
}: Props) {
  const {
    data,
    isLoading,
    error,
    download: downloadFn,
  } = useQuery({ queryPath, params, tanstaskQueryOptions })

  return (
    <AreaChart
      data={data}
      isLoading={isLoading}
      error={error}
      download={download ? downloadFn : undefined}
      {...rest}
    />
  )
}

export default QueryAreaChart
