<?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://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Markup
 */

/*
 * 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;
}
$dulcie_commenter     = wp_get_current_commenter();
$dulcie_name_required = (bool) get_option( 'require_name_email' );
$dulcie_required_attr = $dulcie_name_required ? ' required="required" aria-required="true"' : '';
$dulcie_required_mark = $dulcie_name_required ? ' <span class="required">*</span>' : '';
$dulcie_current_user  = wp_get_current_user();

$fields = array(

	'author' => '<p class="comment-form-author contact-item">'
		. '<label for="author">' . esc_html__( 'Name', 'dulcie' ) . $dulcie_required_mark . '</label>'
		. '<input id="author" name="author" type="text" class="input-form" autocomplete="name" maxlength="245"'
		. ' value="' . esc_attr( $dulcie_commenter['comment_author'] ) . '"' . $dulcie_required_attr . ' />'
		. '</p>',

	'email'  => '<p class="comment-form-email contact-item">'
		. '<label for="email">' . esc_html__( 'Email', 'dulcie' ) . $dulcie_required_mark . '</label>'
		. '<input id="email" name="email" type="email" class="input-form" autocomplete="email" maxlength="100"'
		. ' value="' . esc_attr( $dulcie_commenter['comment_author_email'] ) . '"' . $dulcie_required_attr . ' />'
		. '</p>',

	'url'    => '<p class="comment-form-url contact-item">'
		. '<label for="url">' . esc_html__( 'Website', 'dulcie' ) . '</label>'
		. '<input id="url" name="url" type="url" class="input-form" autocomplete="url" maxlength="200"'
		. ' value="' . esc_attr( $dulcie_commenter['comment_author_url'] ) . '" />'
		. '</p>',
);

/*
 * comment_form() only adds its cookie-consent field to the *default* field
 * list, and a theme supplying its own 'fields' array replaces that list
 * wholesale. This theme did, without the field, so "Show comments cookies
 * opt-in checkbox" in Settings > Discussion had no effect.
 */
if ( get_option( 'show_comments_cookies_opt_in' ) ) {
	$dulcie_consent = empty( $dulcie_commenter['comment_author_email'] ) ? '' : ' checked="checked"';

	$fields['cookies'] = '<p class="comment-form-cookies-consent">'
		. '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $dulcie_consent . ' />'
		. '<label for="wp-comment-cookies-consent">' . esc_html__( 'Save my name, email, and website in this browser for the next time I comment.', 'dulcie' ) . '</label>'
		. '</p>';
}

$custom_comment_form = array(
	'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
	'comment_field'        => '<p class="comment-form-comment contact-item">'
		. '<label for="comment">' . esc_html__( 'Comment', 'dulcie' ) . ' <span class="required">*</span></label>'
		. '<textarea id="comment" name="comment" class="textarea-form" rows="6" maxlength="65525" required="required" aria-required="true"></textarea>'
		. '</p>',
	'logged_in_as'         => '<p class="logged-in-as">'
		. esc_html__( 'Logged in as', 'dulcie' ) . ' '
		. '<a href="' . esc_url( admin_url( 'profile.php' ) ) . '">' . esc_html( $dulcie_current_user->display_name ) . '</a> '
		. '<a href="' . esc_url( wp_logout_url( apply_filters( 'the_permalink', get_permalink(), get_the_ID() ) ) ) . '">' . esc_html__( 'Log out?', 'dulcie' ) . '</a>'
		. '</p>',
	'cancel_reply_link'    => esc_html__( 'Cancel', 'dulcie' ),
	'comment_notes_before' => '<p class="comment-notes">' . esc_html__( 'Your email address will not be published. Required fields are marked *', 'dulcie' ) . '</p>',
	'comment_notes_after'  => '',
	'title_reply'          => esc_html__( 'Leave a Reply', 'dulcie' ),
	'label_submit'         => esc_html__( 'Post Comment', 'dulcie' ),
	'id_submit'            => 'submit',
);
?>
<?php if ( have_comments() ) : ?>
<div id="comments" class="comments-area">
    <?php if ( comments_open() ) : ?>
        <h2 class="title">
            <?php
            printf(
                /* translators: %s: comment count number. */
                esc_html( _nx( '%s Comment', '%s Comments', get_comments_number(), 'comments title', 'dulcie' ) ),
                esc_html( number_format_i18n( get_comments_number() ) )
            );
            ?>
        </h2>
   	<?php endif; ?>
	<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
	<nav id="comment-nav-above" class="navigation comment-navigation" role="navigation">
		<h2 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'dulcie' ); ?></h2>
		<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', 'dulcie' ) ); ?></div>
		<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', 'dulcie' ) ); ?></div>
	</nav>
	<?php endif; ?>    
	<ul class="comment-list">
		<?php
			wp_list_comments( array(
				'style'       => 'ul',
				'short_ping'  => true,
			) );
		?>
	</ul>    
	<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
	<nav id="comment-nav-below" class="navigation comment-navigation" role="navigation">
		<h2 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'dulcie' ); ?></h2>
		<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', 'dulcie' ) ); ?></div>
		<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', 'dulcie' ) ); ?></div>
	</nav>
	<?php endif; ?>    
	<?php if ( ! comments_open() ) : ?>
	<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'dulcie' ); ?></p>
	<?php endif; ?>
</div>
<?php endif; ?>
<?php comment_form($custom_comment_form); ?>
