<?php


function howcan_customize_navbar($wp_customize) {

    // Section
    $wp_customize->add_section('howcan_navbar_section', array(
        'title'    => __('Navbar Settings', 'howcan'),
        'priority' => 3,
          'panel'    => 'howcan_theme_options_panel'
    ));

    // Show/Hide Navbar
    $wp_customize->add_setting('howcan_navbar_enable', array(
        'default'           => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('howcan_navbar_enable', array(
        'label'    => __('Enable Navbar', 'howcan'),
        'section'  => 'howcan_navbar_section',
        'type'     => 'checkbox',
    ));

    // Background Color
    $wp_customize->add_setting('howcan_navbar_bg_color', array(
        'default'           => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'howcan_navbar_bg_color', array(
        'label'    => __('Background Color', 'howcan'),
        'section'  => 'howcan_navbar_section',
    )));

    // Text Color
    $wp_customize->add_setting('howcan_navbar_text_color', array(
        'default'           => '#000000',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'howcan_navbar_text_color', array(
        'label'    => __('Text Color', 'howcan'),
        'section'  => 'howcan_navbar_section',
    )));

    // Font Size
    $wp_customize->add_setting('howcan_navbar_font_size', array(
        'default'           => '15px',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('howcan_navbar_font_size', array(
        'label'       => __('Font Size', 'howcan'),
        'section'     => 'howcan_navbar_section',
        'type'        => 'text',
        'description' => __('Example: 15px or 1rem', 'howcan'),
    ));
}
add_action('customize_register', 'howcan_customize_navbar');

function howcan_navbar_custom_styles() {
    if (!get_theme_mod('howcan_navbar_enable', true)) return;

    $bg    = esc_attr(get_theme_mod('howcan_navbar_bg_color', '#ffffff'));
    $color = esc_attr(get_theme_mod('howcan_navbar_text_color', '#000000'));
    $size  = esc_attr(get_theme_mod('howcan_navbar_font_size', '15px'));

    echo "<style>
        .navbar {
            background-color: {$bg} !important;
            font-size: {$size};
        }
        .navbar,
        .navbar * {
            color: {$color} !important;
        }
        .navbar a,
        .navbar .nav-link {
            color: {$color} !important;
        }
    </style>";
}
add_action('wp_head', 'howcan_navbar_custom_styles');


