import { cva, type VariantProps } from 'class-variance-authority'
import * as React from 'react'

import { cn } from '@lib/utils'

const textareaVariants = cva(
  'border-input placeholder:text-muted-foreground aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none disabled:cursor-not-allowed disabled:opacity-50',
  {
    variants: {
      variant: {
        default: 'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',
        simple: '',
      },
    },
    defaultVariants: {
      variant: 'default',
    },
  },
)

type TextareaProps = React.ComponentProps<'textarea'> &
  VariantProps<typeof textareaVariants> & {
    /**
     * E2E test_id to identify the input.
     */
    __e2e_test_id__?: string
  }

function Textarea({ className, variant, __e2e_test_id__, ...props }: TextareaProps) {
  return (
    <textarea
      data-slot="textarea"
      className={cn(textareaVariants({ variant, className }))}
      {...props}
      data-test-id={__e2e_test_id__}
    />
  )
}

export { Textarea }
