<?php
// firefly-footer.php

function firefly_customize_footer_section($wp_customize) {
    // === Add a new section ===
    $wp_customize->add_section('firefly_footer_section', array(
        'title'       => __('Firefly Footer', 'firefly-theme'),
        'priority'    => 90,
        'description' => __('Customize the footer background, text color, and contact information.', 'firefly-theme'),
    ));


        // === Show Footer Checkbox ===
    $wp_customize->add_setting('firefly_footer_show', array(
        'default'           => false,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport'         => 'refresh',
    ));
    $wp_customize->add_control('firefly_footer_show_control', array(
        'label'    => __('Show Footer', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_show',
        'type'     => 'checkbox',
    ));


    // === Footer Logo ===
$wp_customize->add_setting('firefly_footer_logo', array(
    'default'           => '',
    'sanitize_callback' => 'esc_url_raw',
));

$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'firefly_footer_logo_control', array(
    'label'    => __('Footer Logo', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_logo',
)));



for ($i = 1; $i <= 6; $i++) {

    
    if ($i == 1) {
        $thisone = "Column 1 section 1";
    }
      if ($i == 2) {
        $thisone = "Column 1 section 2";
    }
      if ($i == 3) {
        $thisone = "Column 2 section 1";
    }
      if ($i == 4) {
        $thisone = "Column 2 section 2";
    }
      if ($i == 5) {
        $thisone = "Column 3 section 1";
    }
      if ($i == 6) {
        $thisone = "Column 3 section 2";
    }



    $wp_customize->add_setting("firefly_footer_heading_$i", [
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field',
    ]);
    $wp_customize->add_control("firefly_footer_heading_{$i}_control", [
        'label' => __("Heading $thisone", 'firefly-theme'),
        'section' => 'firefly_footer_section',
        'settings' => "firefly_footer_heading_$i",
        'type' => 'text',
    ]);

    $wp_customize->add_setting("firefly_footer_text_$i", [
        'default' => '',
        'sanitize_callback' => 'wp_kses_post',
    ]);



    $wp_customize->add_control("firefly_footer_text_{$i}_control", [
        'label' => __("Text for $thisone", 'firefly-theme'),
        'section' => 'firefly_footer_section',
        'settings' => "firefly_footer_text_$i",
        'type' => 'textarea',
    ]);
}

    // === Background Colour ===
    $wp_customize->add_setting('firefly_footer_background_color', array(
        'default'           => '#222222',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'firefly_footer_background_color_control', array(
        'label'    => __('Footer Background Colour', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_background_color',
    )));


        // === Text Colour ===
    $wp_customize->add_setting('firefly_footer_heading_color', array(
        'default'           => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'firefly_footer_heading_color_control', array(
        'label'    => __('Footer Heading Colour', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_heading_color',
    )));

        // === Text Colour ===
    $wp_customize->add_setting('firefly_footer_text_color', array(
        'default'           => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'firefly_footer_text_color_control', array(
        'label'    => __('Footer Text Colour', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_text_color',
    )));



            // === Text Colour ===
    $wp_customize->add_setting('firefly_footer_link_color', array(
        'default'           => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'firefly_footer_link_color_control', array(
        'label'    => __('Footer link Colour', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_link_color',
    )));

    // === Text Size (px) ===
$wp_customize->add_setting('firefly_footer_heading_size', array(
    'default' => '16px',
    'sanitize_callback' => function ($input) {
        return preg_match('/^\d{2}px$/', $input) ? $input : '16px';
    },
));

$wp_customize->add_control('firefly_footer_text_heading_size_control', array(
    'label'    => __('Heading Size (px)', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_heading_size',
    'type'     => 'select',
    'choices'  => array_combine(
        $sizes = array_map(function($i){ return "{$i}px"; }, range(12, 36)),
        $sizes
    ),
));


    // === Text Size (px) ===
$wp_customize->add_setting('firefly_footer_text_size', array(
    'default' => '16px',
    'sanitize_callback' => function ($input) {
        return preg_match('/^\d{2}px$/', $input) ? $input : '16px';
    },
));

$wp_customize->add_control('firefly_footer_text_size_control', array(
    'label'    => __('Text Size (px)', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_text_size',
    'type'     => 'select',
    'choices'  => array_combine(
        $sizes = array_map(function($i){ return "{$i}px"; }, range(12, 36)),
        $sizes
    ),
));






    // === Footer Map ===
  $wp_customize->add_setting('firefly_footer_map', array(
    'default'           => '',
    'sanitize_callback' => 'firefly_allow_iframe_only',
));

    $wp_customize->add_control('firefly_footer_map_control', array(
        'label'    => __('Map Embed Code or Address', 'firefly-theme'),
        'section'  => 'firefly_footer_section',
        'settings' => 'firefly_footer_map',
        'type'     => 'textarea',
    ));



    // === Footer Padding Left/Right ===
$wp_customize->add_setting('firefly_footer_padding_lr', array(
    'default' => '20px',
    'sanitize_callback' => function($input) {
        return preg_match('/^\d{1,3}px$/', $input) ? $input : '20px';
    },
));
$wp_customize->add_control('firefly_footer_padding_lr_control', array(
    'label' => __('Left/Right Padding', 'firefly-theme'),
    'section' => 'firefly_footer_section',
    'settings' => 'firefly_footer_padding_lr',
    'type' => 'select',
    'choices' => array_combine(
        $px = array_map(fn($i) => "{$i}px", range(0, 100)),
        $px
    ),
));



    // === Footer Padding Left/Right ===
$wp_customize->add_setting('firefly_footer_logo_padding_right', array(
    'default' => '20px',
    'sanitize_callback' => function($input) {
        return preg_match('/^\d{1,3}px$/', $input) ? $input : '20px';
    },
));
$wp_customize->add_control('firefly_footer_logo_padding_right_control', array(
    'label' => __('Space to right of logo', 'firefly-theme'),
    'section' => 'firefly_footer_section',
    'settings' => 'firefly_footer_logo_padding_right',
    'type' => 'select',
    'choices' => array_combine(
        $px = array_map(fn($i) => "{$i}px", range(0, 100)),
        $px
    ),
));

// === Logo Max Width ===
$wp_customize->add_setting('firefly_footer_logo_max_width', array(
    'default' => '200px',
    'sanitize_callback' => function($input) {
        return preg_match('/^\d{1,3}px$/', $input) ? $input : '200px';
    },
));
$wp_customize->add_control('firefly_footer_logo_max_width_control', array(
    'label' => __('Logo Max Width', 'firefly-theme'),
    'section' => 'firefly_footer_section',
    'settings' => 'firefly_footer_logo_max_width',
    'type' => 'select',
    'choices' => array_combine(
        $pw = array_map(fn($i) => "{$i}px", range(50, 600, 10)),
        $pw
    ),
));

// === Logo Alignment ===
$wp_customize->add_setting('firefly_footer_logo_align', array(
    'default' => 'left',
    'sanitize_callback' => function($input) {
        return in_array($input, ['left', 'center', 'right']) ? $input : 'left';
    },
));
$wp_customize->add_control('firefly_footer_logo_align_control', array(
    'label'    => __('Logo Alignment', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_logo_align',
    'type'     => 'radio',
    'choices'  => [
        'left'   => __('Left', 'firefly-theme'),
        'center' => __('Centre', 'firefly-theme'),
        'right'  => __('Right', 'firefly-theme'),
    ],
));

// === Heading Font Weight + Style ===
$wp_customize->add_setting('firefly_footer_heading_font_weight', array(
    'default'           => 'normal',
    'sanitize_callback' => function($input) {
        return in_array($input, ['normal', 'bold']) ? $input : 'normal';
    },
));
$wp_customize->add_control('firefly_footer_heading_font_weight_control', array(
    'label'    => __('Heading Font Weight', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_heading_font_weight',
    'type'     => 'radio',
    'choices'  => ['normal' => __('Normal', 'firefly-theme'), 'bold' => __('Bold', 'firefly-theme')],
));
$wp_customize->add_setting('firefly_footer_heading_font_style', array(
    'default'           => 'normal',
    'sanitize_callback' => function($input) {
        return in_array($input, ['normal', 'italic']) ? $input : 'normal';
    },
));
$wp_customize->add_control('firefly_footer_heading_font_style_control', array(
    'label'    => __('Heading Font Style', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_heading_font_style',
    'type'     => 'radio',
    'choices'  => ['normal' => __('Normal', 'firefly-theme'), 'italic' => __('Italic', 'firefly-theme')],
));

// === Body Text Font Weight + Style ===
$wp_customize->add_setting('firefly_footer_text_font_weight', array(
    'default'           => 'normal',
    'sanitize_callback' => function($input) {
        return in_array($input, ['normal', 'bold']) ? $input : 'normal';
    },
));
$wp_customize->add_control('firefly_footer_text_font_weight_control', array(
    'label'    => __('Body Text Font Weight', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_text_font_weight',
    'type'     => 'radio',
    'choices'  => ['normal' => __('Normal', 'firefly-theme'), 'bold' => __('Bold', 'firefly-theme')],
));
$wp_customize->add_setting('firefly_footer_text_font_style', array(
    'default'           => 'normal',
    'sanitize_callback' => function($input) {
        return in_array($input, ['normal', 'italic']) ? $input : 'normal';
    },
));
$wp_customize->add_control('firefly_footer_text_font_style_control', array(
    'label'    => __('Body Text Font Style', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_text_font_style',
    'type'     => 'radio',
    'choices'  => ['normal' => __('Normal', 'firefly-theme'), 'italic' => __('Italic', 'firefly-theme')],
));

// === Font Family choices (mirrors firefly_get_google_fonts from menu plugin) ===
$footer_font_choices = [
    // System
    'Arial, sans-serif'        => 'Arial (system)',
    'Courier New, monospace'   => 'Courier New (system)',
    'Georgia, serif'           => 'Georgia (system)',
    'Tahoma, sans-serif'       => 'Tahoma (system)',
    'Times New Roman, serif'   => 'Times New Roman (system)',
    'Trebuchet MS, sans-serif' => 'Trebuchet MS (system)',
    'Verdana, sans-serif'      => 'Verdana (system)',
    // Google — alphabetical
    'Archivo Narrow, sans-serif'     => 'Archivo Narrow',
    'Arvo, serif'                    => 'Arvo',
    'Barlow, sans-serif'             => 'Barlow',
    'Bitter, serif'                  => 'Bitter',
    'Bodoni Moda, serif'             => 'Bodoni Moda',
    'Cabin, sans-serif'              => 'Cabin',
    'Cormorant Garamond, serif'      => 'Cormorant Garamond',
    'Crimson Pro, serif'             => 'Crimson Pro',
    'DM Sans, sans-serif'            => 'DM Sans',
    'DM Serif Display, serif'        => 'DM Serif Display',
    'Dosis, sans-serif'              => 'Dosis',
    'Exo 2, sans-serif'              => 'Exo 2',
    'Fira Sans, sans-serif'          => 'Fira Sans',
    'Fjalla One, sans-serif'         => 'Fjalla One',
    'Francois One, sans-serif'       => 'Francois One',
    'Fraunces, serif'                => 'Fraunces',
    'Hind, sans-serif'               => 'Hind',
    'IBM Plex Sans, sans-serif'      => 'IBM Plex Sans',
    'Inter, sans-serif'              => 'Inter',
    'Josefin Sans, sans-serif'       => 'Josefin Sans',
    'Kanit, sans-serif'              => 'Kanit',
    'Karla, sans-serif'              => 'Karla',
    'Lato, sans-serif'               => 'Lato',
    'Lexend, sans-serif'             => 'Lexend',
    'Libre Baskerville, serif'       => 'Libre Baskerville',
    'Manrope, sans-serif'            => 'Manrope',
    'Merriweather, serif'            => 'Merriweather',
    'Montserrat, sans-serif'         => 'Montserrat',
    'Mulish, sans-serif'             => 'Mulish',
    'Muli, sans-serif'               => 'Muli',
    'Nunito, sans-serif'             => 'Nunito',
    'Open Sans, sans-serif'          => 'Open Sans',
    'Oswald, sans-serif'             => 'Oswald',
    'Outfit, sans-serif'             => 'Outfit',
    'Playfair Display, serif'        => 'Playfair Display',
    'Plus Jakarta Sans, sans-serif'  => 'Plus Jakarta Sans',
    'Poppins, sans-serif'            => 'Poppins',
    'Prompt, sans-serif'             => 'Prompt',
    'Quicksand, sans-serif'          => 'Quicksand',
    'Rajdhani, sans-serif'           => 'Rajdhani',
    'Raleway, sans-serif'            => 'Raleway',
    'Roboto, sans-serif'             => 'Roboto',
    'Roboto Condensed, sans-serif'   => 'Roboto Condensed',
    'Rubik, sans-serif'              => 'Rubik',
    'Saira Condensed, sans-serif'    => 'Saira Condensed',
    'Source Sans Pro, sans-serif'    => 'Source Sans Pro',
    'Source Serif 4, serif'          => 'Source Serif 4',
    'Space Grotesk, sans-serif'      => 'Space Grotesk',
    'Spectral, serif'                => 'Spectral',
    'Teko, sans-serif'               => 'Teko',
    'Titillium Web, sans-serif'      => 'Titillium Web',
    'Ubuntu, sans-serif'             => 'Ubuntu',
    'Urbanist, sans-serif'           => 'Urbanist',
    'Varela Round, sans-serif'       => 'Varela Round',
    'Work Sans, sans-serif'          => 'Work Sans',
    'Yanone Kaffeesatz, sans-serif'  => 'Yanone Kaffeesatz',
];

// === Heading Font Family ===
$wp_customize->add_setting('firefly_footer_heading_font_family', array(
    'default'           => 'Arial, sans-serif',
    'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('firefly_footer_heading_font_family_control', array(
    'label'    => __('Heading Font Family', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_heading_font_family',
    'type'     => 'select',
    'choices'  => $footer_font_choices,
));

// === Body Text Font Family ===
$wp_customize->add_setting('firefly_footer_text_font_family', array(
    'default'           => 'Arial, sans-serif',
    'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('firefly_footer_text_font_family_control', array(
    'label'    => __('Body Text Font Family', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_text_font_family',
    'type'     => 'select',
    'choices'  => $footer_font_choices,
));



// === Footer Line Height ===
$wp_customize->add_setting('firefly_footer_line_height', array(
    'default' => '150%',
    'sanitize_callback' => function($input) {
        return preg_match('/^\d{3}%$/', $input) ? $input : '150%';
    },
));
$wp_customize->add_control('firefly_footer_line_height_control', array(
    'label' => __('Line Height', 'firefly-theme'),
    'section' => 'firefly_footer_section',
    'settings' => 'firefly_footer_line_height',
    'type' => 'select',
    'choices' => array_combine(
        $lh = array_map(fn($i) => "{$i}%", range(100, 300, 5)),
        $lh
    ),
));

// === Space Below Headings ===
$wp_customize->add_setting('firefly_footer_heading_margin_bottom', array(
    'default' => '15px',
    'sanitize_callback' => function($input) {
        return preg_match('/^\d{1,2}px$/', $input) ? $input : '15px';
    },
));
$wp_customize->add_control('firefly_footer_heading_margin_bottom_control', array(
    'label' => __('Space Below Heading', 'firefly-theme'),
    'section' => 'firefly_footer_section',
    'settings' => 'firefly_footer_heading_margin_bottom',
    'type' => 'select',
    'choices' => array_combine(
        $mb = array_map(fn($i) => "{$i}px", range(0, 50, 2)),
        $mb
    ),
));


// === Display Logo Column Option ===
$wp_customize->add_setting('firefly_footer_logo_column', [
    'default'           => 'none',
    'sanitize_callback' => function ($input) {
        return in_array($input, ['col1', 'col2', 'col3', 'none']) ? $input : 'none';
    },
]);
$wp_customize->add_control('firefly_footer_logo_column_control', [
    'label'    => __('Display logo in:', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_logo_column',
    'type'     => 'radio',
    'choices'  => [
        'col1' => __('Column 1', 'firefly-theme'),
        'col2' => __('Column 2', 'firefly-theme'),
        'col3' => __('Column 3', 'firefly-theme'),
        'none' => __("Don't show", 'firefly-theme'),
    ],
]);

// === Display Map Column Option ===
$wp_customize->add_setting('firefly_footer_map_column', [
    'default'           => 'none',
    'sanitize_callback' => function ($input) {
        return in_array($input, ['col1', 'col2', 'col3', 'none']) ? $input : 'none';
    },
]);
$wp_customize->add_control('firefly_footer_map_column_control', [
    'label'    => __('Display map in:', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_map_column',
    'type'     => 'radio',
    'choices'  => [
        'col1' => __('Column 1', 'firefly-theme'),
        'col2' => __('Column 2', 'firefly-theme'),
        'col3' => __('Column 3', 'firefly-theme'),
        'none' => __("Don't show", 'firefly-theme'),
    ],
]);

// === Display Search Column Option ===
// Note: firefly_footer_show_search controls the bottom bar search (different footer area).
// This setting controls a search bar placed inside one of the three main footer columns.
$wp_customize->add_setting('firefly_footer_search_column', [
    'default'           => 'none',
    'sanitize_callback' => function ($input) {
        return in_array($input, ['col1', 'col2', 'col3', 'none']) ? $input : 'none';
    },
]);
$wp_customize->add_control('firefly_footer_search_column_control', [
    'label'    => __('Show search in:', 'firefly-theme'),
    'section'  => 'firefly_footer_section',
    'settings' => 'firefly_footer_search_column',
    'type'     => 'radio',
    'choices'  => [
        'col1' => __('Column 1', 'firefly-theme'),
        'col2' => __('Column 2', 'firefly-theme'),
        'col3' => __('Column 3', 'firefly-theme'),
        'none' => __("Don't show", 'firefly-theme'),
    ],
]);


}

add_action('customize_register', 'firefly_customize_footer_section');



function firefly_allow_iframe_only($input) {
    return wp_kses($input, array(
        'iframe' => array(
            'src' => true,
            'width' => true,
            'height' => true,
            'frameborder' => true,
            'style' => true,
            'allowfullscreen' => true,
        )
    ));
}



function firefly_render_custom_footer() {

  

if (get_theme_mod('firefly_footer_show')) : 
    
    $footer_text_size = get_theme_mod('firefly_footer_text_size', '12px');
    $footer_heading_size = get_theme_mod('firefly_footer_heading_size', '18px');

    $bg_color = get_theme_mod('firefly_footer_background_color', '#222');
    $footer_text_color = get_theme_mod('firefly_footer_text_color', '#fff');
    $footer_heading_color = get_theme_mod('firefly_footer_heading_color', '#fff');
    $footer_link_color = get_theme_mod('firefly_footer_link_color', '#fff');
    $hours = get_theme_mod('firefly_footer_hours');
    $contact = get_theme_mod('firefly_footer_contact');
    $map = get_theme_mod('firefly_footer_map'); // accepts iframe

    $padding_lr = get_theme_mod('firefly_footer_padding_lr', '20px');
$line_height = get_theme_mod('firefly_footer_line_height', '150%');
$heading_margin = get_theme_mod('firefly_footer_heading_margin_bottom', '15px');

$firefly_footer_logo = get_theme_mod('firefly_footer_logo', '');
$logo_col = get_theme_mod('firefly_footer_logo_column', 'none');
$map = get_theme_mod('firefly_footer_map', '');
$map_col = get_theme_mod('firefly_footer_map_column', 'none');
$search_col = get_theme_mod('firefly_footer_search_column', 'none');
$firefly_footer_logo_padding_right = get_theme_mod('firefly_footer_logo_padding_right', '');
$footer_logo_max_width  = get_theme_mod('firefly_footer_logo_max_width', '200px');
$footer_logo_align      = get_theme_mod('firefly_footer_logo_align', 'left');
$footer_heading_weight  = get_theme_mod('firefly_footer_heading_font_weight', 'normal');
$footer_heading_style   = get_theme_mod('firefly_footer_heading_font_style', 'normal');
$footer_text_weight     = get_theme_mod('firefly_footer_text_font_weight', 'normal');
$footer_text_style      = get_theme_mod('firefly_footer_text_font_style', 'normal');
$footer_show_search     = get_theme_mod('firefly_footer_show_search', false);
$footer_heading_family  = get_theme_mod('firefly_footer_heading_font_family', 'Arial, sans-serif');
$footer_text_family     = get_theme_mod('firefly_footer_text_font_family', 'Arial, sans-serif');

?>

<?php
// Enqueue any Google Fonts selected for heading/text (skip system fonts)
$_footer_system_fonts = ['Arial','Courier New','Georgia','Tahoma','Times New Roman','Trebuchet MS','Verdana'];
$_footer_gfonts = [];
foreach ([$footer_heading_family, $footer_text_family] as $_ff) {
    $_name = trim(explode(',', $_ff)[0]);
    if (!in_array($_name, $_footer_system_fonts, true)) {
        $_footer_gfonts[$_name] = true;
    }
}
if (!empty($_footer_gfonts)) {
    $_params = [];
    foreach (array_keys($_footer_gfonts) as $_fn) {
        $_params[] = 'family=' . rawurlencode($_fn) . ':wght@300;400;500;600;700;800;900';
    }
    echo '<link rel="preconnect" href="https://fonts.googleapis.com">' . "\n";
    echo '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . "\n";
    echo '<link rel="stylesheet" href="' . esc_url('https://fonts.googleapis.com/css2?' . implode('&', $_params) . '&display=swap') . '">' . "\n";
}
?>

<style>
.firefly-footer {
    background-color: <?php echo esc_attr($bg_color); ?>;
    color: <?php echo esc_attr($text_color); ?>;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: <?php echo $padding_lr; ?>;
    padding-right: <?php echo $padding_lr; ?>;
    font-family: Arial, sans-serif;
}

.firefly-footer .footer-columns {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 20px;
    max-width: 1200px;
    margin: auto;
}

.firefly-footer .footer-column {
    flex: 1 1 30%;
    min-width: 250px;
    max-width: 320px;
}

/* Center column 2 */
.firefly-footer .footer-column:nth-child(2) {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

/* Optional: tweak first and third for symmetry if needed */
/*
.firefly-footer .footer-column:first-child {
    text-align: left;
}
.firefly-footer .footer-column:last-child {
    text-align: right;
}
*/

.firefly-footer .footer-column h3 {
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-size: 1.2em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.firefly-footer .footer-column p {
    margin: 0 0 10px 0;
    line-height: 1.6;
}

.firefly-footer iframe {
    width: 100%;
    height: 200px;
    border: none;
}

.firefly-footer,
.firefly-footer h3,
.firefly-footer p,
.firefly-footer a {
    color: <?php echo esc_attr($text_color); ?> !important;
}

.footer-heading {
    font-size: <?php echo $footer_heading_size; ?>;
    color: <?php echo $footer_heading_color; ?>;
    line-height: <?php echo $line_height; ?>;
    margin-bottom: <?php echo $heading_margin; ?>;
    font-weight: <?php echo esc_attr($footer_heading_weight); ?>;
    font-style: <?php echo esc_attr($footer_heading_style); ?>;
    font-family: <?php echo esc_attr($footer_heading_family); ?>;
    text-align: left;
}


.footer-text {
    font-size: <?php echo $footer_text_size; ?>;
    color: <?php echo $footer_text_color; ?>;
    line-height: <?php echo $line_height; ?>;
    margin-bottom: 10px;
    font-weight: <?php echo esc_attr($footer_text_weight); ?>;
    font-style: <?php echo esc_attr($footer_text_style); ?>;
    font-family: <?php echo esc_attr($footer_text_family); ?>;
    text-align: left;
}

.footer-text a {
    color: <?php echo $footer_link_color; ?> !important;
}

.footer-text a:hover {
   text-decoration:underline !important;
}


.firefly-footer-bar {
    background-color: <?php echo esc_attr($bg_color); ?>;
    border-top: 1px solid rgba(255,255,255,0.15);
    padding: 10px <?php echo $padding_lr; ?>;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.firefly-footer-bar a,
.firefly-footer-bar span {
    color: <?php echo esc_attr($footer_text_color); ?> !important;
    font-size: <?php echo $footer_text_size; ?>;
    text-decoration: none;
}

.firefly-footer-bar a:hover {
    text-decoration: underline;
}

.firefly-footer-search {
    display: flex;
    align-items: center;
    gap: 4px;
}

.firefly-footer-search input[type="search"] {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 3px;
    color: <?php echo esc_attr($footer_text_color); ?>;
    font-size: <?php echo $footer_text_size; ?>;
    padding: 4px 8px;
    outline: none;
    width: 160px;
}

.firefly-footer-search input[type="search"]::placeholder {
    color: rgba(255,255,255,0.5);
}

.firefly-footer-search button {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 3px;
    color: <?php echo esc_attr($footer_text_color); ?>;
    cursor: pointer;
    font-size: <?php echo $footer_text_size; ?>;
    padding: 4px 10px;
}

.firefly-footer-search button:hover {
    background: rgba(255,255,255,0.25);
}

.firefly-footer-col-search {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 10px;
}

.firefly-footer-col-search input[type="search"] {
    flex: 1;
    min-width: 0;
}

@media (max-width: 768px) {
    .firefly-footer .footer-columns {
        flex-direction: column;
        align-items: left;
    }

    .firefly-footer .footer-column {
        width: 100%;
        max-width: 600px;
        text-align: left;
    }
}
</style>


<footer class="firefly-footer">
    <div class="footer-columns">

       <?php





$columns = [];
for ($i = 1; $i <= 6; $i++) {
    $columns[] = [
        'heading' => get_theme_mod("firefly_footer_heading_$i", ''),
        'text'    => get_theme_mod("firefly_footer_text_$i", ''),
    ];
}


?>

<div class="footer-columns">
   <?php for ($col = 0; $col < 3; $col++) : ?>
    <div class="footer-column">
        <?php
        $column_id = 'col' . ($col + 1);

        // Display logo if assigned to this column
        if ($firefly_footer_logo && $logo_col === $column_id) {
            echo '<div style="text-align:' . esc_attr($footer_logo_align) . ';margin:0;padding:0;">'
                . '<img src="' . esc_url($firefly_footer_logo) . '" style="max-width:' . esc_attr($footer_logo_max_width) . ';height:auto;display:inline-block;margin:0 0 15px 0;padding-right:' . esc_attr($firefly_footer_logo_padding_right) . ';"></div>';
        }

        // Display map if assigned to this column
        if ($map && $map_col === $column_id) {
          
            echo '<div class="footer-text">' . $map . '</div>';
        }

        // Display search bar if assigned to this column
        if ($search_col === $column_id) {
            echo '<form class="firefly-footer-search firefly-footer-col-search" role="search" method="get" action="' . esc_url(home_url('/')) . '">'
               . '<input type="search" name="s" placeholder="' . esc_attr__('Search...', 'firefly-theme') . '" value="' . esc_attr(get_search_query()) . '">'
               . '<button type="submit">&#128269;</button>'
               . '</form>';
        }

        // Output two heading/text blocks
        for ($row = 0; $row < 2; $row++) :
            $index = ($col * 2) + $row;
            if (!empty($columns[$index]['heading']) || !empty($columns[$index]['text'])) :
                echo '<div class="footer-heading">' . esc_html($columns[$index]['heading']) . '</div>';
                echo '<div class="footer-text">' . wp_kses_post(nl2br($columns[$index]['text'])) . '</div>';
            endif;
        endfor;
        ?>
    </div>
<?php endfor; ?>

</div>


    </div></footer>



<?php endif; 
}
add_action('wp_footer', 'firefly_render_custom_footer', 1); // Priority 99 to render near end
?>
