<?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');

$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">
            <div class="bp-lot__image" style="background-image:url('<?= esc_url($featureImage) ?>');"></div>
        </a>
    <?php } else { ?>
        <div class="bp-lot__wrp-image">
            <div class="bp-lot__image" style="background-image:url('<?= esc_url($featureImage) ?>');"></div>
        </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>
