<?php
/**
 *
 *
 * @var int        $form_id            Which form we are dealing with.
 * @var int|string $field_id           Which field ID 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 mixed      $form               Form settings.
 * @var EditAction $bulk_action_object Action we are handling here
 */

use GravityKit\GravityActions\Actions\EditAction;

// When it's a sub-field we can handle it separately.
if ( EditAction::is_sub_field( $field_id ) ) {
	return;
}

$is_meta = false;

if ( is_numeric( $field_id ) ) {
	$field = GFAPI::get_field( $form_id, $field_id );
} else {
	$field   = EditAction::get_meta_field( $field_id );
	$is_meta = true;
}
$html_id = sanitize_html_class( "gk-gravityactions-edit-field-{$field->id}" );
?>
<tr class="gk-gravityactions-edit-field-row">
	<th scope="row">
		<label
			for="<?php echo $html_id; ?>"
		>
			<?php echo esc_html( $field->label ); ?>
			<?php if ( $is_meta ) : ?>
				<span class="gk-gravityactions-label">
					<?php esc_html_e( 'Meta', 'gk-gravityactions' ); ?>
				</span>
			<?php endif; ?>
		</label>
	</th>
	<td>
		<?php
		$template = $bulk_action_object->get_template_for_field( $field );
		$this->render( $template, [
			'field'       => $field,
			'input'       => null, // Here to reset internal input for every field.
			'html_id'     => $html_id,
			'placeholder' => __( 'Leaving blank will empty field.', 'gk-gravityactions' ),
		] );
		?>
	</td>
</tr>