<?php
/**
 * Komentarze motywu Kumibox Pro
 */

if (post_password_required()) {
    return;
}
?>

<div id="comments" class="comments-area mt-12 pt-8 border-t border-[var(--border-custom)]">

    <?php if (have_comments()) : ?>
        <h3 class="text-2xl font-black mb-6 text-[var(--text-main)]">
            <?php
            $comment_count = get_comments_number();
            if ('1' === $comment_count) {
                echo '1 Komentarz';
            } else {
                echo esc_html($comment_count) . ' Komentarze';
            }
            ?>
        </h3>

        <ol class="comment-list space-y-6 mb-8">
            <?php
            wp_list_comments(array(
                'style'       => 'ol',
                'short_ping'  => true,
                'avatar_size' => 50,
                'format'      => 'html5',
            ));
            ?>
        </ol>

        <?php the_comments_navigation(); ?>

    <?php endif; ?>

    <?php
    if (!comments_open() && get_comments_number() && post_type_supports(get_post_type(), 'comments')) : ?>
        <p class="no-comments text-gray-500 italic mb-8">Komentarze są wyłączone.</p>
    <?php
    endif;

    $commenter = wp_get_current_commenter();
    $req = get_option('require_name_email');
    
    $comments_args = array(
        'class_form'           => 'flex flex-col gap-4',
        'title_reply_before'   => '<h3 id="reply-title" class="text-2xl font-black mb-4 text-[var(--text-main)]">',
        'title_reply_after'    => '</h3>',
        'comment_notes_before' => '<p class="text-sm text-gray-500 mb-4">Twój adres e-mail nie zostanie opublikowany.</p>',
        'fields'               => array(
            'author' => '<div class="flex flex-col"><label for="author" class="text-xs font-bold uppercase mb-1">Nazwa</label><input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30" ' . ($req ? 'required' : '') . ' class="kumibox-input" /></div>',
            'email'  => '<div class="flex flex-col"><label for="email" class="text-xs font-bold uppercase mb-1">E-mail</label><input id="email" name="email" type="email" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" ' . ($req ? 'required' : '') . ' class="kumibox-input" /></div>',
            'url'    => '<div class="flex flex-col"><label for="url" class="text-xs font-bold uppercase mb-1">Witryna internetowa</label><input id="url" name="url" type="url" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" class="kumibox-input" /></div>',
        ),
        'comment_field'        => '<div class="flex flex-col"><label for="comment" class="text-xs font-bold uppercase mb-1">Twój komentarz</label><textarea id="comment" name="comment" cols="45" rows="6" required class="kumibox-input"></textarea></div>',
        'submit_button'        => '<div class="cf-turnstile-container"></div><input name="%1$s" type="submit" id="%2$s" class="kumibox-btn %3$s" value="%4$s" />',
    );

    comment_form($comments_args);
    ?>

</div>