"use client"

import { TextField, FormHelperText, Box } from '@mui/material'

type Props = {
  label: string
  type?: string
  value: string
  onChange: (v: string) => void
  placeholder?: string
  required?: boolean
  min?: number
  max?: number
  step?: number
  disabled?: boolean
  error?: string
}

export default function FormField({
  label,
  type = 'text',
  value,
  onChange,
  placeholder,
  required,
  min,
  max,
  step,
  disabled,
  error
}: Props) {
  return (
    <Box sx={{ mb: 2 }}>
      <TextField
        fullWidth
        label={label}
        type={type}
        value={value}
        onChange={(e) => onChange(e.target.value)}
        placeholder={type === 'date' ? undefined : placeholder}
        required={required}
        disabled={disabled}
        error={!!error}
        variant="outlined"
        inputProps={{
          min,
          max,
          step,
        }}
        InputLabelProps={type === 'date' ? { shrink: true } : undefined}
        helperText={error}
      />
    </Box>
  )
}
