<?php
/**
 * Jobs Search Form ID Field Block
 *
 * @link        https://matadorjobs.com/
 *
 * @since       3.9.0
 *
 * @package     Matador Jobs
 * @subpackage  Blocks
 * @author      Matador Software LLC, Jeremy Scott, Paul Bearne
 * @copyright   (c) 2018-2020 Matador Software, LLC
 *
 * @license     https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
 */

use matador\MatadorJobs\Editors\Blocks\Blocks;

/**
 * @var array  $attributes - associative array of block attributes
 * @var WP_Block  $block - all the block settings and attributes
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}


$css_var_mappings = [
	'inputTextColor'                        => '--matador-search-id-input-text-color',
	'inputBackgroundColor'                  => '--matador-search-id-input-background-color',
	'inputPadding'                          => [
		'top'    => '--matador-search-id-input-padding-top',
		'bottom' => '--matador-search-id-input-padding-bottom',
		'left'   => '--matador-search-id-input-padding-left',
		'right'  => '--matador-search-id-input-padding-right',
	],
	'matador-jobs/searchFieldInputsPadding' => [
		'top'    => '--matador-search-input-padding-top',
		'bottom' => '--matador-search-input-padding-bottom',
		'left'   => '--matador-search-input-padding-left',
		'right'  => '--matador-search-input-padding-right',
	],
	'inputMargin'                           => [
		'top'    => '--matador-search-id-input-margin-top',
		'bottom' => '--matador-search-id-input-margin-bottom',
		'left'   => '--matador-search-id-input-margin-left',
		'right'  => '--matador-search-id-input-margin-top',
	],
	'matador-jobs/searchFieldInputsMargin'  => [
		'top'    => '--matador-search-input-margin-top',
		'bottom' => '--matador-search-input-margin-bottom',
		'left'   => '--matador-search-input-margin-left',
		'right'  => '--matador-search-input-margin-right',
	],
];

$style = Blocks::generate_css_variables( $css_var_mappings, $block );

?>

<div <?php echo get_block_wrapper_attributes( [ 'class' => 'matador-search-form-field-group matador-search-form-field-id', 'style' => $style ] ); ?>>

	<label for="matador_xid">
		<?php
		/**
		 * Filter: Matador Search From ID Field Label Text
		 *
		 * Modifies the text of the label for the ID Field
		 *
		 * @since 3.7.0
		 */
		$label = apply_filters( 'matador_search_form_id_field_label_text', esc_html( $attributes['label'] ) );

		/**
		 * Filter: Matador Search From ID Field Screen Reader Text
		 *
		 * Modifies the text of the screen reader text for the ID Field, which is ignored
		 * when a text label is present.
		 *
		 * @since 3.7.0
		 */
		$screen_reader_text = apply_filters(
			'matador_search_form_id_field_screen_reader_text',
			__( 'Job ID', 'matador-jobs' )
		);
		?>

		<?php if ( ! $label ) : ?>

			<span class="matador-screen-reader-text">
			<?php echo esc_html( $screen_reader_text ); ?>
		</span>

		<?php endif; ?>

		<?php echo esc_html( $label ); ?>

	</label>

	<?php
	/**
	 * Matador Search From ID Field Placeholder Text
	 *
	 * @wordpress-filter matador_search_form_id_field_placeholder
	 *
	 * Modifies the text of the placeholder text for the ID field input.
	 *
	 * @since 3.7.0
	 */

	$placeholder = apply_filters( 'matador_search_form_id_field_placeholder', esc_html( $attributes['placeholder'] ) );
	// $value = esc_attr( $_REQUEST['matador_xid'] ?? '' ); @todo matador-4
  // phpcs:ignore WordPress.Security.NonceVerification -- Nonce check.
	$value = isset( $_REQUEST['matador_xid'] ) ? esc_attr( $_REQUEST['matador_xid'] ) : '';

	?>

	<input type="text" id="matador_xid" name="matador_xid" value="<?php echo esc_attr( $value ); ?>"
		placeholder="<?php echo esc_attr( $placeholder ); ?>"/>

</div>
