<?php
/**
 * Widget areas registration
 */

if (!defined('ABSPATH')) exit;

function wpbs_widgets_init() {
    // Footer widget areas
    $columns = get_theme_mod('wpbs_footer_columns', '3');
    
    for ($i = 1; $i <= (int) $columns; $i++) {
        register_sidebar([
            'name'          => sprintf(__('Footer Column %d', 'wpbs-theme'), $i),
            'id'            => 'footer-' . $i,
            'description'   => sprintf(__('Footer widget area column %d', 'wpbs-theme'), $i),
            'before_widget' => '<div id="%1$s" class="widget mb-4 %2$s">',
            'after_widget'  => '</div>',
            'before_title'  => '<h4 class="widget-title">',
            'after_title'   => '</h4>',
        ]);
    }
    
    // Register up to 4 regardless (in case user changes column count later)
    for ($i = (int) $columns + 1; $i <= 4; $i++) {
        register_sidebar([
            'name'          => sprintf(__('Footer Column %d', 'wpbs-theme'), $i),
            'id'            => 'footer-' . $i,
            'description'   => sprintf(__('Footer widget area column %d (activate by increasing footer columns in Customizer)', 'wpbs-theme'), $i),
            'before_widget' => '<div id="%1$s" class="widget mb-4 %2$s">',
            'after_widget'  => '</div>',
            'before_title'  => '<h4 class="widget-title">',
            'after_title'   => '</h4>',
        ]);
    }
}
add_action('widgets_init', 'wpbs_widgets_init');
