<?php
/**
 * The template for displaying the comments
 *
 * @package Felicityhealth
 * @since Felicityhealth 1.0
 */

/*
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the comments.
 */
if ( post_password_required() ) {
    return;
}
?>

<section id="comments" class="container mb-4 pt-lg-4 pb-lg-3">
    <?php if ( have_comments() ) : ?>
        <h2 class="h2 text-center text-sm-start">
            <?php
                $comments_number = get_comments_number();
                if ( 1 === $comments_number ) {
                    /* translators: %s: post title */
                    printf( _x( 'One thought on &ldquo;%s&rdquo;', 'comments title', 'felicityhealth' ), get_the_title() );
                } else {
                    printf(
                        /* translators: 1: number of comments, 2: post title */
                        _nx(
                            '%1$s thought on &ldquo;%2$s&rdquo;',
                            '%1$s thoughts on &ldquo;%2$s&rdquo;',
                            $comments_number,
                            'comments title',
                            'felicityhealth'
                        ),
                        number_format_i18n( $comments_number ),
                        get_the_title()
                    );
                }
            ?>
        </h2>
        <div class="row">
            <!-- Comments -->
            <div class="col-lg-9">
                <?php the_comments_navigation(); ?>
                <!-- Comment -->
                <?php
                    wp_list_comments( array(
                        'style'       => 'div',
                        'short_ping'  => true,
                        'avatar_size' => 48,
                        'type' => 'comment',
                        'callback' => 'felicity_comment'
                    ) );
                ?>
                <?php the_comments_navigation(); ?>
            </div>
        </div>
    <?php endif; // Check for have_comments(). ?>
    <?php
        // If comments are closed and there are comments, let's leave a little note, shall we?
        if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    ?>
    <p class="no-comments"><?php _e( 'Comments are closed.', 'felicityhealth' ); ?></p>
    <?php endif; ?>
    </section>
    <!-- .comments-area -->
    <!-- Comment form-->
    <?php
    //Declare Vars
    $comment_send = __( 'Send', 'felicityhealth' );
    $comment_reply = __( 'Leave a Message', 'felicityhealth' );
    $comment_reply_to = __( 'Reply', 'felicityhealth' );
    $comment_author = __( 'Name', 'felicityhealth' );
    $comment_email = __( 'E-Mail', 'felicityhealth' );
    $comment_body = __( 'Type your comment here...', 'felicityhealth' );
    $comment_url = __( 'Website', 'felicityhealth' );
    $comment_cookies_1 = __( 'Save my name and email in this browser for the next time I comment.', 'felicityhealth' );
    $comment_before = '<p class="small m-0">'. __( 'Registration isn\'t required.', 'felicityhealth' );
    $comment_cancel =' <i class="bx bx-message-rounded-x fs-lg me-1"></i>'. __( 'Cancel Reply', 'felicityhealth' );
    
    //Array
    $comments_args = array(
        'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title h5 mb-4 pb-3 mt-3">',
        'title_reply_after'  => '</h2>',
        'class_container' => 'col',
        'class_form' => 'row gy-4 needs-validation',
        //Define Fields
        'fields' => array(
            //Author field
            'author' => '
                <div class="comment-form-author col-sm-6 col-12">
                    <label for="author" class="form-label fs-base">'. __( 'Name', 'felicityhealth' ) .'</label>
                    <input id="author" type="text" name="author" class="form-control form-control-lg" required="" placeholder="' . $comment_author .'">
                    <span class="invalid-tooltip">'. __( 'Please, enter your name', 'felicityhealth' ) .'.</span>
                </div>',
            //Email Field
            'email' => '
                <div class="comment-form-email col-sm-6 col-12">
                    <label for="email" class="form-label fs-base">'. __( 'Email', 'felicityhealth' ) .'</label>
                    <input id="email" type="email" name="email" placeholder="' . $comment_email .'" class="form-control form-control-lg" required="">
                    <span class="invalid-tooltip">' . __( 'Please, provide a valid email address', 'felicityhealth' ) .'.</span>
                </div>',
            //URL Field 
            'url' => '
                <div class="comment-form-url col-sm-6 col-12">
                    <label for="url" class="form-label fs-base">' . __( 'Website', 'felicityhealth' ) .'</label>
                    <input id="url" type="url" name="url" placeholder="' . $comment_url .'" class="form-control form-control-lg">
                </div>',
            //Cookies
            'cookies' => '
                <div class="comment-form-cookies-consent col-12">
                    <div class="form-check">
                        <input id="wp-comment-cookies-consent" type="checkbox" class="form-check-input" name="wp-comment-cookies-consent">
                        <label for="wp-comment-cookies-consent" class="form-check-label" >' . $comment_cookies_1 . '</label>
                    </div>
                </div>',
        ),
        // Change the title of send button
        'label_submit' => __( $comment_send ),
        // Change the title of the reply section
        'title_reply' => __( $comment_reply ),
        // Change the title of the reply section
        'title_reply_to' => __( $comment_reply_to ),
        //Cancel Reply Text
        'cancel_reply_link' => __( $comment_cancel ),
        // Redefine your own textarea (the comment body).
        'comment_field' => '
                <div class="comment-form-comment col-12">
                    <label for="comment" class="form-label fs-base">' . __( 'Comment', 'felicityhealth' ) .'</label>
                    <textarea id="comment" name="comment" class="form-control form-control-lg" rows="3" placeholder="' . $comment_body .'" required="" spellcheck="false"></textarea>
                    <span class="invalid-tooltip">' . __( 'Please, enter your comment.', 'felicityhealth' ) .'</span>
                </div> ',
        //Message Before Comment
        'comment_notes_before' => __( $comment_before),
        // Remove "Text or HTML to be displayed after the set of comment fields".
        'comment_notes_after' => '',
        //Submit Button ID
        'id_submit' => __( 'comment-submit' ),
        'label_submit' => __( 'Post Comment' ),
        'submit_field' => '<div class="col-12">%1$s %2$s </div>',
        'submit_button' => '
                <input type="submit" id="%2$s" value="%4$s" class="btn btn-lg btn-primary w-sm-auto w-100 mt-2"/>
            ',
    );
    validate_comment_form( $comments_args );
    ?>
