<?php

/**
 * Single Forum Content Part
 *
 * @package bbPress
 * @subpackage Theme
 */

// Exit if accessed directly
defined('ABSPATH') || exit;

$has_sidebar = is_active_sidebar('forum_archive_sidebar');
$main_column = $has_sidebar ? '8' : '12';
?>
<div class="frmx-row frmx-sidebar-<?php echo esc_attr(forumax_get_opt('sidebar_position', 'right')); ?>">
    <div class="frmx-col-lg-<?php echo esc_attr($main_column); ?>">

        <?php do_action('bbp_template_before_single_forum'); ?>

        <?php if (post_password_required()): ?>

            <?php bbp_get_template_part('form', 'protected'); ?>

        <?php else: ?>

            <div class="frmx-forum-description-row">
                <div class="frmx-forum-description-text">
                    <?php bbp_single_forum_description(); ?>
                </div>
                <?php if ( bbp_is_subscriptions_active() ) : ?>
                    <div class="frmx-forum-subscription-action">
                        <?php if ( is_user_logged_in() ) : ?>
                            <span id="subscription-toggle">
                                <?php
                                bbp_forum_subscription_link( array(
                                    'before'      => '',
                                    'after'       => '',
                                    'subscribe'   => esc_html__( 'Subscribe', 'forumax' ),
                                    'unsubscribe' => esc_html__( 'Subscribed', 'forumax' ),
                                ) );
                                ?>
                            </span>
                        <?php else : ?>
                            <?php if ( forumax_get_opt( 'is_forum_subscription', '1' ) == 1 ) : ?>
                                <span id="subscription-toggle">
                                    <a class="subscription-login-btn">
                                        <?php echo esc_html( forumax_get_opt( 'logout_forum_subscription_btn', __( 'Subscribe', 'forumax' ) ) ); ?>
                                    </a>
                                </span>
                                <span class="subscription-login-modal">
                                    <span class="subscription-login-modal-inner">
                                        <span class="subscription-login-modal-close">&times;</span>
                                        <h2><?php echo esc_html( forumax_get_opt( 'forum_subscription_modal_title', __( 'Login to the community', 'forumax' ) ) ); ?></h2>
                                        <p><?php echo esc_html( forumax_get_opt( 'forum_subscription_modal_subtitle', __( 'You must be logged in to subscribe to this forum.', 'forumax' ) ) ); ?></p>
                                        <div class="frmx-subscription-login-form">
                                            <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form">
                                                <fieldset class="bbp-form">
                                                    <legend><?php esc_html_e( 'Log In', 'forumax' ); ?></legend>

                                                    <div class="bbp-username">
                                                        <label for="frmx-forum-sub-user-login"><?php esc_html_e( 'Username', 'forumax' ); ?>: </label>
                                                        <input type="text" name="log" value="" size="20" maxlength="100" id="frmx-forum-sub-user-login" placeholder="<?php esc_attr_e( 'Username or Email', 'forumax' ); ?>" autocomplete="off" />
                                                    </div>

                                                    <div class="bbp-password">
                                                        <label for="frmx-forum-sub-user-pass"><?php esc_html_e( 'Password', 'forumax' ); ?>: </label>
                                                        <input type="password" name="pwd" value="" size="20" id="frmx-forum-sub-user-pass" placeholder="<?php esc_attr_e( 'Password', 'forumax' ); ?>" autocomplete="off" />
                                                    </div>

                                                    <div class="bbp-remember-me">
                                                        <input type="checkbox" name="rememberme" value="forever" id="frmx-forum-sub-rememberme" />
                                                        <label for="frmx-forum-sub-rememberme"><?php esc_html_e( 'Keep me signed in', 'forumax' ); ?></label>
                                                    </div>

                                                    <?php do_action( 'login_form' ); ?>

                                                    <div class="bbp-submit-wrapper">
                                                        <button type="submit" name="user-submit" id="frmx-forum-sub-user-submit" class="button submit user-submit fill-brand"><?php esc_html_e( 'Log In', 'forumax' ); ?></button>
                                                        <?php bbp_user_login_fields(); ?>
                                                    </div>
                                                </fieldset>
                                            </form>
                                        </div>
                                    </span>
                                </span>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>

            <?php if (bbp_has_forums()): ?>

                <?php bbp_get_template_part('loop', 'forums'); ?>

            <?php endif; ?>

            <?php if (!bbp_is_forum_category() && bbp_has_topics()): ?>

                <?php bbp_get_template_part('loop', 'topics'); ?>

                <?php bbp_get_template_part('form', 'topic'); ?>

            <?php elseif (!bbp_is_forum_category()): ?>

                <?php bbp_get_template_part('form', 'topic'); ?>

            <?php endif; ?>

        <?php endif; ?>

        <?php do_action('bbp_template_after_single_forum'); ?>
    </div>

    <?php if ($has_sidebar): ?>
        <div class="frmx-col-lg-4">
            <aside class="forum-sidebar">
                <?php dynamic_sidebar('forum_archive_sidebar'); ?>
            </aside>
        </div>
    <?php endif; ?>
</div>