<?php
/**
 * Single Forum - Style 4: Grid (Forum Info + Topics Side-by-Side).
 *
 * Left side shows forum info, right side shows topics list.
 * Uses $settings, $forum_id, $post_thumbnail_url, $topics, $unique_id.
 *
 * @package bbp-core
 */

// Resolve cover overlay color.
$overlay_color = ! empty( $settings['cover_overlay_color'] ) ? $settings['cover_overlay_color'] : 'rgba(28, 38, 56, 0.5)';
?>
<div class="bbpc-sf-grid">
    <div class="bbpc-sf-grid-info"
        style="background:linear-gradient(<?php echo esc_attr( $overlay_color ); ?>,<?php echo esc_attr( $overlay_color ); ?>), url('<?php echo esc_url( $post_thumbnail_url ); ?>') center / cover no-repeat">
        <div class="bbpc-sf-grid-info-inner">
            <h3 class="bbpc-sf-grid-title">
                <a href="<?php the_permalink( $forum_id ); ?>">
                    <?php echo esc_html( get_the_title( $forum_id ) ); ?>
                </a>
            </h3>
            <?php if ( ! empty( $settings['show_excerpt'] ) ) : ?>
                <p class="bbpc-sf-grid-desc">
                    <?php echo wp_kses_post( wp_trim_words( get_the_content( null, false, $forum_id ), $settings['word_length'] ) ); ?>
                </p>
            <?php endif; ?>
            <?php if ( ! empty( $settings['show_cover_badges'] ) ) : ?>
                <div class="bbpc-sf-grid-badges">
                    <span class="bbpc-sf-grid-badge">
                        <?php echo esc_html( bbp_get_forum_topic_count( $forum_id ) ); ?>
                        <?php esc_html_e( 'Topics', 'forumax' ); ?>
                    </span>
                    <span class="bbpc-sf-grid-badge">
                        <?php echo esc_html( bbp_get_forum_reply_count( $forum_id ) ); ?>
                        <?php esc_html_e( 'Replies', 'forumax' ); ?>
                    </span>
                </div>
            <?php endif; ?>
            <?php if ( ! empty( $settings['show_view_all'] ) ) : ?>
                <a href="<?php the_permalink( $forum_id ); ?>" class="bbpc-sf-grid-view-all">
                    <?php echo esc_html( $settings['read_more'] ); ?> &rarr;
                </a>
            <?php endif; ?>
        </div>
    </div>

    <div class="bbpc-sf-grid-topics">
        <?php
        if ( $topics->have_posts() ) :
            while ( $topics->have_posts() ) :
                $topics->the_post();
                $topic_id = get_the_ID();
                ?>
                <div class="bbpc-sf-grid-topic">
                    <h3>
                        <a href="<?php the_permalink(); ?>">
                            <?php the_title(); ?>
                        </a>
                    </h3>
                    <?php if ( ! empty( $settings['show_excerpt'] ) ) : ?>
                        <p><?php echo wp_kses_post( wp_trim_words( get_the_content(), 15 ) ); ?></p>
                    <?php endif; ?>
                    <div class="bbpc-sf-grid-meta">
                        <?php if ( ! empty( $settings['show_voice'] ) ) : ?>
                            <span>
                                <?php echo esc_html( bbp_get_topic_voice_count( $topic_id ) ); ?>
                                <?php esc_html_e( 'Voices', 'forumax' ); ?>
                            </span>
                        <?php endif; ?>
                        <?php if ( ! empty( $settings['show_replies'] ) ) : ?>
                            <span>
                                <?php bbp_topic_reply_count( $topic_id ); ?>
                                <?php esc_html_e( 'Replies', 'forumax' ); ?>
                            </span>
                        <?php endif; ?>
                        <?php if ( ! empty( $settings['show_freshness'] ) ) : ?>
                            <span>
                                <?php bbp_topic_last_active_time( $topic_id ); ?>
                            </span>
                        <?php endif; ?>
                    </div>
                </div>
                <?php
            endwhile;
            wp_reset_postdata();
        else :
            ?>
            <div class="bbpc-sf-grid-topic">
                <p class="mb-0"><?php esc_html_e( 'No topics found.', 'forumax' ); ?></p>
            </div>
        <?php endif; ?>
    </div>
</div>
