import { TextField } from '@mui/material'
import type { SxProps, Theme } from '@mui/material'

interface TextInputProps {
  label: string
  value: string
  onChange: (value: string) => void
  error?: string
  helperText?: string
  placeholder?: string
  required?: boolean
  disabled?: boolean
  multiline?: boolean
  rows?: number
  size?: 'small' | 'medium'
  fullWidth?: boolean
  sx?: SxProps<Theme>
}

export function TextInput({
  label,
  value,
  onChange,
  error,
  helperText,
  placeholder,
  required,
  disabled,
  multiline,
  rows,
  size = 'small',
  fullWidth = true,
  sx,
}: TextInputProps) {
  return (
    <TextField
      label={label}
      value={value}
      onChange={e => onChange(e.target.value)}
      error={!!error}
      helperText={error ?? helperText}
      placeholder={placeholder}
      required={required}
      disabled={disabled}
      multiline={multiline}
      rows={rows}
      size={size}
      fullWidth={fullWidth}
      sx={sx}
    />
  )
}
