<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains comments and the comment form.
 *
 * 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;
$type = get_post_type();

$aria_req = ( $req ? " aria-required='true'" : '' );
?>
<?php if($type=='listing'){ ?>
    
    <?php
    $user_id = get_current_user_id();
    ?>
    <?php
    $comment_args = array(
        'title_reply_before' => '<h2 class="heading2 contact-form__title">',
        'title_reply_after'  => '</h2>',
        'title_reply'=> esc_html__('Write a Comment','triptip'),
        'fields' => apply_filters( 'comment_form_default_fields', array(
            'author' => '<div class="row">
                <div class="col-md-4">
                    
                    <input type="text" name="author" placeholder="'.esc_attr__('Name','triptip').'*"  id="name" value="' . esc_attr( $commenter['comment_author'] ) . '"  />
                </div>
            ',
            'email' => '<div class="col-md-4">
                
                    <input id="mail" placeholder="'.esc_attr__('Email','triptip').'*" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '"/>
                </div>
            ',
            'url' => '<div class="col-md-4">
                <input id="website" name="url" placeholder="'.esc_attr__('Website','triptip').'" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '"  /></div></div>
                
            '
        )),
        'comment_field' => '<textarea  class="contact-form__textarea" rows="7" id="comment" placeholder="'.esc_attr__('Comments','triptip').'*" name="comment"></textarea>',
        'label_submit' => esc_html__('Submit Comment', 'triptip'),
        'comment_notes_after' => '',
    );
    ?>

    <!-- Contact form module -->
        <div class="contact-form inner-review" id="leave-review">
            <div class="inner-review__form">
                <?php if(get_user_meta($user_id, '_triptip_avatar' ,true)!=''){ ?>
                    <?php $image = get_user_meta($user_id, '_triptip_avatar' ,true); ?>
                    <img src="<?php echo esc_url($image); ?>" />
                <?php }else{ ?>
                  <?php echo get_avatar(get_the_author_meta('user_email'),$size='100',$default='https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=120' ); ?>
                <?php } ?>
                <div class="inner-review__form-box">
                    <?php comment_form($comment_args); ?>
                </div>
            </div>
        </div>
        <!-- End Contact form module -->
        <?php if( get_comments_number()){ ?>
            <!-- tips & reviews-box -->
            <div class="listing-detail__reviews element-waypoint" id="tips-reviews-box">
                <h2 class="heading2 listing-detail__content-title">
                    <?php esc_html_e('Tips & Reviews ', 'triptip'); ?> 
                </h2>
                <div class="listing-detail__reviews-box">

                    <?php if(get_comment_pages_count()>0){ ?>
                        <ul class="reviews-list">
                            <?php wp_list_comments('callback=triptip_theme_comment'); ?>
                        </ul>
                    <?php } ?>
                    <?php
                    // Are there comments to navigate through?
                    if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
                        ?>
                        <div class="navigation comment-navigation" role="navigation">
                            
                            <div class="previous"><?php previous_comments_link( esc_html__( '&larr; Older Comments', 'triptip' ) ); ?></div>
                            <div class="next right"><?php next_comments_link( esc_html__( 'Newer Comments &rarr;', 'triptip' ) ); ?></div>
                        </div><!-- .comment-navigation -->
                    <?php endif; // Check for comment navigation ?>

                    <?php if ( ! comments_open() && get_comments_number() ) : ?>
                        <p class="no-comments"><?php esc_html_e( 'Comments are closed.' , 'triptip' ); ?></p>
                    <?php endif; ?>

                </div>

            </div>
        <?php } ?>

<?php }else{ ?>
<?php 
$comment_args = array(
	'title_reply_before' => '<h2 class="heading2 contact-form__title">',
	'title_reply_after'  => '</h2>',
    'title_reply'=> esc_html__('Write a Comment','triptip'),
    'fields' => apply_filters( 'comment_form_default_fields', array(
        'author' => '<div class="row">
            <div class="col-md-4">
                
                <input type="text" name="author" placeholder="'.esc_attr__('Name','triptip').'*"  id="name" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' />
            </div>
        ',
        'email' => '<div class="col-md-4">
            
                <input id="mail" placeholder="'.esc_attr__('Email','triptip').'*" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" ' . $aria_req . ' />
            </div>
        ',
        'url' => '<div class="col-md-4">
            <input id="website" name="url" placeholder="'.esc_attr__('Website','triptip').'" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '"  /></div></div>
        	
        '
    )),
    'comment_field' => '<textarea  rows="7" id="comment" placeholder="'.esc_attr__('Comments','triptip').'*" name="comment"'.$aria_req.'></textarea>',
    'label_submit' => esc_html__('Post Comment', 'triptip'),
    'comment_notes_after' => '',
);
?>
<?php if( get_comments_number()){ ?>
<div class="comments">
    <h2 class="heading2 comments-line"><?php comments_number( esc_html__('0 Comments','triptip'), esc_html__('1 Comment','triptip'), esc_html__('% Comments','triptip') ); ?></h3>
    <?php if(get_comment_pages_count()>0){ ?>
        <ul class="reviews-list">
            <?php wp_list_comments('callback=triptip_theme_comment'); ?>
        </ul>
    <?php } ?>
    <?php
    // Are there comments to navigate through?
    if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
        ?>
        <div class="navigation comment-navigation" role="navigation">
            
            <div class="previous"><?php previous_comments_link( esc_html__( '&larr; Older Comments', 'triptip' ) ); ?></div>
            <div class="next right"><?php next_comments_link( esc_html__( 'Newer Comments &rarr;', 'triptip' ) ); ?></div>
        </div><!-- .comment-navigation -->
    <?php endif; // Check for comment navigation ?>

    <?php if ( ! comments_open() && get_comments_number() ) : ?>
        <p class="no-comments"><?php esc_html_e( 'Comments are closed.' , 'triptip' ); ?></p>
    <?php endif; ?>

    
</div>
<?php } ?>

<!-- Contact form  -->
<?php if('open' == $post->comment_status){ ?>
<div id="comment-form">
    <?php comment_form($comment_args); ?>
</div>
<!-- End contact form box -->
<?php } ?>

<!-- End Contact form -->
<?php } ?>
