<?php
/**
 * The template for displaying all pages
 *
 * TODO REFACTORING HARD
 * MODEL -> VIEW -> SCENE
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package o66FsWp
 */

//$addMe = get_post(8);
//$addMe2 = get_post(12);
//$addMe3 = get_post(15);
$page_root_model = o66TheModel::getTheRootModel();
//$oneSub = o66TheModel::createOneModelFromWpPostObject($addMe);
//$twoSub = o66TheModel::createOneModelFromWpPostObject($addMe2);
//$threeSub = o66TheModel::createOneModelFromWpPostObject($addMe3);
$primaryMenu = o66TheModel::createOneModelFromWpMenu('primary');
o66TheModel::appendOneModelToTheModel($primaryMenu);
$tree = o66TheModel::getTheTreeModelArray();
$flat = o66TheModel::getTheModelFlatArray();
$children = o66TheModel::getTheChildrenArray();
$fields = o66TheModel::getTheModelFieldsArray();

o66TheViewClass::assignModelToView($page_root_model);
//o66TheViewClass::assignModelToView($primaryMenu, 'feat_text');
$view = o66TheViewClass::getView('page');
$view_model = o66TheViewClass::getModelViewArray();
get_header();
$the_content = get_the_content();
if (!empty($the_content)) {
    echo $view;
}
$contenuto_big = get_field('contenuto_riquadro_grande');
$link_riquadro_grande = get_field('link_riquadro_grande');
$titolo_link_big = get_field('titolo_link_riquadro_grande');
if (!empty($contenuto_big))  :
    $style_riquadro = '';
    $sfondo_riquadro_grande = get_field('sfondo_riquadro_grande');
    if (!empty($sfondo_riquadro_grande)) {
        $style_riquadro = 'background-image: url(' . $sfondo_riquadro_grande['url'] . ')';
    }
    ?>
    <div class="blok section-big" style="<?php //echo $style_riquadro;
    ?>">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="blok contenitore-big">
                        <div class="blok contenuto-big">
                            <?php echo $contenuto_big; ?>

                        </div>
                        <div class="blok link-big">
                            <?php if (!empty($titolo_link_big)) :
                                $link_url = get_permalink($link_riquadro_grande);
                                ?>
                                <a href="<?php echo $link_url; ?>"><?php echo $titolo_link_big; ?></a>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
<?php if (have_rows('sezioni_verticali')) : ?>
    <div class="blok verticale">

    <?php
    $conta = 0;
    while (have_rows('sezioni_verticali')) : the_row();
        $conta++;
        $titolo_verticale = get_sub_field('titolo');
        if ($conta % 2 == 0) {
            ?>
            <div class="blok pari">
                <div class="container ">
                    <div class="row">
                        <div class="col-md-8">
                            <div class="blok content-verticale">
                                <?php if(!empty($titolo_verticale)) :?>  <div class="titolo-verticale"><h2><?php the_sub_field('titolo'); ?></h2></div><?php endif;?>
                                <div class="blok"><?php the_sub_field('testo'); ?></div>
                                <div class="blok bottone-verticale">
                                    <?php $post_object = get_sub_field('pagina_link'); ?>
                                    <?php $testo_link = get_sub_field('testo_link'); ?>
                                    <?php if (!empty($testo_link)): ?>
                                        <?php $post = $post_object; ?>
                                        <?php setup_postdata($post); ?>
                                        <a href="<?php the_permalink(); ?>"><?php echo $testo_link; ?></a>
                                        <?php wp_reset_postdata(); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <?php $immagine = get_sub_field('immagine'); ?>
                            <?php if ($immagine) { ?>
                                <div class="blok">
                                <img src="<?php echo $immagine['url']; ?>" alt="<?php echo $immagine['alt']; ?>"
                                     class="img-responsive immagine-verticale"/></div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        } else { ?>
            <div class="blok dispari">
                <div class="container ">
                    <div class="row">
                        <div class="col-md-4">
                            <?php $immagine = get_sub_field('immagine'); ?>
                            <?php if ($immagine) { ?>
                                <div class="blok">
                                    <img src="<?php echo $immagine['url']; ?>" alt="<?php echo $immagine['alt']; ?>"
                                         class="img-responsive immagine-verticale"/></div>
                            <?php } ?>
                        </div>
                        <div class="col-md-8">
                            <div class="blok content-verticale">
                                <?php if(!empty($titolo_verticale)) :?>  <div class="titolo-verticale"><h2><?php the_sub_field('titolo'); ?></h2></div><?php endif;?>
                                <div class="blok"><?php the_sub_field('testo'); ?></div>
                                <div class="blok bottone-verticale">
                                    <?php $post_object = get_sub_field('pagina_link'); ?>
                                    <?php $testo_link = get_sub_field('testo_link'); ?>
                                    <?php if (!empty($testo_link)): ?>
                                        <?php $post = $post_object; ?>
                                        <?php setup_postdata($post); ?>
                                        <a href="<?php the_permalink(); ?>"><?php echo $testo_link; ?></a>
                                        <?php wp_reset_postdata(); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>

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

        }
    endwhile; ?>
<?php else : ?>
    <?php // no rows found ?>

    </div>
<?php endif; ?>
<?php get_footer();

