<?php $fanspaysite_layout = get_theme_mod('fanspaysite_layout', 'left-sidebar'); ?>

<?php
$footer_cols = (int) get_theme_mod( 'fanspaysite_footer_columns', 1 );
if ( $footer_cols > 0 ) :
	$has_widgets = false;
	for ( $i = 1; $i <= $footer_cols; $i++ ) {
		if ( is_active_sidebar( 'fanspaysite_footer_' . $i ) ) {
			$has_widgets = true;
			break;
		}
	}
	if ( $has_widgets ) : ?>
	<div class="fps-footer-widgets" style="display:grid; grid-template-columns: repeat(<?php echo $footer_cols; ?>, 1fr); gap: var(--space-md, 16px);">
		<?php for ( $i = 1; $i <= $footer_cols; $i++ ) : ?>
			<div class="fps-footer-col">
				<?php if ( is_active_sidebar( 'fanspaysite_footer_' . $i ) ) : ?>
					<?php dynamic_sidebar( 'fanspaysite_footer_' . $i ); ?>
				<?php endif; ?>
			</div>
		<?php endfor; ?>
	</div>
	<?php endif; ?>
<?php endif; ?>

<footer id="colophon" class="site-footer" role="contentinfo">
	<?php if ( get_theme_mod( 'fanspaysite_show_copyright', true ) ) : ?>
	<div class="site-info">
		&copy; <?php echo esc_html( date( 'Y' ) ); ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>. <?php esc_html_e( 'All rights reserved.', 'fanspaysite' ); ?>
	</div>
	<?php endif; ?>
</footer>

</main><!-- .site-content -->

<?php if ($fanspaysite_layout === 'top-bar') : ?>
<!-- Top bar layout: right sidebar inside content wrapper, left widgets moved here -->
<aside class="site-sidebar-right">
	<?php if (is_active_sidebar('fanspaysite_left_sidebar')) : ?>
		<div class="sidebar-relocated-widgets">
			<?php dynamic_sidebar('fanspaysite_left_sidebar'); ?>
		</div>
	<?php endif; ?>
	<?php if (is_active_sidebar('fanspaysite_right_sidebar')) : ?>
		<?php dynamic_sidebar('fanspaysite_right_sidebar'); ?>
	<?php endif; ?>
</aside>
</div><!-- .site-content-wrapper -->

<?php else : ?>
<!-- Left sidebar layout: right sidebar outside content -->
<aside class="site-sidebar-right">
	<?php if (is_active_sidebar('fanspaysite_right_sidebar')) : ?>
		<?php dynamic_sidebar('fanspaysite_right_sidebar'); ?>
	<?php endif; ?>
</aside>

<?php endif; ?>

</div><!-- .site-wrapper -->

<?php
if ( get_background_image() ) : ?>
<style type="text/css">
    .site-content {
        background-image: url(<?php echo esc_url(get_background_image()); ?>);
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }
</style>
<?php endif; ?>
<?php wp_footer(); ?>
</body>
</html>
