<?php 

get_header();

do_action( 'constructionarc_themes_enable_front_page' );

$enable_front_page = get_theme_mod( 'constructionarc_enable_frontpage', 'disable' );

if ( $enable_front_page === 'enable' || $enable_front_page === true ) {
    $constructionarc_home_sections = constructionarc_themes_homepage_section();
    
    if ( is_array( $constructionarc_home_sections ) && ! empty( $constructionarc_home_sections ) ) {
        // Whitelist of allowed sections for security
        $allowed_sections = array(
            'aboutus', 'blog', 'calltoaction', 'client', 'contact', 'counter',
            'customa', 'promoservice', 'recentwork', 'service', 'team',
            'testimonial', 'video_calltoaction'
        );

        foreach ( $constructionarc_home_sections as $constructionarc_homepage_section ) {
            $constructionarc_homepage_section = str_replace( 'constructionarc_', '', $constructionarc_homepage_section );
            $constructionarc_homepage_section = str_replace( '_section', '', $constructionarc_homepage_section );
            
            // Sanitize and validate section name
            $clean_section = sanitize_key( $constructionarc_homepage_section );
            
            if ( in_array( $clean_section, $allowed_sections, true ) ) {
                get_template_part( 'section/section', $clean_section );
            }
        }
    }
}

get_footer();