// Original: src/renderer/components/ellipsis/index.tsx
import { cn } from '@cherrystudio/ui/lib/utils'
import type { HTMLAttributes } from 'react'

type Props = {
  maxLine?: number
  className?: string
  ref?: React.Ref<HTMLDivElement>
} & HTMLAttributes<HTMLDivElement>

const Ellipsis = (props: Props) => {
  const { maxLine = 1, children, className, ref, ...rest } = props

  const ellipsisClasses = cn(
    'overflow-hidden text-ellipsis',
    maxLine > 1 ? `line-clamp-${maxLine} break-words` : 'block whitespace-nowrap',
    className
  )

  return (
    <div ref={ref} className={ellipsisClasses} {...rest}>
      {children}
    </div>
  )
}

export default Ellipsis
