/**
 * 统一的 FormField 组件
 * 用于包装表单元素，提供标签、帮助文本和错误信息
 */
import React from "react";

export interface FormFieldProps {
  label?: string;
  required?: boolean;
  help?: string;
  error?: string;
  children: React.ReactNode;
  className?: string;
}

export const FormField: React.FC<FormFieldProps> = ({
  label,
  required = false,
  help,
  error,
  children,
  className = "",
}) => {
  return (
    <div className={className}>
      {label && (
        <label className="block text-sm font-medium text-slate-700 mb-2">
          {label}
          {required && <span className="text-red-400 ml-1">*</span>}
        </label>
      )}
      {children}
      {help && !error && (
        <p className="mt-1 text-xs text-slate-500">{help}</p>
      )}
      {error && (
        <p className="mt-1 text-xs text-red-400">{error}</p>
      )}
    </div>
  );
};

