<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Always
 * @since 1.0.0
 */
get_header(); ?>

<?php if ( is_paged() || is_archive() || is_search()) { ?>
    <!-- blog section -->

    <div class="wrapper">

        <div class="theme-panelarea theme-panelarea-blocks">
            
            <?php
            if (!is_front_page()) { ?>

                <div id="site-contentarea" class="theme-panel-blocks theme-header-panel archive-breadcrumb-panel">
                    <div class="theme-panel-header">

                        <?php always_breadcrumb(); ?>
                        <?php always_archive_title(); ?>

                    </div>
                </div>
            
            <?php }

            
            
            if (have_posts()):

                $i = 1;
                while (have_posts()) :
                    the_post();

                    ?>
                    <div class="theme-panel-blocks article-panel-blocks theme-article-main">

                    <?php

                    if( is_front_page() ){

                        if( $i == 1 ){

                            ?><div id="site-contentarea"></div><?php

                        }

                    }
                    
                    get_template_part('template-parts/content', get_post_format());

                    ?></div><?php

                    $i++;
                endwhile;

            else :

                get_template_part('template-parts/content', 'none');

            endif; ?>

        </div>

        <?php do_action('always_archive_pagination'); ?>

    </div>
<?php } else {

    $always_default = always_get_default_theme_options();
    $home_section_arrange_valsue = get_theme_mod( 'home_section_arrange_vals_3', $always_default['home_section_arrange_vals_3'] );
    $home_section_arrange_valsue = explode(",",$home_section_arrange_valsue );

    $paged_active = false;
    if ( !is_paged() ) {
        $paged_active = true;
    }

    foreach( $home_section_arrange_valsue as $home_section_reorder ){


        switch( $home_section_reorder ){

            case 'always_banner_slider_section':

                if( $paged_active ){
                    always_banner_slider_section();
                }

            break;

            case 'static_front_page':

                if( $paged_active ){ ?>

                    <div class="wrapper">

                        <div class="theme-panelarea theme-panelarea-blocks">
                            
                            <?php
                            if (!is_front_page()) { ?>

                                <div id="site-contentarea" class="theme-panel-blocks theme-header-panel archive-breadcrumb-panel">
                                    <div class="theme-panel-header">

                                        <?php always_breadcrumb(); ?>
                                        <?php always_archive_title(); ?>

                                    </div>
                                </div>
                            
                            <?php }

                            
                            
                            if (have_posts()):

                                $i = 1;
                                while (have_posts()) :
                                    the_post();

                                    ?>
                                    <div class="theme-panel-blocks article-panel-blocks theme-article-main">

                                    <?php

                                    if( is_front_page() ){

                                        if( $i == 1 ){

                                            ?><div id="site-contentarea"></div><?php

                                        }

                                    }
                                    
                                    get_template_part('template-parts/content', get_post_format());

                                    ?></div><?php

                                    $i++;
                                endwhile;

                            else :

                                get_template_part('template-parts/content', 'none');

                            endif; ?>

                        </div>

                        <?php do_action('always_archive_pagination'); ?>

                    </div>
                <?php }

            break;

            case 'homepage_about_Section':

                if( $paged_active ){
                    always_about_section();
                }

            break;


            case 'homepage_cta_Section':

                if( $paged_active ){
                    always_cta_section();
                }

            break;
            
            case 'homepage_category_Section':

                if( $paged_active ){
                    always_category_section();
                }

            break;            

            case 'homepage_contact_Section':

                if( $paged_active ){
                    always_contact_section();

                }

            break;

            case 'homepage_related_post_Section':

                if( $paged_active ){
                    always_related_post_section();

                }
            break;
            
            case 'twp_mailchimp_newsletter':

                if( $paged_active ){
                    always_newsletter_section();
                }

            break;


        }

    } 
}?>
<?php get_footer();
