<?php
/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function bblog_content_width() {
  $GLOBALS['content_width'] = apply_filters( 'bblog_content_width', 640 );
}
add_action( 'after_setup_theme', 'bblog_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function bblog_widgets_init() {
  register_sidebar(
    array(
      'name'          => esc_html__( 'Sidebar', 'bblog' ),
      'id'            => 'sidebar-1',
      'description'   => esc_html__( 'Add widgets here.', 'bblog' ),
      'before_widget' => '<section id="%1$s" class="widget %2$s">',
      'after_widget'  => '</section>',
      'before_title'  => '<h2 class="widget-title">',
      'after_title'   => '</h2>',
    )
  );
}
add_action( 'widgets_init', 'bblog_widgets_init' );


/**
 * Display admin notice when theme is activated or themes page is loaded
 */
function bblog_admin_notice() {
    // Get current screen
    $screen = get_current_screen();

    // Check if we're on the themes page
    if ($screen && ($screen->id === 'themes' || $screen->id === 'dashboard')) {
        $theme_activated = isset($_GET['activated']) && $_GET['activated'] == 'true';

        // Get theme screenshot URL
        $theme = wp_get_theme();
        $screenshot = $theme->get_screenshot();

        // Start output buffering to build our notice
        ob_start();
        ?>
        <div class="notice notice-success is-dismissible bblog-welcome-notice">
            <div class="bblog-welcome-content" style="display: flex; align-items: center; padding: 15px 0;">
                <?php if ($screenshot) : ?>
                    <div class="bblog-screenshot" style="margin-right: 20px; flex: 0 0 200px;">
                        <img src="<?php echo esc_url($screenshot); ?>" style="max-width: 100%; height: auto; border: 1px solid #ddd;">
                    </div>
                <?php endif; ?>

                <div class="bblog-welcome-text">
                    <h2><?php echo $theme_activated ? 'Welcome! Thank you for choosing ' . esc_html($theme->get('Name')) . '!' : 'Welcome! Thank you for choosing ' . esc_html($theme->get('Name')). ' theme. ' ?> </h2>

                    <p><?php echo esc_html__("We're delighted to have you on board. To make the most of your experience and unlock all the features this theme offers, explore the customization options and start building your site today.", "bblog");?></p>

                    <div class="bblog-links" style="margin-top: 15px;">
                        <a href="mailto:kader.webdev@gmail.com" class="button button-primary" target="_blank"><?php echo esc_html__('Send email', 'bblog');?></a>
                        <a href="/wp-admin/customize.php" class="button" target="_blank" style="margin-left: 10px;"><?php echo esc_html__('Settings', 'bblog');?></a>
                    </div>
                </div>
            </div>
        </div>
        <?php
        // Get the buffered content
        $notice = ob_get_clean();
        echo $notice;
    }
}
add_action('admin_notices', 'bblog_admin_notice');