<?php
/*
* Template Name: My account
*/
__('My account', 'irk');

global $options, $labels;
$account_url = $options->get_option('account-url');
$copyright = $options->get_option('copyright');
$footer_menu = $options->get_option('login-footer-menu');
$action = $_GET['account-action'] ?? 'login';

get_header();
if (is_user_logged_in()) {
    get_template_part('partials/main-header');
}
?>
    <main id="main" class="my-account-template">
        <div class="container">
            <?php if (!is_user_logged_in()): ?>
                <div class="logo-wrapper">
                    <a href="<?php echo esc_url(home_url()); ?>" title="<?php echo get_bloginfo('name'); ?>">
                        <?php echo irk_get_logo(); ?>
                    </a>
                </div>
            <?php endif; ?>
            <div class="row">
                <div class="post-container <?php echo is_user_logged_in() ? 'col-12' : 'col-12 col-md-8 col-lg-4 ' . $action; ?>">
                    <?php if (have_posts()): ?>
                        <?php while (have_posts()): ?>
                            <?php the_post(); ?>
                            <article <?php post_class('post-inner'); ?>>
                                <div class="post-body">
                                    <?php the_content(); ?>
                                </div>
                                <?php if (!is_user_logged_in() && $action): ?>
                                    <div class="footer">
                                        <?php if ($action == 'login'): ?>
                                            <span><?php echo esc_html($labels->get_label('new-user?')); ?></span>
                                            <a href="<?php echo esc_attr(add_query_arg(['account-action' => 'register'], $account_url)); ?>"><?php echo esc_html($labels->get_label('register-in-site')); ?></a>
                                        <?php endif; ?>
                                        <?php if ($action == 'register'): ?>
                                            <span><?php echo esc_html($labels->get_label('already-registered?')); ?></span>
                                            <a href="<?php echo esc_attr(add_query_arg(['account-action' => 'login'], $account_url)); ?>"><?php echo esc_html($labels->get_label('login-to-account')); ?></a>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                            </article>
                        <?php endwhile; ?>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </main>
<?php
if (is_user_logged_in()) {
    get_template_part('partials/main-footer');
} else {
    echo '<footer class="account-footer"><div class="container">';
    if (has_nav_menu($footer_menu)) {
        wp_nav_menu(array('theme_location' => $footer_menu, 'container' => ''));
    }
    echo $copyright ? '<div class="footer-copyright"><div class="container">' . str_replace('{{year}}', date('Y'), $copyright) . '</div></div>' : null;
    echo '</div></footer>';
}
get_footer();