<?php
/**
 * The comments template
 *
 * @package Paws_And_Care
 * @since 1.0.0
 */

// Prevent direct access
if ( post_password_required() ) {
    return;
}
?>

<div id="comments" class="comments-area mt-5">
    <?php if ( have_comments() ) : ?>
        <h3 class="comments-title mb-4">
            <?php
            $comment_count = get_comments_number();
            if ( '1' === $comment_count ) {
                printf(
                    /* translators: %s: post title */
                    esc_html__( 'One comment on &ldquo;%s&rdquo;', 'paws-and-care' ),
                    '<span>' . wp_kses_post( get_the_title() ) . '</span>'
                );
            } else {
                printf(
                    /* translators: 1: comment count, 2: post title */
                    esc_html( _nx( '%1$s comment on &ldquo;%2$s&rdquo;', '%1$s comments on &ldquo;%2$s&rdquo;', $comment_count, 'comments title', 'paws-and-care' ) ),
                    number_format_i18n( $comment_count ),
                    '<span>' . wp_kses_post( get_the_title() ) . '</span>'
                );
            }
            ?>
        </h3>

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

        <?php
        the_comments_navigation( array(
            'prev_text' => '<i class="fa-solid fa-chevron-left"></i> ' . esc_html__( 'Older Comments', 'paws-and-care' ),
            'next_text' => esc_html__( 'Newer Comments', 'paws-and-care' ) . ' <i class="fa-solid fa-chevron-right"></i>',
        ) );

        if ( ! comments_open() ) :
            ?>
            <p class="no-comments alert alert-info"><?php esc_html_e( 'Comments are closed.', 'paws-and-care' ); ?></p>
        <?php endif; ?>

    <?php endif; ?>

    <?php
    comment_form( array(
        'class_form'         => 'comment-form',
        'class_submit'       => 'btn btn-primary',
        'title_reply'        => esc_html__( 'Leave a Comment', 'paws-and-care' ),
        'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title mb-4">',
        'title_reply_after'  => '</h3>',
        'comment_field'      => '<div class="mb-3"><label for="comment" class="form-label">' . esc_html__( 'Comment', 'paws-and-care' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" class="form-control" rows="5" required></textarea></div>',
    ) );
    ?>
</div>

