<?php
/**
 * Template Part : Select Jobs Field
 *
 * Template part to present a multi-select form field with a list of Matador jobs.
 *
 * Override this in your theme by copying it to /wp-content/themes/{yourtheme}/matador/form-fields/field-select-jobs.php.
 *
 * @link        https://matadorjobs.com/
 * @since       3.0.0
 *
 * @package     Matador Jobs
 * @subpackage  Templates/Form-Fields
 * @author      Matador Software LLC, Jeremy Scott, Paul Bearne
 * @copyright   (c) 2017-2021, 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.
}

/**
 * (Possibly) Defined before include:
 *
 * @var array  $args
 * @var string $type
 * @var string $name
 * @var string $label
 * @var string $sublabel
 * @var string $description
 * @var array  $options
 * @var array  $attributes
 * @var array  $class
 * @var mixed  $value
 * @var mixed  $default
 */ ?>

<div class="<?php matador_build_classes( $class ); ?>">

	<div class="matador-label">

		<?php if ( $label ) : ?>
			<h5 class="matador-field-label">
				<label for="<?php echo esc_attr( $name ); ?>">
					<?php echo esc_html( $label ); ?>
				</label>
			</h5>
		<?php endif; ?>

		<?php if ( $sublabel ) : ?>
			<h6 class="matador-field-sublabel">
				<?php echo esc_html( $sublabel ); ?>
			</h6>
		<?php endif; ?>

	</div>

	<div class="matador-field">

		<?php

		/**
		 * Matador Application Select Jobs Limit for Jobs to Show
		 *
		 * @wordpress-filter matador_application_select_jobs_limit
		 *
		 * @since 3.0.0
		 *
		 * @param int $limit Default 200
		 * @return int
		 */
		$limit = apply_filters( 'matador_application_select_jobs_limit', 200 );

		$args = array(
			'as'       => 'select',
			'selected' => isset( $selected ) ? $selected : null,
			// 'selected' => $selected ?? null, // @todo: matador-4
			'limit'    => $limit,
		);

		matador_get_jobs( $args );

		?>

	</div>

</div>
