/**
 * 텍스트영역(Textarea) 필드 컴포넌트
 * 기존 ItemForm과 100% 동일한 디자인
 */

'use client';

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

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

  // properties에서 rows 추출
  const rows = field.properties?.rows as number | undefined;

  return (
    <div className="md:col-span-2">
      <Label htmlFor={fieldKey}>
        {field.field_name}
        {field.is_required && <span className="text-red-500"> *</span>}
      </Label>
      <Textarea
        id={fieldKey}
        placeholder={field.placeholder || `${field.field_name}을(를) 입력하세요`}
        value={stringValue}
        onChange={(e) => onChange(e.target.value)}
        disabled={disabled}
        rows={rows || 3}
        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>
  );
}
