<?php
/**
 * The Template for displaying lot archives, including the main shop page which is a post type archive.
 *
 */

if (!defined('ABSPATH')) {
    exit;
}

get_header();

global $post;

$header_options_arr = get_option('archive_auction_text');  ?>

    <div id="primary" class="content-area shop-page">

        <div class="header__auction with_featured_img">
            <div class="header__auction_bkg" style="background-image:url(<?= $header_options_arr['image'] ?>)" ></div>
            <div class="header__auction_overlay"></div>
            <div class="header__auction_info_row row">
                <h2 class="header_archive__auction_title text_center"><?= $header_options_arr['title'] ?></h2>
            </div><!-- .auction_info_row -->
        </div>

        <div class="row">
            <div class="bt-container large-12 columns">

                <div class="sub-header__archive">
                    <p><?= $header_options_arr['description'] ?></p>
                </div>

                <div id="content" class="site-content" role="main">
                    <div class="row">

                        <?php
                        $args_completed_auction = array(
                            'post_type'  => 'lot',
                            'taxonomy'   => 'auction_number',
                            'hide_empty' => 0,
                            'meta_query' => array(
                                'relation' => 'AND',
                                array(
                                    'key'     => 'auction_is_archived',
                                    'value'   => '1',
                                    'compare' => '='
                                )
                            ),
                            'orderby'    => 'title',
                            'order'      => 'DESC',
                        );

                        if( $list_completed_auctions = get_terms($args_completed_auction) ) :  ?>
                            <div class="row_auctions row_completed_auctions">

                                <div class="row_auctions_items">
                                    <?php foreach($list_completed_auctions as $auction) :
                                        $auction_full_name   = get_field('auction_full_name', $auction->taxonomy . '_' . $auction->term_id);
                                        $auction_start_date  = get_field('auction_start_date', $auction->taxonomy . '_' . $auction->term_id);
                                        $auction_subtitle    = get_field('auction_subtitle', $auction->taxonomy . '_' . $auction->term_id);
                                        $auction_image       = get_field('auction_image', $auction->taxonomy . '_' . $auction->term_id);
                                        $auction_is_archived = get_field('auction_is_archived', $auction->taxonomy . '_' . $auction->term_id);
                                        $new__start_date     = date("l, d.m.y", strtotime($auction_start_date));
                                        ?>
                                        <div class="auction_item custom_item_shadow">
                                            <div class="auction_item_container">
                                                <div class="auction_image_wrapper">
                                                    <div class="thumbnail_ratio_img">
                                                        <img src="<?= $auction_image; ?>" alt="<?= $auction_full_name; ?>">
                                                    </div>
                                                </div>
                                                <div class="auction_info_wrapper">
                                                    <h3><?= $auction_subtitle . ' ' . $auction->name ?></h3>
                                                    <p class="archive__auction_item_date text_center"><?= $new__start_date ?></p>
                                                    <hr>
                                                    <h4><?= $auction_full_name; ?></h4>
                                                </div>
                                                <div class="auction_button_open">
                                                    <a href="<?= get_term_link($auction) ?>" ><?= __('View results', 'auctionforge') ?></a>
                                                </div>
                                            </div>
                                        </div>
                                    <?php endforeach; wp_reset_postdata(); ?>
                                </div>

                            </div>

                        <?php  endif; ?>

                    </div><!-- .row-->
                </div><!-- #content -->

            </div><!-- .large-12 -->
        </div><!-- .row -->

    </div><!-- #primary -->


<?php get_footer(); ?>