<?php
    /**
     * Template part for reordering sections in frontpage || home || blog
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
     *
     * @package Blog Bee
     * @since 1.0.0
     */
    use BBE\Customizer\Section\Web_Stories as Web_Stories;
    use BBE\Customizer\Section\Main_Banner as Main_Banner;
    use BBE\Customizer\Section\Carousel as Carousel;
    use BBE\Customizer\Section\Category_Collection as Category_Collection;
    use BBE\Customizer\Section\Three_Blocks as Three_Blocks;
    use BBE\Customizer\Section\Post_Grid as Post_Grid;
    use BBE\Customizer\Section\Post_List as Post_List;
    use BBE\Customizer\Section\Frontpage_ShortCode_One as Frontpage_ShortCode_One;
    use BBE\Customizer\Section\Frontpage_Widget_Area_One as Frontpage_Widget_Area_One;
    use BBE\Customizer\Section\Content_Sidebar as Content_Sidebar;
    use BBE\Customizer\Section\Hover_Effects as Hover_Effects;
    use BBE\Customizer\Section\You_May_Have_Missed as You_May_Have_Missed;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;
    use BBE\Helpers as Helpers;

    $default = isset( $args[ 'default' ] ) ? $args[ 'default' ] : '';

    $section_reorder = Theme_Defaults::get_theme_option( 'section_reorder_fields' );

    $is_first = false;

    if( ! empty( $section_reorder ) && is_array( $section_reorder ) ) {

        echo '<div class="bbe-sections-wrap" '. Hover_Effects::get_instance()->get_aos_data_attributes() .'>';

            foreach( $section_reorder as $index => $section ) {
                
                if( ! $section[ 'value' ] ) continue;
                
                if( ! $is_first ) {
                    $is_first = true;
                    if( $section[ 'id' ] !== 'latest' ) add_filter( 'blog_bee_thumbnail_attr_filters', [ Helpers::class, 'add_fetchpriority_high' ] );
                }
                
                switch( $section[ 'id' ] ) {
                    case 'web-stories':
                            Web_Stories::get_instance()->render_html();
                        break;
                    case 'main-banner':
                            Main_Banner::get_instance()->render_html();
                        break;
                    case 'carousel':
                            Carousel::get_instance()->render_html();
                        break;
                    case 'category-collection':
                            Category_Collection::get_instance()->render_html();
                        break;
                    case 'three-blocks':
                            Three_Blocks::get_instance()->render_html();
                        break;
                    case 'post-grid':
                            Post_Grid::get_instance()->render_html();
                        break;
                    case 'post-list':
                            Post_List::get_instance()->render_html();
                        break;
                    case 'shortcode-one':
                            Frontpage_ShortCode_One::get_instance()->render_html();
                        break;
                    case 'widget-one':
                            Frontpage_Widget_Area_One::get_instance()->render_html();
                        break;
                    case 'widget-two':
                            Frontpage_Widget_Area_Two::get_instance()->render_html();
                        break;
                    case 'content-sidebar':
                            Content_Sidebar::get_instance()->render_html();
                        break;
                    case 'latest':
                            echo $default;
                        break;
                }

            }

            if( ! is_single() && ( is_home() || is_front_page() ) ) You_May_Have_Missed::get_instance()->render_html();

        echo '</div><!-- .bbe-sections-wrap -->';
        
    }