<?php 
function howcan_topbar($wp_customize) {

    // Section
    $wp_customize->add_section('howcan_topbar_section', array(
        'title'    => __('Topbar Settings', 'howcan'),
        'priority' => 2,
          'panel'    => 'howcan_theme_options_panel',
    ));

    // Enable/Disable Toggle
    $wp_customize->add_setting('howcan_topbar_enable', array(
        'default'           => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));

    $wp_customize->add_control('howcan_topbar_enable', array(
        'label'    => __('Enable Topbar', 'howcan'),
        'section'  => 'howcan_topbar_section',
        'type'     => 'checkbox',
    ));

    // Background Color
    $wp_customize->add_setting('howcan_topbar_bg_color', array(
        'default'           => '#f8f9fa',
        'sanitize_callback' => 'sanitize_hex_color',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'howcan_topbar_bg_color', array(
        'label'    => __('Background Color', 'howcan'),
        'section'  => 'howcan_topbar_section',
    )));

    // Text Color
    $wp_customize->add_setting('howcan_topbar_text_color', array(
        'default'           => '#212529',
        'sanitize_callback' => 'sanitize_hex_color',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'howcan_topbar_text_color', array(
        'label'    => __('Text Color', 'howcan'),
        'section'  => 'howcan_topbar_section',
    )));

    // Font Size
    $wp_customize->add_setting('howcan_topbar_font_size', array(
        'default'           => '14px',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('howcan_topbar_font_size', array(
        'label'       => __('Font Size', 'howcan'),
        'section'     => 'howcan_topbar_section',
        'type'        => 'text',
        'description' => __('Example: 14px or 1rem', 'howcan'),
    ));
}
add_action('customize_register', 'howcan_topbar');


function howcan_topbar_custom_styles() {
    if (!get_theme_mod('howcan_topbar_enable', true)) return;

    $bg    = esc_attr(get_theme_mod('howcan_topbar_bg_color', '#f8f9fa'));
    $color = esc_attr(get_theme_mod('howcan_topbar_text_color', '#212529'));
    $size  = esc_attr(get_theme_mod('howcan_topbar_font_size', '14px'));

    echo "<style>
        .topbar {
            background-color: {$bg};
            font-size: {$size};
        }

        .topbar,
        .topbar * {
            color: {$color} !important;
        }

        .topbar a {
            color: {$color} !important;
        }
    </style>";
}
add_action('wp_head', 'howcan_topbar_custom_styles');

