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

use auctionforge\inc\model\Auction;

$limitWords = apply_filters('auctionforge_lot_title_words', 8);
?>
<div class="bp-lot bp-lot_auction term_<?= $auction->term_id ?>">
    <?php if ($auctionState == Auction::STATE_PENDING) { ?>
        <div class="bp-lot__wrp-image" style="position: relative;">
            <div class="bp-lot__image" style="background-image:url('<?= $featureImage ?>');"></div>
            <?php if (!empty($isTimedAuction) && $isTimedAuction) : ?>
                <div style="position: absolute; top: 0; left: 0; background-color: rgba(56, 55, 39, 0.95); color: #fff; padding: 6px 14px; font-size: 15px; font-weight: 500;">Timed Auction</div>
            <?php endif; ?>
        </div>
    <?php } else { ?>
        <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-lot__wrp-image" style="position: relative;">
            <div class="bp-lot__image" style="background-image:url('<?= $featureImage ?>');"></div>
            <?php if (!empty($isTimedAuction) && $isTimedAuction) : ?>
                <div style="position: absolute; top: 0; left: 0; background-color: rgba(56, 55, 39, 0.95); color: #fff; padding: 6px 14px; font-size: 15px; font-weight: 500;">Timed Auction</div>
            <?php endif; ?>
        </a>
    <?php } ?>
    <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 ?>" <?= ($target) ? $target : '' ?> class="bp-title"><?= $auctionTitle ?></a>
            <?php } ?>
            <p class="bp-lot__date">
                <?php do_action('bp_print_auction_time', array('auctionDay' => $auctionDay)) ?>
            </p>
        </div>
        <div class="bp-lot__tool bp-d-flex bp-f-center bp-f-wrap">
            <?php if (!empty($auctionDay->details) && $auctionDay->details != "") { ?>
                <div class="bp-lot__text"><?= 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 } ?>
            <?php if ($auctionState == Auction::STATE_READY || $auctionState == Auction::STATE_RUNNING || $auctionState == Auction::STATE_PRE_AUCTION) { ?>
                <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> 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>