import { Notice } from "@wordpress/components";
import { __ } from "@wordpress/i18n";


/**
 * Display validation errors in a dismissible Notice.
 */
export default function ValidationErrors({ errors, onDismiss }) {
    if (!errors || errors.length === 0) {
        return null;
    }

    return (
        <Notice
            status="error"
            isDismissible={!!onDismiss}
            onRemove={onDismiss}
            className="eci-validation-errors"
        >
            <strong>{__("Validation errors:", "cache-autopilot")}</strong>
            <ul className="eci-validation-errors__list">
                {errors.map((err, i) => (
                    <li key={i}>{err}</li>
                ))}
            </ul>
        </Notice>
    );
}
