<?php
/**
 * The template for displaying comments
 */

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

<div id="comments" class="comments-area reading-container mt-3">

	<?php
	// Move the comment form ABOVE the comments thread.
	$commenter = wp_get_current_commenter();
	$req = get_option('require_name_email');
	$html_req = ($req ? " required='required'" : '');

	$args = array(
		'class_form' => 'comment-form mb-4',
		'class_submit' => 'btn btn-secondary fw-bold text-uppercase mt-3 px-4 py-2',
		'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title h4 font-sans mb-3 fw-bold">',
		'title_reply_after' => '</h2>',
		'comment_field' => '<div class="comment-form-comment mb-3"><label for="comment" class="form-label text-muted small text-uppercase tracking-wider fw-bold">Add a Perspective <span class="text-danger">*</span></label><textarea id="comment" name="comment" cols="45" rows="4" maxlength="65525" required="required" class="form-control border-0" style="background-color: #f1f3f5;"></textarea></div>',
		'fields' => array(
			'author' => '<div class="row g-3 mb-2"><div class="col-md-6 comment-form-author"><label for="author" class="form-label small fw-bold">Name ' . ($req ? '<span class="text-danger">*</span>' : '') . '</label><input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30" maxlength="245"' . $html_req . ' class="form-control bg-white" /></div>',
			'email' => '<div class="col-md-6 comment-form-email"><label for="email" class="form-label small fw-bold">Email ' . ($req ? '<span class="text-danger">*</span>' : '') . '</label><input id="email" name="email" type="email" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $html_req . ' class="form-control bg-white" /></div></div>',
			'url' => '<div class="comment-form-url mb-4"><label for="url" class="form-label small fw-bold">Website</label><input id="url" name="url" type="url" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" maxlength="200" class="form-control bg-white" /></div>',
		),
	);
	comment_form($args);
	?>

	<?php if (have_comments()): ?>
		<h2 class="comments-title mt-4 h5 font-sans border-bottom pb-2 mb-3">
			<?php
			$comment_count = get_comments_number();
			if ('1' === $comment_count) {
				printf(
					esc_html__('One Response', 'wisdom1')
				);
			} else {
				printf(
					esc_html(_nx('%1$s Response', '%1$s Responses', $comment_count, 'comments title', 'wisdom1')),
					number_format_i18n($comment_count)
				);
			}
			?>
		</h2>

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

		<?php
		the_comments_navigation();

		// If comments are closed and there are comments, let's leave a little note, shall we?
		if (!comments_open()):
			?>
			<p class="no-comments text-muted small fw-bold"><?php esc_html__('Comments are closed.', 'wisdom1'); ?></p>
			<?php
		endif;

	endif; // Check for have_comments().
	?>

</div><!-- #comments -->