<?php
    $badge = $d['badge'];
    $cap = $d['capacity'];
    $isCustom = (bool) ($d['is_custom_sale'] ?? false);
    $isCancelled = $badge['key'] === 'cancelled';
    $isTerminal = in_array($badge['key'], ['cancelled', 'completed']);
    $isGuaranteed = in_array($badge['key'], ['auto_guaranteed', 'manual_guaranteed']);
    $ringColor = $cap['occupancy'] >= 80 ? '#16a34a' : ($cap['occupancy'] >= 40 ? '#334155' : '#f59e0b');
?>

<div class="ops-card <?php echo e($isCancelled ? 'is-cancelled' : ''); ?>" style="--tcolor:<?php echo e($d['type_color']); ?>"
     data-quickview-url="<?php echo e($d['quick_view_url']); ?>"
     data-ops-search="<?php echo e($d['tour_name'] . ' ' . ($d['tour_code'] ?? '')); ?>">

    <div class="ops-card-top">
        <div>
            <span class="ops-type"><span class="dot"></span><?php echo e($d['type_label']); ?></span>
            <?php if($d['is_private'] ?? false): ?><span class="ops-private" title="Satış kartında elle tarih girilerek açılan kişiye özel kalkış"><i class="fas fa-user-lock"></i> ÖZEL</span><?php endif; ?>
            <div class="ops-tourname <?php if($d['tour_qv_url'] ?? null): ?> ops-tourlink <?php endif; ?>"
                 <?php if($d['tour_qv_url'] ?? null): ?> data-quickview-url="<?php echo e($d['tour_qv_url']); ?>" title="Tur kartını aç" <?php endif; ?>><?php echo e($d['tour_name']); ?></div>
            <?php if($d['tour_code']): ?><span class="ops-code"><?php echo e($d['tour_code']); ?></span><?php endif; ?>
        </div>
        <div class="ops-ring" style="--pct:<?php echo e($cap['occupancy']); ?>;--rcolor:<?php echo e($ringColor); ?>" title="<?php echo e($isCustom ? $cap['used'] . ' yolcu' : 'Doluluk %' . $cap['occupancy']); ?>">
            <div class="inner">
                <span class="n"><?php echo e($isCustom ? $cap['used'] : $cap['used'] . '/' . ($cap['total'] ?: '∞')); ?></span>
                <span class="t"><?php echo e($isCustom ? 'YOLCU' : 'KOLTUK'); ?></span>
            </div>
        </div>
    </div>

    <div class="ops-badge" style="background:<?php echo e($badge['color']); ?>1a;color:<?php echo e($badge['color']); ?>">
        <i class="fas <?php echo e($badge['icon']); ?>"></i> <?php echo e($badge['label']); ?>

    </div>

    <div class="ops-meta">
        <?php if($d['start_time']): ?>
            <div class="ops-meta-item"><i class="fas fa-clock"></i> <?php echo e($d['start_time']); ?></div>
        <?php endif; ?>
        <?php if(!is_null($d['days_until'])): ?>
            <div class="ops-meta-item"><i class="fas fa-hourglass-start"></i>
                <?php if($d['days_until'] > 0): ?> <?php echo e((int) $d['days_until']); ?> gün kaldı
                <?php elseif($d['days_until'] === 0): ?> Bugün
                <?php else: ?> Geçti <?php endif; ?>
            </div>
        <?php elseif($isCustom): ?>
            <div class="ops-meta-item" title="Bu satışta tarih girilmemiş"><i class="fas fa-calendar-question"></i> Tarihi belirsiz</div>
        <?php endif; ?>
        <div class="ops-meta-item"><i class="fas fa-ticket"></i> <?php echo e($d['res_count']); ?> rezervasyon</div>
        <div class="ops-meta-item"><i class="fas fa-users"></i> <?php echo e($d['pax']); ?> yolcu</div>
    </div>

    <?php if($d['services']): ?>
        <div class="ops-svc">
            <span class="<?php echo e($d['services']['accommodation'] ? 'on' : ''); ?>" title="Konaklama"><i class="fas fa-bed"></i></span>
            <span class="<?php echo e($d['services']['meals'] ? 'on' : ''); ?>" title="Yemek"><i class="fas fa-utensils"></i></span>
            <span class="<?php echo e($d['services']['transportation'] ? 'on' : ''); ?>" title="Ulaşım"><i class="fas fa-bus"></i></span>
        </div>
    <?php endif; ?>

    <?php if(($d['resource_count'] ?? 0) > 0): ?>
        <div class="ops-res-chip">
            <i class="fas fa-people-carry-box"></i> <?php echo e($d['resource_count']); ?> kaynak
            <span class="dot">·</span> <b><?php echo e(number_format($d['resource_cost'], 0, ',', '.')); ?>₺</b> maliyet
        </div>
    <?php endif; ?>

    <div class="ops-card-foot">
        <div class="ops-rev">
            <?php echo e(number_format($d['revenue'], 0, ',', '.')); ?>₺
            <small>CİRO</small>
            <?php if(($d['remaining'] ?? 0) > 0): ?>
                <span class="ops-due" title="Tahsil edilmemiş tutar"><?php echo e(number_format($d['remaining'], 0, ',', '.')); ?>₺ bekliyor</span>
            <?php elseif(($d['revenue'] ?? 0) > 0): ?>
                <span class="ops-due ok" title="Tamamı tahsil edildi"><i class="fas fa-circle-check"></i> tahsil edildi</span>
            <?php endif; ?>
        </div>
        <div class="ops-acts">
            <?php if($d['show_url']): ?>
                <a href="<?php echo e($d['show_url']); ?>" class="ops-btn" title="Detay"><i class="fas fa-up-right-and-down-left-from-center"></i></a>
            <?php else: ?>
                <button type="button" class="ops-btn" data-quickview-url="<?php echo e($d['quick_view_url']); ?>" title="Satış kartını aç"><i class="fas fa-up-right-and-down-left-from-center"></i></button>
            <?php endif; ?>

            <?php if(!$isCustom && !$isTerminal && !$isGuaranteed): ?>
                <form method="POST" action="<?php echo e(route('agency.operations.guarantee', [$d['type_key'], $d['id']])); ?>"
                      onsubmit="return confirm('Bu kalkış kesin kalkışa alınsın mı?')">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="ops-btn ok" title="Kesin Kalkışa Al"><i class="fas fa-circle-check"></i></button>
                </form>
            <?php endif; ?>

            <?php if(!$isCustom && !$isTerminal): ?>
                <form method="POST" action="<?php echo e(route('agency.operations.cancel', [$d['type_key'], $d['id']])); ?>"
                      onsubmit="return confirm('Bu kalkış iptal edilsin mi?')">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="ops-btn no" title="Kalkışı İptal Et"><i class="fas fa-ban"></i></button>
                </form>
            <?php endif; ?>
        </div>
    </div>
</div>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/operations/_card.blade.php ENDPATH**/ ?>