<?php
/**
 * Template part for displaying the job field block
 *
 * @link        https://matadorjobs.com/
 *
 * @since       3.90
 *
 * @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
 */

$wrapper_attributes = get_block_wrapper_attributes();
$job_id             = isset( $attributes['postId'] ) ? $attributes['postId'] : $block->context['postId'];
$selected_field     = $attributes['selectedField'] ?? 'externalId';
$label              = ! empty( $attributes['displayLabel'] ) ? $attributes['displayLabel'] : '';

if ( 'externalId' === $selected_field ) {
	$selected_field = 'bullhorn_job_id';
}

$field_value = matador_get_the_job_meta( $selected_field, $job_id );

if ( empty( $field_value ) ) {
	return; // Prevent anything from being rendered on frontend if no meta value is set.
}
?>

<span <?php echo $wrapper_attributes; ?>>

	<?php if ( $label ) : ?>
		<span><?php echo wp_kses( $label, 'post' ); ?></span>
	<?php endif ?>

	<?php echo wp_kses( $field_value, 'post' ); ?>

</span>