<?php
if ( post_password_required() ) {
	return;
}
?>

<div id="comments" class="comments-wrap">

	<?php if ( have_comments() ) : ?>
		<div class="comments-header">
			<h2 class="comments-title">
				<i class="fa-regular fa-comments" aria-hidden="true"></i>
				<?php
				printf(
					esc_html( _n( '%d دیدگاه', '%d دیدگاه', get_comments_number(), 'vista' ) ),
					(int) get_comments_number()
				);
				?>
			</h2>
		</div>

		<ol class="comment-list">
			<?php
			wp_list_comments( array(
				'style'       => 'ol',
				'short_ping'  => true,
				'avatar_size' => 52,
				'callback'    => 'vista_comment_template',
			) );
			?>
		</ol>

		<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
			<div class="comment-pagination">
				<?php paginate_comments_links( array(
					'prev_text' => '<i class="fa-solid fa-chevron-' . ( is_rtl() ? 'right' : 'left' ) . '"></i>',
					'next_text' => '<i class="fa-solid fa-chevron-' . ( is_rtl() ? 'left' : 'right' ) . '"></i>',
				) ); ?>
			</div>
		<?php endif; ?>

	<?php endif; // have_comments() ?>

	<?php if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
		<p class="no-comments"><?php esc_html_e( 'نظرات بسته است.', 'vista' ); ?></p>
	<?php endif; ?>

	<?php if ( comments_open() ) : ?>
		<div class="comment-form-section">
			<div class="comment-form-header">
				<h3 class="comment-form-title">
					<i class="fa-solid fa-pen-to-square" aria-hidden="true"></i>
					<?php esc_html_e( 'دیدگاه خود را بنویسید', 'vista' ); ?>
				</h3>
				<?php if ( is_user_logged_in() ) : ?>
					<p class="comment-logged-in">
						<?php
						printf(
							wp_kses( __( 'وارد شده به عنوان <strong>%s</strong>.', 'vista' ), array( 'strong' => array() ) ),
							esc_html( wp_get_current_user()->display_name )
						);
						?>
						<a href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>" class="comment-logout-link">
							<?php esc_html_e( 'خروج', 'vista' ); ?>
						</a>
					</p>
				<?php endif; ?>
			</div>

			<?php
			$commenter = wp_get_current_commenter();

			comment_form( array(
				'title_reply'         => '',
				'title_reply_to'      => esc_html__( 'پاسخ به %s', 'vista' ),
				'cancel_reply_link'   => '<i class="fa-solid fa-xmark"></i> ' . esc_html__( 'لغو پاسخ', 'vista' ),
				'label_submit'        => esc_html__( 'ارسال دیدگاه', 'vista' ),
				'submit_button'       => '<button name="%1$s" type="submit" id="%2$s" class="%3$s btn btn-primary"><i class="fa-solid fa-paper-plane" aria-hidden="true"></i> %4$s</button>',
				'class_form'          => 'comment-form rp-comment-form',
				'comment_notes_before'=> '',
				'comment_notes_after' => '',
				'comment_field'       => '<div class="cf-field cf-field-textarea">
					<label for="comment" class="cf-label">' . esc_html__( 'دیدگاه', 'vista' ) . ' <span class="required" aria-hidden="true">*</span></label>
					<textarea id="comment" name="comment" class="cf-input" rows="6" required placeholder="' . esc_attr__( 'دیدگاه خود را اینجا بنویسید...', 'vista' ) . '"></textarea>
				</div>',
				'fields' => array(
					'author' => '<div class="cf-row">
						<div class="cf-field">
							<label for="author" class="cf-label">' . esc_html__( 'نام', 'vista' ) . ' <span class="required" aria-hidden="true">*</span></label>
							<input id="author" name="author" type="text" class="cf-input" value="' . esc_attr( $commenter['comment_author'] ) . '" placeholder="' . esc_attr__( 'نام شما', 'vista' ) . '" required autocomplete="name">
						</div>',
					'email'  => '<div class="cf-field">
							<label for="email" class="cf-label">' . esc_html__( 'ایمیل', 'vista' ) . ' <span class="required" aria-hidden="true">*</span></label>
							<input id="email" name="email" type="email" class="cf-input" value="' . esc_attr( $commenter['comment_author_email'] ) . '" placeholder="' . esc_attr__( 'ایمیل شما (نمایش داده نمی‌شود)', 'vista' ) . '" required autocomplete="email" dir="ltr">
						</div>
					</div>',
					'url'    => '',
					'cookies'=> '<p class="cf-cookies">
						<label class="cf-check-label">
							<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" ' . ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ? 'checked' : '' ) . '>
							' . esc_html__( 'اطلاعاتم را برای دفعه بعد ذخیره کن', 'vista' ) . '
						</label>
					</p>',
				),
			) );
			?>
		</div>
	<?php endif; ?>

</div>
