<?php
/**
 * @var $featureImage string
 * @var $auction WP_Term
 * @var $auctionDay array
 * @var $auctionState string
 * @var $linkToAuction string
 * @var $target string|null
 * @var $dateTime string
 * @var $isAdmin bool
 * @var $auctionTitle 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 ?>">
    <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-lot__wrp-image">
        <div class="bp-lot__image" style="background-image:url('<?= $featureImage ?>');"></div>
    </a>
    <div class="bp-lot__content">
        <div class="bp-lot__title">
            <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-title"><?= $auctionTitle ?></a>
            <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" data-text="auctionName"><?= wp_trim_words($auctionDay->details, $limitWords, '...') ?></div>
            <?php } elseif (!empty($auctionDay->name) && $auctionDay->name != "") { ?>
                <div class="bp-lot__text" data-text="dateName"><?= wp_trim_words($auctionDay->name, $limitWords, '...') ?></div>
            <?php } else { ?>
                <div class="bp-lot__text" data-text="desc"><?= wp_trim_words($auction->description, $limitWords, '...') ?></div>
            <?php } ?>
            <?php if ($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>
            <?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>
            <?php } ?>
            <a href="<?= $linkToAuction ?>" <?= ($target) ? $target : '' ?> class="bp-lot__tool__item bp-btn bp-btn-default"><?= __('View catalog', 'auctionforge') ?></a>
        </div>
    </div>
</div>
