<?php
/**
 * @var $index int
 * @var $featureImage string
 * @var $auction WP_Term
 * @var $auctionState string
 * @var $auctionDay array
 * @var $linkToAuction string
 * @var $target string|null
 * @var $dateTime string
 * @var $auctionTitle bool
 */

use auctionforge\inc\model\Auction;

$limitWords = apply_filters('auctionforge_lot_title_words', 8);

$dateTimeStr = date_i18n('M. j, Y', strtotime($dateTime));
?>
<div class="bp-lot bp-lot_auction bp-lot_countdown term_<?= $auction->term_id ?>">
    <a href="<?= $linkToAuction ?>" class="bp-lot__wrp-image">
        <p class="bp-lot__date"><?= $dateTimeStr ?></p>
        <div class="bp-lot__image" style="background-image:url('<?= $featureImage ?>');"></div>
    </a>
    <div class="bp-lot__content">
        <div class="bp-lot__title">
            <?php if ($auctionState == Auction::STATE_PENDING) { ?>
                <p class="bp-title"><?= $auctionTitle ?></p>
            <?php } else { ?>
                <a href="<?= $linkToAuction ?>" class="bp-title"><?= $auctionTitle ?></a>
            <?php } ?>
            <?php if (!empty($auctionDay->details) && $auctionDay->details != "") { ?>
                <div class="bp-lot__text" data-text="auctionName"><?= wp_trim_words($auctionDay->details, $limitWords, '...') ?></div>
            <?php } elseif (!empty($auctionDay->name) && $auctionDay->name != "") { ?>
                <div class="bp-lot__text"><?= wp_trim_words($auctionDay->name, $limitWords, '...') ?></div>
            <?php } else { ?>
                <div class="bp-lot__text"><?= wp_trim_words($auction->description, $limitWords, '...') ?></div>
            <?php } ?>
        </div>
        <div class="bp-lot__tool bp-d-flex bp-f-center bp-f-wrap">
            <?php if ($auctionState == Auction::STATE_READY || $auctionState == Auction::STATE_RUNNING) { ?>
                <a href="<?= $linkToAuction ?>" class="bp-lot__tool__item bp-btn bp-btn-default"><?= __('View catalog', 'auctionforge') ?></a>
            <?php } elseif ($auctionState == Auction::STATE_PENDING) { ?>
                <div class="bp-lot__tool__item bp-text-red"><?= __('Catalog will be available soon', 'auctionforge') ?></div>
            <?php } elseif ($auctionState == Auction::STATE_ENDING &&
                (isset($auctionDay->postAuctionSaleOpenedUntil) && ($auctionDay->postAuctionSaleOpenedUntil/1000 > time()))) { ?>
                <div class="bp-lot__tool__item bp-text-red"><?= __('The after-sale has started', 'auctionforge') ?></div>
                <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-lot__tool__item bp-btn bp-btn-default"><?= __('View results', 'auctionforge') ?></a>
            <?php } elseif ($auctionState == Auction::STATE_ENDING || $auctionState == Auction::STATE_ARCHIVED) { ?>
                <div class="bp-lot__tool__item bp-text-red"><?= __('The auction has ended', 'auctionforge') ?></div>
                <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-lot__tool__item bp-btn bp-btn-default"><?= __('View results', 'auctionforge') ?></a>
            <?php } ?>
        </div>
    </div>
</div>