/**
 * 텍스트 입력 필드 컴포넌트
 * 기존 ItemForm과 100% 동일한 디자인
 */

'use client';

import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
import type { DynamicFieldRendererProps } from '../types';

export function TextField({
  field,
  value,
  onChange,
  error,
  disabled,
}: DynamicFieldRendererProps) {
  const fieldKey = field.field_key || `field_${field.id}`;
  const stringValue = value !== null && value !== undefined ? String(value) : '';

  return (
    <div>
      <Label htmlFor={fieldKey}>
        {field.field_name}
        {field.is_required && <span className="text-red-500"> *</span>}
      </Label>
      <Input
        id={fieldKey}
        type="text"
        placeholder={field.placeholder || `${field.field_name}을(를) 입력하세요`}
        value={stringValue}
        onChange={(e) => onChange(e.target.value)}
        disabled={disabled}
        className={error ? 'border-red-500' : ''}
      />
      {error && (
        <p className="text-xs text-red-500 mt-1">{error}</p>
      )}
      {!error && field.description && (
        <p className="text-xs text-muted-foreground mt-1">
          * {field.description}
        </p>
      )}
    </div>
  );
}
