<?php

namespace EDPW\Pro\Helpers;

use Valitron\Validator;

defined( 'ABSPATH' ) || exit;

class Validation {
	/**
	 * Validates the custom block's data.
	 *
	 * @param array $save_data The data to be validated.
	 *
	 * @return bool|array True if validation succeeds, or array of errors if validation fails.
	 */
	public static function validateCustomBlocks( $save_data ) {
		$validator = new Validator( $save_data );
		$validator->stopOnFirstFail( false );
		$fields     = [
			'title',
			//'title_content',
			//'block_id',
			'content',
			'category'
		];
		$this_field = __( 'This field', 'email-editor-plus' );
		$labels     = [];
		foreach ( $fields as $field ) {
			$labels[ $field ] = $this_field;
		}
		$validator->labels( $labels );
		$validator->rule( 'required', [
			'title',
			//'title_content',
			//'block_id',
			'content',
			'category'
		] )->message( __( '{field} is required', 'email-editor-plus' ) );

		return $validator->validate() ? true : $validator->errors();
	}
}