<?php
/**
 * The template for displaying comments
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package    Wira
 * @since      1.0.0
 */

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

<!-- Comments Area -->
<div id="comments" class="comments-area theme-bg-white theme-space-small theme-rounded theme-box-shadow">

	<?php
	if ( have_comments() ) :
		?>

		<!-- Comments Title -->
		<h2 class="comments-title pb-3 mb-5">
			<?php
			$wira_comment_count = get_comments_number();
			if ( '1' === $wira_comment_count ) {
				printf(
					esc_html__( 'Comments on &ldquo;%1$s&rdquo;', 'wira' ),
					'<span>' . wp_kses_post( get_the_title() ) . '</span>'
				);
			} else {
				printf(
					esc_html( _nx( '%1$s Comments on &ldquo;%2$s&rdquo;', '%1$s Comments on &ldquo;%2$s&rdquo;', $wira_comment_count, 'comments title', 'wira' ) ),
					number_format_i18n( $wira_comment_count ),
					'<span>' . wp_kses_post( get_the_title() ) . '</span>'
				);
			}
			?>
		</h2>

		<?php the_comments_navigation(); ?>
		
		<!-- Comments List -->
		<ul class="comment-list">
			<?php
			wp_list_comments(
				array(
					'style'      => 'ul',
					'callback'   => 'Wira_Custom_Comments',
					'short_ping' => true,
				)
			);
			?>
		</ul>

		<?php
		the_comments_navigation();

		if ( ! comments_open() ) :
			?>
			<p class="no-comments"><?php echo esc_html__( 'Comments are closed.', 'wira' ); ?></p>
			<?php
		endif;

	endif;

	/*
	* Comments Form
	*/
	comment_form(
		array(
			'title_reply'       => esc_html__( 'Leave Your Comment', 'wira' ),
			'title_reply_to'    => esc_html__( 'Leave A Reply To %s', 'wira' ),
			'cancel_reply_link' => '<i class="fas fa-times ms-2 theme-color-primary"></i>',
			'comment_field'     => '<p class="comment-form-comment">
                <textarea id="comment" name="comment" placeholder="' . esc_attr__( 'Your comment here...', 'wira' ) . '" rows="5" required></textarea>
            </p>',
			'fields'            => array(
				'author' =>
					'<p class="comment-form-author">
                        <input id="author" name="author" type="text" placeholder="' . esc_attr__( 'Your Name', 'wira' ) . '" required />
                    </p>',
				'email'  =>
					'<p class="comment-form-email">
                        <input id="email" name="email" type="email" placeholder="' . esc_attr__( 'Your Email', 'wira' ) . '" required />
                    </p>',
				'url'    =>
					'<p class="comment-form-url">
                        <input id="url" name="url" type="url" placeholder="' . esc_attr__( 'Your Website (optional)', 'wira' ) . '" />
                    </p>',
			),
		)
	);
	?>

</div>
