<?php

/**
 * Text Field
 *
 * @package AmbassadorHub\CustomFields
 */

namespace AmbassadorHub\Fields\Fields;

use function esc_attr;

/**
 * Class representing a text custom field.
 */
final class TextArea extends AbstractField {

	/**
	 * Constructor.
	 *
	 * Initializes the text field with ID and label.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		$this->id    = 'textarea';
		$this->label = __( 'Text Area', 'ambassadorhub' );

		parent::__construct();
	}

	/**
	 * Sanitize a text area value.
	 *
	 * @param mixed $value The raw value to sanitize.
	 *
	 * @return string The sanitized text area value.
	 */
	public function sanitize_value( $value ) {
		return wp_kses_post( $value );
	}

	/**
	 * Render frontend input for text areas.
	 *
	 * @param array  $field         Field definition.
	 * @param string $id            HTML id attribute.
	 * @param string $name          HTML name attribute.
	 * @param string $value         Current value.
	 * @param string $placeholder   Placeholder text.
	 * @param string $required_attr Required attribute string.
	 * @param string $class_attr    CSS class attribute string.
	 *
	 * @return void
	 */
	public function render_field_input(
		array $field,
		string $id,
		string $name,
		string $value,
		string $placeholder,
		bool $required,
		string $class_attr
	): void {
		echo '<textarea'
			. ' id="' . esc_attr( $id ) . '"'
			. ' name="' . esc_attr( $name ) . '"'
			. ' class="' . esc_attr( $class_attr ) . '"'
			. ' placeholder="' . esc_attr( $placeholder ) . '"'
			. ( $required ? ' required' : '' )
			. '>';
		echo esc_html( $value );
		echo '</textarea>';
	}
}
