<?php
/**
 * Template for displaying a manual auction card in the auction list.
 *
 * @var $manualAuction object Manual auction data object
 * @var $isAdmin bool
 */

use auctionforge\inc\helpers\LotHelper;

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

$featureImage = !empty($manualAuction->feature_image) ? $manualAuction->feature_image : LotHelper::getPlaceholderImage();
$auctionTitle = esc_html($manualAuction->title);
$auctionLink = !empty($manualAuction->auction_link) ? esc_url($manualAuction->auction_link) : '';
$hasLink = !empty($auctionLink);
$isExternal = !empty($manualAuction->has_external_link);
$target = $isExternal ? 'target="_blank"' : '';
$description = !empty($manualAuction->description) ? wp_trim_words(wp_strip_all_tags($manualAuction->description), $limitWords, '...') : '';
$auctionType = $manualAuction->auction_type === 'online' ? __('Online', 'auctionforge') : __('In Person', 'auctionforge');

$showTimedBadge = \auctionforge\inc\helpers\SettingsHelper::getOption(\auctionforge\inc\controllers\Settings::SHOW_TIMED_AUCTION_BADGE, 'off') === 'on';

$dateDisplay = '';
if (!empty($manualAuction->date)) {
    $dateDisplay = date_i18n('F d, Y', strtotime($manualAuction->date));
    if (!empty($manualAuction->time) && $manualAuction->time !== '00:00') {
        $dateDisplay .= ', ' . date_i18n('g:i A', strtotime($manualAuction->date . 'T' . $manualAuction->time));
    }
}
?>
<div class="bp-lot bp-lot_auction manual_auction_<?= $manualAuction->post_id ?>">
    <?php if ($hasLink) { ?>
        <a href="<?= $auctionLink ?>" <?= $target ?> class="bp-lot__wrp-image" style="position: relative;">
            <div class="bp-lot__image" style="background-image:url('<?= esc_url($featureImage) ?>');"></div>
            <?php if ($showTimedBadge && $manualAuction->auction_type === 'online') : ?>
                <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 } else { ?>
        <div class="bp-lot__wrp-image" style="position: relative;">
            <div class="bp-lot__image" style="background-image:url('<?= esc_url($featureImage) ?>');"></div>
            <?php if ($showTimedBadge && $manualAuction->auction_type === 'online') : ?>
                <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 } ?>
    <div class="bp-lot__content">
        <div class="bp-lot__title">
            <?php if ($hasLink) { ?>
                <a href="<?= $auctionLink ?>" <?= $target ?> class="bp-title"><?= $auctionTitle ?></a>
            <?php } else { ?>
                <p class="bp-title"><?= $auctionTitle ?></p>
            <?php } ?>
            <p class="bp-lot__date">
                <?= $dateDisplay ?>
                <?php if ($auctionType) { ?>
                    <span class="bp-lot__type"> &mdash; <?= $auctionType ?></span>
                <?php } ?>
            </p>
        </div>
        <div class="bp-lot__tool bp-d-flex bp-f-center bp-f-wrap">
            <?php if (!empty($description)) { ?>
                <div class="bp-lot__text"><?= $description ?></div>
            <?php } ?>
            <?php if ($hasLink) { ?>
                <a href="<?= $auctionLink ?>" <?= $target ?> class="bp-lot__tool__item bp-btn bp-btn-default"><?= __('View auction', 'auctionforge') ?></a>
            <?php } ?>
        </div>
    </div>
</div>
