<?php
/**
 * The template for displaying comments
 * This is the template that displays the area of the page that contains both the current comments
 * and the comment form.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 * @package Equable_Lite
 */

/*
 * 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;
}
?>

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

	<?php if ( have_comments() ) : ?>
		<h2 class="comments-title">

			<?php
			$comment_count = get_comments_number();
			if ( 1 === $comment_count ) {

				/* translators: %s: post title */
				printf( esc_html(_x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'equable-lite' ), get_the_title() ));
			} else {
				printf( // WPCS: XSS OK.
					/* translators: %1$s: number of comments, %2$s: post title */
					esc_html( _nx( '%1$s Reply on &ldquo;%2$s&rdquo;', '%1$s Replies on &ldquo;%2$s&rdquo;', $comment_count, 'comments title', 'equable-lite' ) ),
					number_format_i18n( $comment_count ),
					'<span>' . get_the_title() . '</span>'
				);					
			}
			?>							
		</h2><!-- .comments-title -->

		<?php the_comments_navigation(); ?>

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

		<?php the_comments_navigation(); ?>

	<?php endif; ?>


<?php // Customize the comments form
		$commenter = wp_get_current_commenter();
		$req = get_option( 'require_name_email' );

		$fields =  array(
			// author
			'author' => '<div class="row"><p class="comment-form-author col-md-4">' . '<label for="author" class="screen-reader-text">' . esc_attr__( '*Name', 'equable-lite'  ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input id="author" name="author" placeholder="' . esc_attr__('Name', 'equable-lite') . '" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" /></p>',
			
			// email	
			'email'     =>  '<p class="comment-form-email col-md-4"><label for="email" class="screen-reader-text">'. esc_html__( 'Email', 'equable-lite' ) .($req ? '<span class="required">*</span>' : '') . '</label><input type="email" name="email" id="email" placeholder="' . esc_attr__('Email', 'equable-lite') . '" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" /></p>',
			
			// website
			'url'       => '<p class="comment-form-url col-md-4"><label class="screen-reader-text">' . esc_html__( 'Website', 'equable-lite' ) . '</label><input type="text" name="url" id="url" placeholder="' . esc_attr__('Website', 'equable-lite') . '"="' . esc_attr( $commenter['comment_author_url'] ) . '"/></p></div>'
		);

		$class_submit   = 'btn btn-default';
		$comment_form_args  = array(    
			  'id_form'           => 'comment-form',
			  'class_submit'      => 'submit',
			  'name_submit'       => 'submit',
			  'title_reply'       => esc_attr__( 'Leave a Reply', 'equable-lite' ),
			  /* translators: %s: title name */
			  'title_reply_to'    => esc_attr__( 'Leave a Reply to %s', 'equable-lite' ),
			  'cancel_reply_link' => esc_attr__( 'Cancel Reply', 'equable-lite' ),
			  'label_submit'      => esc_attr__( 'Post Comment', 'equable-lite' ),
			  'format'            => 'xhtml',
			  'comment_field' =>  '<div class="row"><p class="comment-form-comment col-md-12"><label for="comment" class="screen-reader-text">' . esc_html(_x( 'Comment', 'noun', 'equable-lite' )) .
				'</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="' . esc_attr__('Comment', 'equable-lite') . '">' .
				'</textarea></p></div>',
			  'must_log_in' => '<p class="must-log-in">' .
						  
				sprintf(
				/* translators: %s: link */	
				  esc_html__( 'You must be <a href="%s">logged in</a> to post a comment.','equable-lite' ),
				  wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )
				) . '</p>',
			  'logged_in_as' => '<p class="logged-in-as">' .
			  
				sprintf(
				/* translators: %1$s: user link, %2$s: user name, %3$s: logout link */
				__( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'equable-lite' ),
				  admin_url( 'profile.php' ),
				  $user_identity,
				  wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) )
				) . '</p>',

			  'comment_notes_before' => '<p class="comment-notes">' .
				__( 'Your email address will not be published.', 'equable-lite' ) . ( $req ? '<span class="required">*</span>' : '' ) .
				'</p>',

			  'fields' => apply_filters( 'comment_form_default_fields', $fields ),
		);
	?>
	
		<?php if ( comments_open() ) { 
        if ( get_option('comment_registration') && !is_user_logged_in() ) { ?>
            <p class="login-to-comment"><?php 
			esc_html_e('You must be logged in to post a comment.', 'equable-lite'); ?>
			<a href="<?php echo wp_login_url( get_permalink() ); // WPCS: XSS OK ?>" title="Login"><?php esc_html_e( 'Login', 'equable-lite' ); ?></a>	
			</p>
        <?php } else { 
            comment_form($comment_form_args); 
        } 
    } 
	?>
</div>