<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

?>

<div class="modal fade prodigy-review-modal"
	id="reviewModal"
	role="dialog"
	aria-modal="true"
	aria-labelledby="reviewModalTitle"
	aria-describedby="reviewModalDesc">
	<div class="modal-dialog modal-dialog-centered prodigy-review-modal__dialog">
		<div class="container">
			<div class="row">
				<div
					class="modal-content prodigy-review-modal__content col-md-12 col-lg-10 offset-lg-1 col-xl-8 offset-xl-2">
					<h2 id="reviewModalTitle" class="prodigy-visually-hidden"><?php esc_attr_e( 'Write a Review', 'prodigy-commerce' ); ?></h2>
					<p id="reviewModalDesc" class="prodigy-visually-hidden"><?php esc_attr_e( 'Please complete the form below to submit your review.', 'prodigy-commerce' ); ?></p>
					<div class="prodigy-review-modal__img-wrp d-none d-md-block">
				<?php

				if ( is_array( $product->get_images() ) && ! empty( $product->get_images() ) && isset( $product->get_images()[ array_key_first( $product->get_images() ) ]['versions']['medium'] ) ) :
					?>
								<img
									src="<?php echo esc_url( $product->get_images()[ array_key_first( $product->get_images() ) ]['versions']['medium'] ); ?>"
									class="mb-20"
									alt="<?php echo esc_attr( $post_title ?? __( 'Product Image', 'prodigy-commerce' ) ); ?>">
				<?php else : ?>
								<i
									class="icon icon-image mb-20 prodigy-review-modal__img-wrp-icon"
									style="font-size: 100px;" role="presentation" aria-label="<?php echo esc_attr( 'Empty image icon', 'prodigy-commerce' ); ?>"></i>
				<?php endif; ?>
						<p
							class="prodigy-review-modal__img-caption"><?php echo esc_html( $post_title ?? '' ); ?></p>
					</div>
					<div class="prodigy-review-modal__body">
						<button type="button"
							class="icon icon-small-close prodigy-review-modal__icon-close"
							data-dismiss="modal"
							aria-label="<?php esc_attr_e( 'Close Review Modal', 'prodigy-commerce' ); ?>"></button>
						<div class="prodigy-review-modal__form">
							<div id="review_form" class="prodigy-comment">
					<?php
					$commenter = wp_get_current_commenter();

					/*
						 * Format standard comments output
						 */
					$comment_form = array(
						'fields'               => array(),
						'submit_field'         => '<div class="form-submit"  style="clear: both">%1$s %2$s</div>',
						'class_submit'         => 'prodigy-main-button submit-product-button cursor-pointer',
						'label_submit'         => esc_html__( 'Post a review', 'prodigy-commerce' ),
						'comment_notes_before' => '',
						'submit_button'        => '<button class="prodigy-main-button submit-product-button cursor-pointer" id="submit" type="submit">Post a review</button>',
					);

					/*
						 * Google captcha
						 */
					if ( ! empty( get_option( 'pg_captcha_launch' ) ) && ! empty( get_option( 'pg_captcha_site_key' ) ) ) {
						$comment_form['comment_notes_after'] =
							'<div class="g-recaptcha mb-20" id="captcha" data-callback="prodigyRecaptchaCallback" data-sitekey="' . get_option( 'pg_captcha_site_key' ) . '"></div>';
					}

					$is_enable_rating = get_option( 'pg_product_rating' );
					$user             = wp_get_current_user();

					$role = $user->roles[0] ?? '';

					/*
						 * Format standard comments output
						 */
					$comment_form['comment_field'] = '';
					if ( ! empty( $is_enable_rating ) && $role !== 'administrator' ) {
						$comment_form['comment_field'] =
							'<div class="prodigy-review-modal__body-section comment-form-rating flex-wrap">
											<label class="prodigy-review-modal__body-label" for="prodigy-rating">
												' . esc_html__( 'Product rating *', 'prodigy-commerce' ) . '
											</label>
											<div class="d-flex align-items-center flex-wrap comment-form-rating__rating-wrap">
												<select class="prodigy-main-select" name="rating" id="prodigy-rating" required>
													<option value="">' . esc_html__( 'Rate&hellip;', 'prodigy-commerce' ) . '</option>
													<option value="5">' . esc_html__( 'Perfect', 'prodigy-commerce' ) . '</option>
													<option value="4">' . esc_html__( 'Good', 'prodigy-commerce' ) . '</option>
													<option value="3">' . esc_html__( 'Average', 'prodigy-commerce' ) . '</option>
													<option value="2">' . esc_html__( 'Not that bad', 'prodigy-commerce' ) . '</option>
													<option value="1">' . esc_html__( 'Very poor', 'prodigy-commerce' ) . '</option>
												</select>
												<span class="prodigy-comment__hint">Click to rate</span>
											</div>
                                        </div>';
					}

					$author_name_value              = isset( $author_name_value ) ? $author_name_value : '';
					$comment_form['comment_field'] .=
						"<div class='prodigy-review-modal__body-section prodigy-review-modal__body-section--column'>" . "
                                        <label class='prodigy-review-modal__body-label' for='author_name'>" . esc_html__( 'Your name *', 'prodigy-commerce' ) . "
                                        </label>
                                        <input id='author_name' class='prodigy-review-modal__body-section-text  comment-author-js prodigy-main-input' name='author' type='text' value='" . $author_name_value . "' size='30' required />
                                    </div>";

					if ( get_option( 'require_name_email' ) ) {
						$author_email_value             = isset( $author_email_value ) ? $author_email_value : '';
						$comment_form['comment_field'] .=
							"<div class='prodigy-review-modal__body-section prodigy-review-modal__body-section--column'>" . "
                                        <label class='prodigy-review-modal__body-label' for='author_email'>" . esc_html__( 'Your email *', 'prodigy-commerce' ) . "
                                        </label>
                                        <input id='author_email' class='prodigy-review-modal__body-section-text  comment-email-js prodigy-main-input' name='email' type='email' value='" . $author_email_value . "' size='100' required />
                                    </div>";
					}

					$comment_form['comment_field'] .=
						"<div class='prodigy-review-modal__body-section prodigy-review-modal__body-section--column mb-20'>
											<label class='prodigy-review-modal__body-label' for='comment'>
												" . esc_html__( 'Review *', 'prodigy-commerce' ) . "&nbsp;
											</label>
											<textarea placeholder='" . esc_html__( 'Write your review here...', 'prodigy-commerce' ) . "' id='comment' class='prodigy-review-modal__body-section-text prodigy-comment__text prodigy-main-input' name='comment' cols='45' rows='8' required></textarea>
									</div>";
					comment_form( apply_filters( 'prodigy_product_review_comment_form_args', $comment_form ) );
					?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
