<?php $__env->startSection('title', 'Bid #' . $bid->id . ' Management – Admin CRM'); ?>
<?php $__env->startSection('page_title', 'Bid Authorization #' . $bid->id); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6 max-w-7xl">
    
    <!-- Top Nav Back -->
    <div class="flex items-center justify-between">
        <a href="<?php echo e(route('admin.bids.index')); ?>" class="text-xs font-bold text-slate-400 hover:text-white flex items-center gap-1.5">
            <i class="fa-solid fa-arrow-left"></i>
            <span>Back to Bids CRM</span>
        </a>
        <div class="flex items-center gap-2">
            <span class="text-xs text-slate-400">Current Status:</span>
            <span class="px-3 py-1 rounded-full text-xs font-bold uppercase bg-red-600/20 text-red-400 border border-red-500/30">
                <?php echo e($bid->status); ?>

            </span>
        </div>
    </div>

    <!-- 2 Column Layout -->
    <div class="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start">
        
        <!-- Left 7 Cols: Vehicle, Auction Sheet, Client Information -->
        <div class="lg:col-span-7 space-y-6">
            
            <!-- Vehicle Specs Card -->
            <div class="bg-slate-900 border border-white/10 rounded-2xl overflow-hidden shadow-xl">
                <div class="aspect-16/9 bg-slate-950 relative overflow-hidden">
                    <?php if($bid->auctionVehicle && !empty($bid->auctionVehicle->images)): ?>
                        <img src="<?php echo e($bid->auctionVehicle->images[0]); ?>" alt="Vehicle" class="w-full h-full object-cover">
                    <?php else: ?>
                        <div class="w-full h-full flex items-center justify-center text-slate-700"><i class="fa-solid fa-car text-5xl"></i></div>
                    <?php endif; ?>
                    <div class="absolute top-4 left-4 bg-slate-900/90 border border-white/10 backdrop-blur-md px-3 py-1 rounded-lg text-xs font-bold text-white">
                        Grade <?php echo e($bid->auctionVehicle->grade ?? '4.5'); ?>

                    </div>
                    <div class="absolute top-4 right-4 bg-red-600 text-white px-3 py-1 rounded-lg text-xs font-bold uppercase">
                        <?php echo e($bid->auctionVehicle->auctionHouse->name ?? 'USS'); ?>

                    </div>
                </div>

                <div class="p-6">
                    <h3 class="text-lg font-bold text-white font-heading">
                        <?php echo e($bid->auctionVehicle->year ?? ''); ?> <?php echo e($bid->auctionVehicle->brand ?? ''); ?> <?php echo e($bid->auctionVehicle->model ?? ''); ?> <?php echo e($bid->auctionVehicle->grade_package ?? ''); ?>

                    </h3>
                    <p class="text-xs text-slate-400 mt-1">
                        Lot #<?php echo e($bid->auctionVehicle->lot_number); ?> · Chassis: <span class="font-mono text-slate-200"><?php echo e($bid->auctionVehicle->chassis_number ?? 'Pending'); ?></span>
                    </p>

                    <div class="grid grid-cols-2 sm:grid-cols-4 gap-3 mt-5 pt-5 border-t border-white/10 text-xs">
                        <div class="bg-slate-950 p-3 rounded-xl border border-white/5">
                            <span class="text-[10px] text-slate-500 font-bold block">Mileage</span>
                            <span class="font-bold text-white"><?php echo e(number_format($bid->auctionVehicle->mileage ?? 0)); ?> km</span>
                        </div>
                        <div class="bg-slate-950 p-3 rounded-xl border border-white/5">
                            <span class="text-[10px] text-slate-500 font-bold block">Engine</span>
                            <span class="font-bold text-white"><?php echo e($bid->auctionVehicle->engine_cc ?? 1800); ?> cc</span>
                        </div>
                        <div class="bg-slate-950 p-3 rounded-xl border border-white/5">
                            <span class="text-[10px] text-slate-500 font-bold block">Transmission</span>
                            <span class="font-bold text-white"><?php echo e($bid->auctionVehicle->transmission ?? 'Automatic'); ?></span>
                        </div>
                        <div class="bg-slate-950 p-3 rounded-xl border border-white/5">
                            <span class="text-[10px] text-slate-500 font-bold block">Fuel</span>
                            <span class="font-bold text-white"><?php echo e($bid->auctionVehicle->fuel_type ?? 'Hybrid'); ?></span>
                        </div>
                    </div>

                    <!-- Auction Sheet -->
                    <?php if($bid->auctionVehicle && $bid->auctionVehicle->auction_sheet_url): ?>
                        <div class="mt-6 pt-5 border-t border-white/10">
                            <span class="text-xs font-bold uppercase tracking-wider text-slate-400 block mb-2">Original Auction Sheet</span>
                            <div class="rounded-xl overflow-hidden border border-white/10 bg-slate-950 max-h-80">
                                <img src="<?php echo e($bid->auctionVehicle->auction_sheet_url); ?>" alt="Auction Sheet" class="w-full h-auto object-contain">
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Customer CRM Profile Card -->
            <div class="bg-slate-900 border border-white/10 rounded-2xl p-6 shadow-xl space-y-4">
                <div class="flex items-center justify-between border-b border-white/10 pb-3">
                    <h4 class="text-sm font-bold text-white uppercase tracking-wider flex items-center gap-2">
                        <i class="fa-solid fa-user text-blue-400"></i> Customer CRM Profile
                    </h4>
                    <a href="https://wa.me/<?php echo e($bid->user->phone ?? ''); ?>" target="_blank" class="text-xs font-bold text-emerald-400 hover:underline flex items-center gap-1">
                        <i class="fa-brands fa-whatsapp"></i> WhatsApp Direct
                    </a>
                </div>
                <div class="grid grid-cols-2 gap-4 text-xs">
                    <div>
                        <span class="text-slate-500 font-bold block">Client Name:</span>
                        <span class="font-bold text-white text-sm"><?php echo e($bid->user->name ?? 'N/A'); ?></span>
                    </div>
                    <div>
                        <span class="text-slate-500 font-bold block">Contact Phone:</span>
                        <span class="font-bold text-white"><?php echo e($bid->user->phone ?? 'N/A'); ?></span>
                    </div>
                    <div>
                        <span class="text-slate-500 font-bold block">Email:</span>
                        <span class="text-slate-300"><?php echo e($bid->user->email ?? 'N/A'); ?></span>
                    </div>
                    <div>
                        <span class="text-slate-500 font-bold block">City / Address:</span>
                        <span class="text-slate-300"><?php echo e($bid->user->customer->city ?? 'Dhaka'); ?> (<?php echo e($bid->user->customer->address ?? 'Showroom pickup'); ?>)</span>
                    </div>
                </div>
            </div>

        </div>

        <!-- Right 5 Cols: Financials & Admin Workflow Actions -->
        <div class="lg:col-span-5 space-y-6">
            
            <!-- Bid Figures Card -->
            <div class="bg-slate-900 border border-white/10 rounded-2xl p-6 shadow-xl space-y-4">
                <h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/10 pb-3 flex items-center gap-2">
                    <i class="fa-solid fa-coins text-amber-400"></i> Bidding Ceiling & Landed Cost
                </h4>
                <div class="space-y-3 text-xs">
                    <div class="flex justify-between text-slate-400">
                        <span>Starting Auction Price:</span>
                        <span class="font-semibold text-slate-200">¥<?php echo e(number_format($bid->auctionVehicle->starting_price_jpy ?? 0)); ?></span>
                    </div>
                    <div class="flex justify-between text-slate-400">
                        <span>Client Maximum Authorized:</span>
                        <span class="font-extrabold text-amber-400 text-base">¥<?php echo e(number_format($bid->max_bid_jpy)); ?></span>
                    </div>
                    <div class="flex justify-between text-slate-400 border-t border-white/5 pt-2">
                        <span>Estimated Landed Cost (Dhaka):</span>
                        <span class="font-extrabold text-white text-base">৳<?php echo e(number_format($bid->estimated_landed_cost_bdt)); ?></span>
                    </div>
                    <div class="flex justify-between text-slate-400">
                        <span>Token Security Deposit:</span>
                        <span class="font-bold text-emerald-400">৳<?php echo e(number_format($bid->deposit_amount_bdt ?? 200000)); ?> (<?php echo e(ucfirst($bid->deposit_status ?? 'verified')); ?>)</span>
                    </div>
                </div>
            </div>

            <!-- Admin CRM Action Center (Contextual based on status) -->
            <div class="bg-gradient-to-br from-slate-900 to-[#1b1424] border-2 border-red-500/30 rounded-2xl p-6 shadow-2xl space-y-5">
                <h4 class="text-sm font-bold text-white font-heading uppercase tracking-wider flex items-center gap-2">
                    <i class="fa-solid fa-sliders text-red-500"></i> CRM Workflow Actions
                </h4>

                <!-- 1. APPROVE & DISPATCH ACTION (if pending) -->
                <?php if($bid->status === 'pending'): ?>
                    <form method="POST" action="<?php echo e(route('admin.bids.approve', $bid->id)); ?>" class="space-y-3 p-4 rounded-xl bg-slate-950 border border-blue-500/30">
                        <?php echo csrf_field(); ?>
                        <span class="text-xs font-bold text-blue-400 block">Step 1: Admin Verification & Japan API Dispatch</span>
                        <p class="text-[11px] text-slate-400">Validates client deposit and submits the maximum bid limit to Japanese floor agent.</p>
                        <input type="text" name="notes" placeholder="Admin verification notes (optional)..." class="w-full bg-slate-900 border border-white/10 rounded-lg px-3 py-2 text-white text-xs">
                        <button type="submit" class="w-full py-2.5 rounded-xl bg-blue-600 hover:bg-blue-500 text-white font-bold text-xs shadow transition flex items-center justify-center gap-2">
                            <i class="fa-solid fa-check"></i>
                            <span>Approve & Dispatch to Japan Floor</span>
                        </button>
                    </form>

                    <!-- Reject Form -->
                    <form method="POST" action="<?php echo e(route('admin.bids.reject', $bid->id)); ?>" class="space-y-2 pt-2 border-t border-white/10">
                        <?php echo csrf_field(); ?>
                        <input type="text" name="reason" placeholder="Reason for declining bid..." required class="w-full bg-slate-950 border border-white/10 rounded-lg px-3 py-2 text-white text-xs">
                        <button type="submit" class="w-full py-2 rounded-xl bg-rose-950/40 hover:bg-rose-950/80 text-rose-300 font-bold text-xs border border-rose-500/30 transition">
                            Decline / Reject Bid
                        </button>
                    </form>
                <?php endif; ?>

                <!-- 2. MARK AS WON (if approved or submitted) -->
                <?php if(in_array($bid->status, ['approved', 'submitted', 'bidding'])): ?>
                    <form method="POST" action="<?php echo e(route('admin.bids.won', $bid->id)); ?>" class="space-y-3 p-4 rounded-xl bg-slate-950 border border-emerald-500/40">
                        <?php echo csrf_field(); ?>
                        <div class="flex items-center justify-between">
                            <span class="text-xs font-bold text-emerald-400">Step 2: Auction Hammer Struck (WON)</span>
                            <i class="fa-solid fa-trophy text-emerald-400"></i>
                        </div>
                        <p class="text-[11px] text-slate-400">Enter final Japanese hammer price. Automatically creates Order & generates live 12-step import tracker.</p>
                        <div>
                            <label class="block text-[10px] uppercase font-bold text-slate-400 mb-1">Final Auction Hammer Price (JPY) *</label>
                            <input type="number" name="won_hammer_price_jpy" value="<?php echo e($bid->max_bid_jpy); ?>" required class="w-full bg-slate-900 border border-white/10 rounded-lg px-3 py-2 text-white text-xs font-bold text-emerald-400">
                        </div>
                        <input type="text" name="notes" placeholder="Auction house invoice notes..." class="w-full bg-slate-900 border border-white/10 rounded-lg px-3 py-2 text-white text-xs">
                        <button type="submit" class="w-full py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs shadow transition">
                            Confirm WON & Generate Import Order
                        </button>
                    </form>

                    <!-- Mark as Lost -->
                    <form method="POST" action="<?php echo e(route('admin.bids.lost', $bid->id)); ?>" class="space-y-2 pt-2 border-t border-white/10">
                        <?php echo csrf_field(); ?>
                        <input type="text" name="reason" value="Hammer price exceeded customer maximum ceiling." class="w-full bg-slate-950 border border-white/10 rounded-lg px-3 py-2 text-white text-xs">
                        <button type="submit" class="w-full py-2 rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-300 font-bold text-xs transition">
                            Mark as Lost (Outbid on Floor)
                        </button>
                    </form>
                <?php endif; ?>

                <?php if($bid->status === 'won' && $bid->order): ?>
                    <div class="p-4 rounded-xl bg-emerald-950/40 border border-emerald-500/40 text-xs text-emerald-300">
                        <p class="font-bold mb-1">Order Generated:</p>
                        <a href="<?php echo e(route('admin.orders.show', $bid->order->id)); ?>" class="underline font-bold text-white">
                            View Order #<?php echo e($bid->order->order_number); ?> Tracker &rarr;
                        </a>
                    </div>
                <?php endif; ?>
            </div>

            <!-- Activity Log -->
            <div class="bg-slate-900 border border-white/10 rounded-2xl p-6 shadow-xl">
                <h4 class="text-xs font-bold uppercase tracking-wider text-slate-400 border-b border-white/10 pb-3 mb-4">
                    Audit Activity History
                </h4>
                <div class="space-y-3 text-xs">
                    <?php $__empty_1 = true; $__currentLoopData = $bid->history; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $history): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="flex items-start gap-2.5">
                            <div class="w-1.5 h-1.5 rounded-full bg-red-500 mt-1.5 shrink-0"></div>
                            <div class="flex-1">
                                <div class="flex justify-between text-[11px]">
                                    <span class="font-bold text-white"><?php echo e(ucwords(str_replace('_', ' ', $history->action))); ?></span>
                                    <span class="text-slate-500"><?php echo e($history->created_at->format('M d, h:i A')); ?></span>
                                </div>
                                <p class="text-slate-400 text-[10px] mt-0.5"><?php echo e($history->notes); ?></p>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="text-slate-500 text-xs">No activity logged.</p>
                    <?php endif; ?>
                </div>
            </div>

        </div>

    </div>

</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/redwoneferdous/Desktop/MotoSolution/resources/views/admin/bids/show.blade.php ENDPATH**/ ?>