<?php
/**
 *
 *
 * @var int    $form_id         Which form we are dealing with.
 * @var int    $field_id        Which field ID we are dealing with.
 * @var string $html_id         Which field html this field has.
 * @var array  $field           Which field object we are dealing with.
 * @var array  $entries         Which entries we are modifying.
 * @var array  $selected_fields Which fields were selected.
 * @var string $view            Which view are in.
 * @var string $placeholder     Place holder for this field.
 * @var mixed  $form            Form settings.
 */
if ( empty( $field->choices ) && $field->id === 'toField' ) {
	echo '<p>' . $field->empty_message . '</p>';

	return;
}
?>
<select
	id="<?php echo esc_attr( $html_id ); ?>"
	name="field_values[<?php echo esc_attr( $field->id ); ?>]"
	class="gk-gravityactions-email-field"
>
	<?php if ( ! empty( $placeholder ) ) { ?>
		<option value="">
			<?php echo esc_html( $placeholder ); ?>
		</option>
	<?php } ?>
	<?php foreach ( $field->choices as $choice ) {
		$value = null;
		if ( isset( $choice->value ) ) {
			$value = $choice->value;
		}
		?>
		<option
			value="<?php echo esc_attr( $value ) ?>"
			<?php selected( ! empty( $field_values[ $field->id ] ) && (int) $value === (int) $field_values[ $field->id ] ) ?>
		>
			<?php echo esc_html( $choice->text ); ?>
		</option>
	<?php } ?>
</select>