import type {
  ComponentPropsWithoutRef,
  ElementType,
  PropsWithChildren,
} from 'react'
import { cn } from '@/shared/lib/utils'
import type { VariantProps } from 'class-variance-authority'
import { typographyVariants } from './variants/typography'


type TypographyProps<T extends ElementType> = PropsWithChildren<
  ComponentPropsWithoutRef<T> & { as?: T }
> &
  VariantProps<typeof typographyVariants>

export function Typography<T extends ElementType = 'p'>(
  props: TypographyProps<T>
) {
  const { as: Component = 'p', variant, className, ...otherProps } = props
  return (
    <Component
      className={cn(typographyVariants({ variant, className }))}
      {...otherProps}
    />
  )
}