<?php
/**
 *
 *
 * @var int    $form_id      Which form we are dealing with.
 * @var array  $entries      Which entries we are modifying.
 * @var array  $field_values Which fields were selected.
 * @var string $view         Which view are in.
 * @var mixed  $form         Form settings.
 */

use \GravityKit\GravityActions\Assets;
use \GravityKit\GravityActions\Actions\EmailAction;

$next_button = get_submit_button(
	esc_html__( 'Send Message', 'gk-gravityactions' ),
	'primary',
	'submit',
	false,
	[
		'data-js'         => 'gk-gravityactions-modal-submit',
		'data-modal-view' => 'email/step-processing',
	]
);
$back_button = get_submit_button(
	esc_html__( 'Back', 'gk-gravityactions' ),
	'secondary',
	'submit',
	false,
	[
		'data-js'         => 'gk-gravityactions-modal-submit',
		'data-modal-view' => 'email/step-1',
	]
);

$to_value_uses_field = ! empty( $field_values['toType'] ) && $field_values['toType'] === 'field';

require_once( ABSPATH . 'wp-admin' . '/includes/upgrade.php' );
?>
<form
	class="gk-gravityactions"
	data-js="gk-gravityactions-modal-form"
>
	<?php $this->render( 'components/modal-fields', [ 'bulk_action' => EmailAction::get_key() ] ); ?>
	<?php $this->render( 'components/header' ); ?>

	<?php foreach ( $field_values as $key => $value ) { ?>
		<input type="hidden" name="field_values[<?php echo $key; ?>]" value="<?php echo( $key !== 'message' ? esc_attr( $value ) : esc_html( $value ) ); ?>"/>
	<?php } ?>

	<div class="gk-gravityactions-modal-body">
		<div class="gv-bulk-edit-step gv-bulk-edit-step-2">
			<div class="gv-bulk-edit-step-content-side">

				<div class="email-header">
					<h3><?php echo __( 'Preview Message', 'gk-gravityactions' ); ?></h3>
				</div>
				<div class="email-body">
					<ul>
						<li>
							<span>
								<?php echo esc_html_x( 'From', 'On the Preview step of the Bulk Email action, "From" which email', 'gk-gravityactions' ); ?>
							</span>
							<?php echo( isset( $field_values['fromName'] ) ? esc_html( $field_values['fromName'] ) : '' ); ?>

							<em><</em><?php echo( isset( $field_values['fromEmail'] ) ? esc_html( $field_values['fromEmail'] ) : '' ); ?><em>></em>
						</li>
						<li>
							<span>
								<?php echo esc_html_x( 'To', 'On the Preview step of the Bulk Email action, "To" which email', 'gk-gravityactions' ); ?>
							</span>
							<?php echo esc_html( EmailAction::get_to_email( $field_values, $form ) ); ?>
							<?php if ( $to_value_uses_field ) { ?>
							<span class="gk-gravityactions-bubble">
								<?php echo esc_html( sprintf( _x( 'ID: %s', '%s is replaced by the value of the email "To" field.', 'gk-gravityactions' ), $field_values['toField'] ) ); ?>
							</span>
							<?php } ?>
						</li>
						<li>
							<span>
								<?php echo esc_html_x( 'Reply To', 'On the Preview step of the Bulk Email action, "Reply To" which email', 'gk-gravityactions' ); ?>
							</span>
							<?php echo( isset( $field_values['replyTo'] ) ? esc_html( $field_values['replyTo'] ) : '' ); ?></li>
						<li>
							<span>
								<?php echo esc_html_x( 'Bcc', 'On the Preview step of the Bulk Email action, "Bcc" which email', 'gk-gravityactions' ); ?>
							</span>
							<?php echo( isset( $field_values['bcc'] ) ? esc_html( $field_values['bcc'] ) : '' ); ?>
						</li>
						<li>
							<span>
								<?php echo esc_html_x( 'Subject', 'On the Preview step of the Bulk Email action, "Subject" of the email', 'gk-gravityactions' ); ?>
							</span>
							<?php echo( isset( $field_values['subject'] ) ? esc_html( $field_values['subject'] ) : '' ); ?>
						</li>
						<li><?php echo( isset( $field_values['message'] ) ? wp_kses_post( wpautop( force_balance_tags( deslash( $field_values['message'] ) ) ) ) : '' ); ?></li>
					</ul>
				</div>

			</div>

			<div class="gv-bulk-edit-step-help-side">

				<img width="188" height="235" src="<?php echo Assets::get_url( 'src/assets/images/edit_step_2_character.svg' ); ?>" alt=""/>

				<span class="gk-gravityactions-modal-help-title">
					<?php esc_html_e( 'Preview Message', 'gk-gravityactions' ); ?>
				</span>

				<span class="gk-gravityactions-modal-help-subtitle">
					<?php esc_html_e( 'Great, looks like you’ve prepared your message.', 'gk-gravityactions' ); ?>
				</span>

			</div>


		</div>

	</div>
	<?php
	$this->render( 'components/footer', [
		'current_step'     => 1,
		'total_steps'      => 3,
		'left_navigation'  => $back_button,
		'right_navigation' => $next_button,
	] );
	?>
</form>