<?php
/**
 * Template: Job Application 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 = [
	'labelsTextColor'       => '--matador-application-labels-text-color',
	'labelsBackgroundColor' => '--matador-application-labels-background-color',
	'labelsPadding'         => [
		'top'    => '--matador-application-labels-padding-top',
		'right'  => '--matador-application-labels-padding-right',
		'bottom' => '--matador-application-labels-padding-bottom',
		'left'   => '--matador-application-labels-padding-left',
	],
	'labelsMargin'          => [
		'top'    => '--matador-application-labels-margin-top',
		'right'  => '--matador-application-labels-margin-right',
		'bottom' => '--matador-application-labels-margin-bottom',
		'left'   => '--matador-application-labels-margin-left',
	],
	'labelsPosition'        => '--matador-application-labels-position',
	'inputsTextColor'       => '--matador-application-inputs-text-color',
	'inputsBackgroundColor' => '--matador-application-inputs-background-color',
	'inputsPadding'         => [
		'top'    => '--matador-application-inputs-padding-top',
		'right'  => '--matador-application-inputs-padding-right',
		'bottom' => '--matador-application-inputs-padding-bottom',
		'left'   => '--matador-application-inputs-padding-left',
	],
	'inputsMargin'          => [
		'top'    => '--matador-application-inputs-margin-top',
		'right'  => '--matador-application-inputs-margin-right',
		'bottom' => '--matador-application-inputs-margin-bottom',
		'left'   => '--matador-application-inputs-margin-left',
	],
	'inputsBorders'         => [
		'top'    => '--matador-application-inputs-borders-top',
		'right'  => '--matador-application-inputs-borders-right',
		'bottom' => '--matador-application-inputs-borders-bottom',
		'left'   => '--matador-application-inputs-borders-left',
		'style'  => '--matador-application-inputs-borders-style',
		'width'  => '--matador-application-inputs-borders-width',
		'color'  => '--matador-application-inputs-borders-color',
	],
	'inputsBorderRadius'    => '--matador-application-inputs-border-radius',
	'submitButtonTextColor'       => '--matador-application-submit-button-text-color',
	'submitButtonBackgroundColor' => '--matador-application-submit-button-background-color',
	'submitButtonPadding'         => [
		'top'    => '--matador-application-submit-button-padding-top',
		'right'  => '--matador-application-submit-button-padding-right',
		'bottom' => '--matador-application-submit-button-padding-bottom',
		'left'   => '--matador-application-submit-button-padding-left',
	],
	'submitButtonMargin'          => [
		'top'    => '--matador-application-submit-button-margin-top',
		'right'  => '--matador-application-submit-button-margin-right',
		'bottom' => '--matador-application-submit-button-margin-bottom',
		'left'   => '--matador-application-submit-button-margin-left',
	],
	'submitButtonBorders'         => [
		'top'    => '--matador-application-submit-button-borders-top',
		'right'  => '--matador-application-submit-button-borders-right',
		'bottom' => '--matador-application-submit-button-borders-bottom',
		'left'   => '--matador-application-submit-button-borders-left',
		'style'  => '--matador-application-submit-button-borders-style',
		'width'  => '--matador-application-submit-button-borders-width',
		'color'  => '--matador-application-submit-button-borders-color',
	],
	'submitButtonBorderRadius'    => '--matador-application-submit-button-border-radius',
];

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

$args = [];

if ( isset( $attributes['isFullWidthSubmitButton'] ) && $attributes['isFullWidthSubmitButton'] ) {
	$args['class'] = 'is-style-matador-full-width-submit-button';
}
?>
<div <?php echo get_block_wrapper_attributes( [ 'style' => $style ] ); ?>>
	<?php matador_the_application( $args ); ?>
</div>
