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

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

use matador\MatadorJobs\Editors\Blocks\Blocks;

/**
 * Defined before include:
 *
 * @var array  $attributes - associative array of block attributes
 * @var WP_Block  $block - all the block settings and attributes
 * @var string $content - the block inner HTML
 */

$css_var_mappings = [
	'labelsPosition'         => '--matador-search-labels-position',
	'labelsTextColor'        => '--matador-search-labels-text-color',
	'labelsBackgroundColor'  => '--matador-search-labels-background-color',
	'inputsBackgroundColor'  => '--matador-search-inputs-background-color',
	'inputsPlaceholderColor' => '--matador-search-inputs-placeholder-color',
	'inputsBorders'          => [
		'top'    => '--matador-search-inputs-borders-top',
		'right'  => '--matador-search-inputs-borders-right',
		'bottom' => '--matador-search-inputs-borders-bottom',
		'left'   => '--matador-search-inputs-borders-left',
		'style'  => '--matador-search-inputs-borders-style',
		'width'  => '--matador-search-inputs-borders-width',
		'color'  => '--matador-search-inputs-borders-color',
	],
	'inputsBorderRadius'     => '--matador-search-inputs-border-radius',
];

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

<?php
/**
 * Action: Matador Search From Before
 *
 * @wordpress-action matador_search_form_before
 *
 * Fires before the opening markup for the [matador_search] shortcode, matador_search() function and matador-jobs/jobs-search block.
 *
 * @since 3.0.0
 */
do_action( 'matador_search_form_before' );
?>

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

	<?php
	/**
	 * Action: Matador Search From Before Form
	 *
	 * Fires after opening markup and before the form for the [matador_search] shortcode and matador_search() function.
	 *
	 * @since 3.3.0
	 */
	do_action( 'matador_search_form_before_form' );
	?>

	<form role="search" method="get" class="matador-search-form" action="<?php echo esc_url( matador_get_the_jobs_link() ); ?>">

		<?php
		/**
		 * Action: Matador Search From Before Fields
		 *
		 * Fires before all fields inside the <form> tag of the [matador_search] shortcode and matador_search()
		 * function.
		 *
		 * @since 3.3.0
		 */
		do_action( 'matador_search_form_before_fields' );
		?>

		<?php echo $content ?>

	</form>

	<?php
	/**
	 * Action: Matador Search From After Form
	 *
	 * Fires before closing markup and after the form for the [matador_search] shortcode and matador_search() function.
	 *
	 * @since 3.3.0
	 */
	do_action( 'matador_search_form_after_form' );
	?>

</div>

<?php
/**
 * Action: Matador Search From After
 *
 * Fires after closing markup for the [matador_search] shortcode and matador_search() function.
 *
 * @since 3.0.0
 */
do_action( 'matador_search_form_after' );
?>
