<?php
if ( !defined('ABSPATH')) exit;

if (post_password_required() || !comments_open()):
    return;
else:
    ?>
    <?php if (have_comments()) : ?>  
        <div id="comments">
            <h3>
                <?php comments_number(__('No Comments', 'circle-lite'), __('1 Comment', 'circle-lite'), __('% Comments', 'circle-lite')); ?>                
            </h3>
            <ol class="comments-list clearfix">
                <?php
                wp_list_comments(array(
                    'walker' => null,
                    'style' => 'ul',
                    'callback' => 'kopa_comment_callback',
                    'end-callback' => null,
                    'type' => 'all'
                ));
                ?>
            </ol>
            <center class="pagination kopa-comment-pagination"><?php paginate_comments_links(); ?></center>
        </div>
    <?php endif; ?>	  
    <?php comment_form(kopa_comment_form_args()); ?>
<?php endif; ?>

<?php

function kopa_comment_callback($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    ?>
    <li <?php comment_class(); ?> id="li-comment-<?php echo get_comment_ID() ?>">   


        <article id="comment-<?php echo get_comment_ID(); ?>" class="comment-wrap clearfix">
            <div class="comment-avatar">
                <?php echo get_avatar($comment->comment_author_email, 90); ?>                                          
            </div>
            <div class="comment-body clearfix">
                <div class="comment-meta">
                    <span class="author"><?php comment_author_link(); ?></span>
                    <span class="date">-&nbsp;&nbsp;<?php comment_time(get_option('date_format') . ' - ' . get_option('time_format')); ?></span>
                    <?php
                    $status = wp_get_comment_status(get_comment_ID());
                    if ('approved' != $status) {
                        ?>
                        <span><i><?php _e('(Your Comment is Under Moderation)', 'circle-lite'); ?></i></span>
                        <?php
                    }
                    ?>
                </div><!-- end:comment-meta -->                        
                <div><?php comment_text(true); ?></div>

                <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>                                
                <?php edit_comment_link(__('Edit', 'circle-lite')) ?>                                                        

                <!-- <a href="#" class="comment-reply-link small-button green-button">Reply</a> -->
            </div><!--comment-body -->
        </article>                                                                 
    </li>

    <?php
}

function kopa_comment_form_args() {
    global $user_identity;
    $commenter = wp_get_current_commenter();

    $fields = array(
        'author' => '<div class="clear"></div><div class="comment-left">
                <p class="input-block">               
                <label class="required" for="comment_name" >' . __("Name <span>(required):</span>", 'circle-lite') . '</label>
                <input type="text" name="author" id="comment_name"                 
                value="' . esc_attr($commenter['comment_author']) . '">                                               
                </p>',
        'email' => '
                <p class="input-block">   
                <label for="comment_email" class="required">' . __("Email <span>(required):</span>", 'circle-lite') . '</label>                                            
                <input type="email" name="email" id="comment_email"                                                                 
                value="' . esc_attr($commenter['comment_author_email']) . '" >
                </p>',
        'url' => '
                <p class="input-block">   
                <label for="comment_url" class="required">' . __("Website", 'circle-lite') . '</label>                                                            
                <input type="url" name="url" id="comment_url"                 
                value="' . esc_attr($commenter['comment_author_url']) . '" >
                </p></div>'
    );

    $comment_field = '<div class="comment-right"><p class="textarea-block">
        <label class="required" for="comment_message">' . __('Message <span>(required):</span>', 'circle-lite') . '</label>        
        <textarea name="comment" id="comment_message"></textarea>
        </p></div><div class="clear"></div>';

    $args = array(
        'fields' => apply_filters('comment_form_default_fields', $fields),
        'comment_field' => $comment_field,
        'must_log_in' => '<p class="alert">' . sprintf(__('You must be <a href="%1$s" title="Log in">logged in</a> to post a comment.', 'circle-lite'), wp_login_url(get_permalink())) . '</p><!-- .alert -->',
        'logged_in_as' => '<p class="log-in-out">' . sprintf(__('Logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'circle-lite'), admin_url('profile.php'), esc_attr($user_identity)) . ' <a href="' . wp_logout_url(get_permalink()) . '" title="' . esc_attr__('Log out of this account', 'circle-lite') . '">' . __('Log out &raquo;', 'circle-lite') . '</a></p><!-- .log-in-out -->',
        'comment_notes_before' => '<span class="c-note">' . __('Your email address will not be published. Required fields are marked <span>(required):</span>', 'circle-lite') . '</span>',
        'comment_notes_after' => '',
        'id_form' => 'comments-form',
        'id_submit' => 'submit-comment',
        'title_reply' => __('Leave A Comment', 'circle-lite'),
        'title_reply_to' => __('Reply', 'circle-lite'),
        'cancel_reply_link' => __('Cancel', 'circle-lite'),
        'label_submit' => __('Submit', 'circle-lite'),
    );

    return $args;
}
