import React from 'react';
import { Input, Form } from 'antd';
import type { TextAreaProps } from 'antd/es/input';
import type { FormItemProps } from 'antd/es/form';

const { TextArea } = Input;

interface FormTextareaProps extends Omit<TextAreaProps, 'name'> {
    /** Opcional quando o campo já está envolvido por Form.Item com name. */
    name?: string | (string | number)[];
    label?: string;
    required?: boolean;
    help?: string;
    /** Texto persistente abaixo do campo (ex.: guideline DLP). */
    extra?: React.ReactNode;
    rows?: number;
    showCount?: boolean;
    maxLength?: number;
    rules?: FormItemProps['rules'];
}

export default function FormTextarea({
    name,
    label,
    required = false,
    help,
    extra,
    rows = 4,
    showCount = false,
    maxLength,
    rules,
    ...textareaProps
}: FormTextareaProps) {
    const formRules = required
        ? [{ required: true, message: `${label || 'Campo'} é obrigatório` }, ...(rules || [])]
        : rules;

    return (
        <Form.Item name={name} label={label} rules={formRules} help={help} extra={extra}>
            <TextArea rows={rows} showCount={showCount} maxLength={maxLength} {...textareaProps} />
        </Form.Item>
    );
}
