<?php
    /**
     * Page: Home
     */

    get_header();

    $box1 = get_field('box-1');
    $box2 = get_field('box-2');
    $box3 = get_field('box-3');
    $box4 = get_field('box-4');
    $box5 = get_field('box-5');
    $box6 = get_field('box-6');

    $args = [
        'post_type'      => 'post',
        'posts_per_page' => 3,
        'orderby'        => 'date',
        'order'          => 'DESC',
    ];
    $query = new WP_Query($args);
?>
	<main id="primary" class="site-main">

        <div class="box-1">
            <div class="container">
                <div class="row">
                    <div class="col col-1">
                        <div class="box-head">
                             <h2><?php echo $box1['title']; ?></h2>
                        </div>
                        <div class="box-text">
                             <p><?php echo $box1['text']; ?></p>
                        </div>
                        <a class="btn_3" href="<?php echo esc_url($box1['btn']['url']); ?>" target="<?php echo esc_attr($box1['btn']['target'] ?: '_self'); ?>">
                            <?php echo esc_html($box1['btn']['title']); ?>
                        </a>
                        <div class="box-quote">
                            <p><?php echo $box1['quote_text']; ?></p>
                            <a class="btn_5" href="<?php echo esc_url($box1['quote_btn']['url']); ?>" target="<?php echo esc_attr($box1['quote_btn']['target'] ?: '_self'); ?>">
                                <?php echo esc_html($box1['quote_btn']['title']); ?>
                            </a>
                        </div>
                    </div>

                    <div class="col col-2">
                        <img src="<?php echo $box1['image']; ?>" alt="Image">
                    </div>
                </div>
            </div>
        </div>

        <div class="box-2">
            <div class="container">
                <div class="row">
                    <div class="col col-1" box-title="<?php echo $box2['mini_title']; ?>">
                        <div class="box-text">
                             <p><?php echo $box2['text']; ?></p>
                        </div>
                        <a class="btn_4" href="<?php echo esc_url($box2['btn']['url']); ?>" target="<?php echo esc_attr($box2['btn']['target'] ?: '_self'); ?>">
                            <?php echo esc_html($box2['btn']['title']); ?>
                        </a>
                    </div>

                    <div class="col col-2"></div>
                </div>
            </div>
        </div>

        <div class="box-3">
            <div class="container">
                <div class="row" box-title="<?php echo $box3['mini_title']; ?>">
                    <ul>
                        <?php foreach ($box3['cards'] as $i => $item) : ?>
                            <li class="<?php echo ($i == count($box3['cards']) - 1) ? 'last' : ''; ?>">
                                <h2><?php echo $item['title']; ?></h2>
                                <p><?php echo $item['text']; ?></p>
                                <?php if ($item['btn_handler'] == true) : ?>
                                    <a class="btn_4" href="<?php echo esc_url($item['btn']['url']); ?>" target="<?php echo esc_attr($item['btn']['target'] ?: '_self'); ?>">
                                        <?php echo esc_html($item['btn']['title']); ?>
                                    </a>
                                <?php endif; ?>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            </div>
        </div>

        <div class="box-4">
            <div class="container">
                <div class="row">
                    <div class="col col-1" box-title="<?php echo $box4['mini_title']; ?>">
                        <img src="<?php echo $box4['img']; ?>" alt="">
                    </div>
                    <div class="col col-2">
                        <ul>
                            <?php foreach ($box4['lists'] as $i => $item) : ?>
                            <li>
                                <h3><?php echo $item['title']; ?></h3>
                                <p><?php echo $item['text']; ?></p>
                            </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="box-5">
            <div class="container">
                <div class="row">
                    <div class="big-quote" box-title="<?php echo $box5['mini_title']; ?>">
                        <h3><?php echo $box5['author']; ?></h3>
                        <div class="big-quote-text">
                            <?php echo $box5['text']; ?>
                        </div>
                        <a class="btn_3" href="<?php echo esc_url($box5['btn']['url']); ?>" target="<?php echo esc_attr($box5['btn']['target'] ?: '_self'); ?>">
                            <?php echo esc_html($box5['btn']['title']); ?>
                        </a>
                        <ol>
                            <?php foreach ($box5['images'] as $i => $item) : ?>
                                <li>
                                    <img src="<?php echo $item; ?>" alt="">
                                </li>
                            <?php endforeach; ?>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="box-6">
            <div class="container">
                <div class="row">
                    <div class="col col-1" box-title="<?php echo $box6['mini_title']; ?>">
                        <div class="box-text">
                            <p><?php echo $box6['text']; ?></p>
                        </div>
                        <ul>
                            <a class="btn_3" href="<?php echo esc_url($box6['btn']['url']); ?>" target="<?php echo esc_attr($box6['btn']['target'] ?: '_self'); ?>">
                                <?php echo esc_html($box6['btn']['title']); ?>
                            </a>
                            <li>
                                <img src="<?php echo $box6['icon']; ?>" alt="">
                            </li>
                        </ul>
                    </div>
                    <div class="col col-2">
                        <img src="<?php echo $box6['img']; ?>" alt="">
                    </div>
                </div>
            </div>
        </div>

        <div class="box-7">
            <div class="container">
                <div class="row" box-title="Blog">
                    <?php
                        if ($query->have_posts()) :
                            while ($query->have_posts()) : $query->the_post();
                                $image = get_the_post_thumbnail_url(get_the_ID(), 'medium');
                                $title = get_the_title();
                                $link  = get_permalink();

                                get_template_part(
                                    'inc/template-article-card', null, [
                                        'image' => $image,
                                        'title' => $title,
                                        'link'  => $link
                                    ]
                                );
                            endwhile;
                            wp_reset_postdata();
                        endif;
                    ?>
                </div>
            </div>
        </div>
	</main>
<?php
get_footer();
