<?php
/**
 * Template: Jobs Search Form Taxonomy 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-2025, Matador Software, LLC
 *
 * @license     https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
 */

use matador\MatadorJobs\Editors\Blocks\Blocks;

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

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

$chosen_taxonomy = $attributes['chosenTaxonomy'] ?? 'category';
$label           = $attributes['label'] ?? '';

$args = array(
	'taxonomy' => $chosen_taxonomy,
	'as'       => 'select',
	'method'   => 'value',
	'label'    => $label,
	'class'    => 'matador-search-form-field-group matador-search-form-field-' . $chosen_taxonomy,
);

/**
 * Filter: Matador Search From Taxonomy Field Args
 *
 * Modifies the args array passed to matador_taxonomy() from the Jobs Search Taxonomy Field template.
 *
 * @since 3.3.0
 */
$args = apply_filters( 'matador_search_from_taxonomy_field_args', $args );

$css_var_mappings = [
	'inputTextColor'                         => '--matador-search-taxonomy-input-text-color',
	'inputBackgroundColor'                   => '--matador-search-taxonomy-input-background-color',
	'inputPadding'                           => [
		'top'    => '--matador-search-taxonomy-input-padding-top',
		'bottom' => '--matador-search-taxonomy-input-padding-bottom',
		'left'   => '--matador-search-taxonomy-input-padding-left',
		'right'  => '--matador-search-taxonomy-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-taxonomy-input-margin-top',
		'bottom' => '--matador-search-taxonomy-input-margin-bottom',
		'left'   => '--matador-search-taxonomy-input-margin-left',
		'right'  => '--matador-search-taxonomy-input-margin-top',
	],
];

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

<div <?php echo get_block_wrapper_attributes( [ 'style' => $style ] ); ?>>
	<?php matador_taxonomy( $args ); ?>
</div>

