<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <div class="flex items-center gap-3">
            <a href="<?php echo e(route('customer.orders.index')); ?>" class="text-gray-500 hover:text-gray-700" style="text-decoration: none;">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                </svg>
            </a>
            <h2 style="font-size: 1.25rem; font-weight: 500; color: #1a1a1a;">
                Detail Pesanan #<?php echo e($order->order_number); ?>

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

    <style>
        * {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        }
        
        .order-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 32px 24px;
            background: #f5f5f5;
            min-height: 100vh;
        }

        /* Alert */
        .alert {
            padding: 12px 16px;
            margin-bottom: 20px;
            border-radius: 8px;
            font-size: 0.875rem;
            background: white;
            border-left: 3px solid;
        }
        .alert-success { border-left-color: #22c55e; background: #f0fdf4; color: #166534; }
        .alert-error { border-left-color: #ef4444; background: #fef2f2; color: #991b1b; }
        .alert-info { border-left-color: #3b82f6; background: #eff6ff; color: #1e40af; }

        /* Card */
        .card {
            background: white;
            border-radius: 12px;
            margin-bottom: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
            border: 1px solid #e5e7eb;
            overflow: hidden;
        }
        .card-header {
            padding: 16px 20px;
            border-bottom: 1px solid #e5e7eb;
            background: #fafafa;
        }
        .card-title {
            font-size: 0.875rem;
            font-weight: 600;
            color: #374151;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin: 0;
        }
        .card-body { padding: 20px; }

        /* Header Info */
        .order-header {
            background: white;
            border-radius: 12px;
            padding: 20px 24px;
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 12px;
            border: 1px solid #e5e7eb;
        }
        .order-number {
            font-size: 1.125rem;
            font-weight: 600;
            color: #1f2937;
        }
        .order-date {
            font-size: 0.75rem;
            color: #9ca3af;
            margin-top: 4px;
        }
        .badge {
            display: inline-block;
            padding: 4px 12px;
            font-size: 0.7rem;
            font-weight: 600;
            border-radius: 20px;
            letter-spacing: 0.3px;
        }
        .badge-pending { background: #fef3c7; color: #92400e; }
        .badge-paid { background: #dbeafe; color: #1e40af; }
        .badge-processing { background: #e0e7ff; color: #3730a3; }
        .badge-shipped { background: #cffafe; color: #0e7490; }
        .badge-completed { background: #dcfce7; color: #166534; }
        .badge-cancelled { background: #fee2e2; color: #991b1b; }
        
        .invoice-link {
            font-size: 0.7rem;
            font-weight: 500;
            color: #6b7280;
            text-decoration: none;
            margin-left: 12px;
        }
        .invoice-link:hover { color: #1f2937; }

        /* Progress Steps */
        .progress-steps {
            display: flex;
            align-items: center;
            padding: 24px;
            background: white;
        }
        .step {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
            flex: 1;
            position: relative;
        }
        .step-dot {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: #f3f4f6;
            border: 2px solid #e5e7eb;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.875rem;
            font-weight: 600;
            color: #9ca3af;
        }
        .step.done .step-dot {
            background: #22c55e;
            border-color: #22c55e;
            color: white;
        }
        .step.active .step-dot {
            border-color: #3b82f6;
            background: #eff6ff;
            color: #3b82f6;
        }
        .step-line {
            flex: 1;
            height: 2px;
            background: #e5e7eb;
            margin: 0 -8px;
            margin-top: -18px;
        }
        .step-line.done { background: #22c55e; }
        .step-label {
            font-size: 0.7rem;
            font-weight: 500;
            color: #9ca3af;
        }
        .step.done .step-label { color: #22c55e; }
        .step.active .step-label { color: #3b82f6; font-weight: 600; }

        /* Info Row */
        .info-row {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid #f3f4f6;
            font-size: 0.875rem;
        }
        .info-row:last-child { border-bottom: none; }
        .info-label {
            color: #6b7280;
            font-weight: 500;
        }
        .info-value {
            color: #1f2937;
            font-weight: 500;
        }

        /* Order Items */
        .order-item {
            display: flex;
            gap: 16px;
            padding: 16px 0;
            border-bottom: 1px solid #f3f4f6;
        }
        .order-item:last-child { border-bottom: none; }
        .item-img {
            width: 70px;
            height: 70px;
            border-radius: 8px;
            object-fit: cover;
            background: #f3f4f6;
            border: 1px solid #e5e7eb;
        }
        .item-info { flex: 1; }
        .item-name {
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 4px;
        }
        .item-variant {
            font-size: 0.75rem;
            color: #6b7280;
            margin-bottom: 4px;
        }
        .item-qty {
            font-size: 0.75rem;
            color: #9ca3af;
        }
        .item-price {
            font-weight: 600;
            color: #1f2937;
            white-space: nowrap;
        }
        .review-link {
            display: inline-block;
            margin-top: 6px;
            font-size: 0.7rem;
            color: #3b82f6;
            text-decoration: none;
        }
        .review-link:hover { text-decoration: underline; }
        .reviewed-badge {
            display: inline-block;
            margin-top: 6px;
            font-size: 0.65rem;
            color: #9ca3af;
        }

        /* Totals */
        .totals {
            padding: 16px 20px;
            background: #f9fafb;
            border-top: 1px solid #e5e7eb;
        }
        .total-row {
            display: flex;
            justify-content: space-between;
            padding: 6px 0;
            font-size: 0.875rem;
        }
        .grand-total {
            display: flex;
            justify-content: space-between;
            padding-top: 12px;
            margin-top: 8px;
            border-top: 2px solid #e5e7eb;
            font-weight: 700;
            font-size: 1rem;
        }

        /* Address */
        .address-box {
            background: #f9fafb;
            border-radius: 8px;
            padding: 16px;
            font-size: 0.875rem;
            line-height: 1.6;
        }
        .address-name {
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 4px;
        }

        /* Buttons */
        .btn {
            display: block;
            width: 100%;
            padding: 12px 16px;
            font-size: 0.75rem;
            font-weight: 600;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
        }
        .btn-primary {
            background: #1f2937;
            color: white;
        }
        .btn-primary:hover { background: #374151; }
        .btn-danger {
            background: white;
            color: #dc2626;
            border: 1px solid #fecaca;
        }
        .btn-danger:hover {
            background: #dc2626;
            color: white;
            border-color: #dc2626;
        }
        .info-box {
            background: #f3f4f6;
            border-radius: 8px;
            padding: 12px;
            font-size: 0.75rem;
            color: #4b5563;
            text-align: center;
        }

        /* Layout */
        .two-columns {
            display: grid;
            grid-template-columns: 1fr 320px;
            gap: 20px;
        }
        @media (max-width: 768px) {
            .two-columns { grid-template-columns: 1fr; }
            .order-container { padding: 20px 16px; }
        }

        /* Modal */
        .modal {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }
        .modal.active { display: flex; }
        .modal-content {
            background: white;
            border-radius: 12px;
            padding: 28px;
            width: 90%;
            max-width: 400px;
        }
        .modal-title {
            font-size: 1.125rem;
            font-weight: 600;
            margin-bottom: 8px;
        }
        .modal-sub {
            font-size: 0.75rem;
            color: #6b7280;
            margin-bottom: 16px;
        }
        .modal-textarea {
            width: 100%;
            padding: 10px 12px;
            font-size: 0.875rem;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            resize: vertical;
            min-height: 90px;
        }
        .modal-textarea:focus {
            outline: none;
            border-color: #3b82f6;
        }
        .modal-actions {
            display: flex;
            gap: 12px;
            margin-top: 16px;
        }
        .modal-btn {
            flex: 1;
            padding: 10px;
            font-size: 0.75rem;
            font-weight: 600;
            border: none;
            border-radius: 8px;
            cursor: pointer;
        }
        .modal-btn-cancel {
            background: #f3f4f6;
            color: #6b7280;
        }
        .modal-btn-submit {
            background: #dc2626;
            color: white;
        }

        /* Courier Steps */
        .courier-steps {
            display: flex;
            align-items: center;
            padding: 20px;
        }
        .cstep {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 6px;
            flex: 1;
        }
        .cstep-dot {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: #f3f4f6;
            border: 2px solid #e5e7eb;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.75rem;
        }
        .cstep.done .cstep-dot {
            background: #22c55e;
            border-color: #22c55e;
            color: white;
        }
        .cstep.active .cstep-dot {
            border-color: #3b82f6;
        }
        .cstep-line {
            flex: 1;
            height: 2px;
            background: #e5e7eb;
            margin: 0 -8px;
            margin-top: -16px;
        }
        .cstep-line.done { background: #22c55e; }
        .cstep-label {
            font-size: 0.6rem;
            font-weight: 500;
            color: #9ca3af;
        }
        .cstep.done .cstep-label { color: #22c55e; }

        /* Proof Image */
        .proof-img {
            width: 100%;
            border-radius: 8px;
            cursor: pointer;
            margin-top: 12px;
        }
        .tracking-box {
            background: #f3f4f6;
            padding: 10px 12px;
            border-radius: 8px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 12px;
        }
        .copy-btn {
            background: none;
            border: none;
            font-size: 0.875rem;
            cursor: pointer;
            padding: 4px 8px;
        }
    </style>

    <?php
        $statusRank = ['pending'=>0,'paid'=>1,'processing'=>2,'shipped'=>3,'completed'=>4,'cancelled'=>-1];
        $curRank    = $statusRank[$order->status] ?? 0;

        $pillMap = [
            'pending'=>'badge-pending','paid'=>'badge-paid',
            'processing'=>'badge-processing','shipped'=>'badge-shipped',
            'completed'=>'badge-completed','cancelled'=>'badge-cancelled',
        ];
        $statusLabel = [
            'pending'=>'Menunggu Bayar','paid'=>'Dibayar','processing'=>'Diproses',
            'shipped'=>'Dikirim','completed'=>'Selesai','cancelled'=>'Dibatalkan',
        ];

        $taskRank = ['assigned'=>1,'picked_up'=>2,'delivered'=>3];
        $curTask  = $taskRank[$order->courier_task_status ?? ''] ?? 0;

        $canConfirm      = $order->status === 'shipped' && $curTask >= 3;
        $canPay          = $order->payment_status !== 'paid' && $order->status === 'paid' && $order->snap_token;
        $cancellable     = in_array($order->status, ['pending','paid','processing']) && $order->cancel_request_status !== 'pending';
        $isPaid          = in_array($order->status, ['paid','processing','shipped','completed']) || $order->payment_status === 'paid';
    ?>

    <div class="order-container">
        
        <div class="order-header">
            <div>
                <div class="order-number">Pesanan #<?php echo e($order->order_number); ?></div>
                <div class="order-date"><?php echo e($order->created_at->format('d M Y, H:i')); ?> WIB</div>
            </div>
            <div>
                <span class="badge <?php echo e($pillMap[$order->status] ?? ''); ?>">
                    <?php echo e($statusLabel[$order->status] ?? ucfirst($order->status)); ?>

                </span>
                <?php if(in_array($order->status, ['paid','processing','shipped','completed'])): ?>
                    <a href="<?php echo e(route('customer.orders.invoice', $order->id)); ?>" target="_blank" class="invoice-link">Invoice →</a>
                <?php endif; ?>
            </div>
        </div>

        
        <?php if(session('success')): ?>
            <div class="alert alert-success"><?php echo e(session('success')); ?></div>
        <?php endif; ?>
        <?php if(session('error')): ?>
            <div class="alert alert-error"><?php echo e(session('error')); ?></div>
        <?php endif; ?>
        <?php if(session('info')): ?>
            <div class="alert alert-info"><?php echo e(session('info')); ?></div>
        <?php endif; ?>

        
        <?php if($order->status !== 'cancelled'): ?>
        <div class="card">
            <div class="progress-steps">
                <?php
                    $steps = [
                        ['key'=>'pending', 'label'=>'Pesanan'],
                        ['key'=>'paid', 'label'=>'Dibayar'],
                        ['key'=>'processing', 'label'=>'Diproses'],
                        ['key'=>'shipped', 'label'=>'Dikirim'],
                        ['key'=>'completed', 'label'=>'Selesai'],
                    ];
                    $stepRanks = ['pending'=>0,'paid'=>1,'processing'=>2,'shipped'=>3,'completed'=>4];
                ?>
                <?php $__currentLoopData = $steps; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $step): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $r = $stepRanks[$step['key']];
                        $cls = $curRank > $r ? 'done' : ($curRank === $r ? 'active' : '');
                    ?>
                    <?php if($i > 0): ?>
                        <div class="step-line <?php echo e($curRank > $stepRanks[$steps[$i-1]['key']] ? 'done' : ''); ?>"></div>
                    <?php endif; ?>
                    <div class="step <?php echo e($cls); ?>">
                        <div class="step-dot">
                            <?php if($curRank > $r): ?> ✓ <?php else: ?> <?php echo e($i+1); ?> <?php endif; ?>
                        </div>
                        <div class="step-label"><?php echo e($step['label']); ?></div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>
        <?php else: ?>
        <div class="card">
            <div class="card-body" style="text-align: center; color: #dc2626;">
                <strong>✕ Pesanan Dibatalkan</strong>
            </div>
        </div>
        <?php endif; ?>

        <div class="two-columns">
            
            <div>
                
                <?php if($order->courier_id): ?>
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">Status Pengiriman</div>
                    </div>
                    <div class="courier-steps">
                        <?php
                            $cs = [
                                ['label'=>'Menuju Toko','rank'=>1],
                                ['label'=>'Dikirim','rank'=>2],
                                ['label'=>'Tiba','rank'=>3],
                            ];
                        ?>
                        <?php $__currentLoopData = $cs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($i > 0): ?>
                                <div class="cstep-line <?php echo e($curTask >= $c['rank'] ? 'done' : ''); ?>"></div>
                            <?php endif; ?>
                            <?php $cCls = $curTask >= $c['rank'] ? 'done' : ($curTask === $c['rank']-1 ? 'active' : ''); ?>
                            <div class="cstep <?php echo e($cCls); ?>">
                                <div class="cstep-dot">
                                    <?php if($curTask >= $c['rank']): ?> ✓ <?php else: ?> <?php echo e($i+1); ?> <?php endif; ?>
                                </div>
                                <div class="cstep-label"><?php echo e($c['label']); ?></div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <div class="card-body">
                        <?php if($order->courier_task_status === 'assigned'): ?>
                            <div class="info-box">Kurir sedang menuju toko untuk mengambil paket Anda.</div>
                        <?php elseif($order->courier_task_status === 'picked_up'): ?>
                            <div class="info-box">
                                Paket sedang dalam perjalanan menuju alamat Anda.
                                <?php if($order->picked_up_at): ?>
                                    <div style="margin-top: 6px;">Diambil: <?php echo e($order->picked_up_at->format('d M Y, H:i')); ?> WIB</div>
                                <?php endif; ?>
                                <?php if($order->tracking_number): ?>
                                    <div class="tracking-box">
                                        <span>No. Resi: <strong><?php echo e($order->tracking_number); ?></strong></span>
                                        <button class="copy-btn" onclick="copyResi()">📋 Salin</button>
                                    </div>
                                <?php endif; ?>
                            </div>
                        <?php elseif($order->courier_task_status === 'delivered'): ?>
                            <div class="info-box" style="background: #dcfce7; color: #166534;">
                                ✓ Paket telah diantar ke alamat Anda.
                                <?php if($order->delivered_at): ?>
                                    <div>Diantar: <?php echo e($order->delivered_at->format('d M Y, H:i')); ?> WIB</div>
                                <?php endif; ?>
                            </div>
                            <?php
                                $deliveryProofs = $order->deliveryProofs ?? collect();
                                $proofDelivered = $deliveryProofs->where('type', 'delivered')->last();
                            ?>
                            <?php if($proofDelivered): ?>
                                <div style="margin-top: 16px;">
                                    <div style="font-size: 0.75rem; font-weight: 600; margin-bottom: 8px;">Bukti Pengiriman</div>
                                    <a href="<?php echo e(asset('storage/' . $proofDelivered->photo_path)); ?>" target="_blank">
                                        <img src="<?php echo e(asset('storage/' . $proofDelivered->photo_path)); ?>" class="proof-img">
                                    </a>
                                    <?php if($proofDelivered->notes): ?>
                                        <div style="font-size: 0.7rem; color: #6b7280; margin-top: 8px;"><?php echo e($proofDelivered->notes); ?></div>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endif; ?>

                
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">Item Pesanan</div>
                    </div>
                    <div style="padding: 0 20px;">
                        <?php $__currentLoopData = $order->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $imgUrl = null;
                            if ($item->variant && $item->variant->image) $imgUrl = $item->variant->image->image_path;
                            if (!$imgUrl && $item->product?->images?->count()) {
                                $primary = $item->product->images->where('is_primary',true)->first();
                                $imgUrl  = $primary ? $primary->image_path : $item->product->images->first()->image_path;
                            }
                        ?>
                        <div class="order-item">
                            <?php if($imgUrl): ?>
                                <img src="<?php echo e(asset('storage/'.$imgUrl)); ?>" class="item-img">
                            <?php else: ?>
                                <div class="item-img" style="display: flex; align-items: center; justify-content: center;">📦</div>
                            <?php endif; ?>
                            <div class="item-info">
                                <div class="item-name"><?php echo e($item->product_name ?? $item->product?->name); ?></div>
                                <?php if($item->variant_info): ?>
                                    <div class="item-variant"><?php echo e($item->variant_info); ?></div>
                                <?php endif; ?>
                                <div class="item-qty">Jumlah: <?php echo e($item->quantity); ?></div>
                                <?php if($order->status === 'completed' && $item->product): ?>
                                    <?php
                                        $hasReviewed = \App\Models\Review::where('user_id', Auth::id())
                                            ->where('order_id', $order->id)
                                            ->where('product_id', $item->product->id)
                                            ->exists();
                                    ?>
                                    <?php if($hasReviewed): ?>
                                        <span class="reviewed-badge">✓ Sudah Diulas</span>
                                    <?php else: ?>
                                        <a href="<?php echo e(route('reviews.create', ['order'=>$order->id, 'product'=>$item->product->id])); ?>"
                                           class="review-link">✎ Beri Ulasan</a>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                            <div class="item-price">Rp <?php echo e(number_format($item->price * $item->quantity, 0, ',', '.')); ?></div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <div class="totals">
                        <div class="total-row">
                            <span>Subtotal</span>
                            <span>Rp <?php echo e(number_format($order->subtotal, 0, ',', '.')); ?></span>
                        </div>
                        <div class="total-row">
                            <span>Ongkos Kirim</span>
                            <span>Rp <?php echo e(number_format($order->shipping_cost, 0, ',', '.')); ?></span>
                        </div>
                        <div class="grand-total">
                            <span>Total Bayar</span>
                            <span>Rp <?php echo e(number_format($order->total, 0, ',', '.')); ?></span>
                        </div>
                    </div>
                </div>

                
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">Alamat Pengiriman</div>
                    </div>
                    <div class="card-body">
                        <div class="address-box">
                            <div class="address-name"><?php echo e($order->recipient_name); ?></div>
                            <div><?php echo e($order->recipient_phone); ?></div>
                            <div style="margin-top: 8px;"><?php echo e($order->shipping_address); ?></div>
                            <div><?php echo e($order->village ? 'Kel. '.$order->village : ''); ?> <?php echo e($order->district ? 'Kec. '.$order->district : ''); ?></div>
                            <div><?php echo e($order->city ?? ''); ?> <?php echo e($order->province ?? ''); ?> <?php echo e($order->postal_code ?? ''); ?></div>
                        </div>
                    </div>
                </div>
            </div>

            
            <div>
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">Informasi Pesanan</div>
                    </div>
                    <div style="padding: 0 20px;">
                        <div class="info-row">
                            <span class="info-label">No. Pesanan</span>
                            <span class="info-value">#<?php echo e($order->order_number); ?></span>
                        </div>
                        <div class="info-row">
                            <span class="info-label">Tanggal</span>
                            <span class="info-value"><?php echo e($order->created_at->format('d M Y')); ?></span>
                        </div>
                        <div class="info-row">
                            <span class="info-label">Status Pembayaran</span>
                            <span class="info-value" style="<?php echo e($isPaid ? 'color:#22c55e;' : 'color:#ef4444;'); ?>">
                                <?php echo e($isPaid ? 'Lunas' : 'Belum Bayar'); ?>

                            </span>
                        </div>
                        <?php if($order->tracking_number): ?>
                        <div class="info-row">
                            <span class="info-label">No. Resi</span>
                            <span class="info-value" style="font-family: monospace;"><?php echo e($order->tracking_number); ?></span>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="card">
                    <div class="card-header">
                        <div class="card-title">Aksi</div>
                    </div>
                    <div class="card-body">
                        <?php if($canPay): ?>
                            <button id="btn-pay" class="btn btn-primary" style="margin-bottom: 12px;">Bayar Sekarang</button>
                        <?php endif; ?>

                        <?php if($canConfirm): ?>
                            <form action="<?php echo e(route('customer.orders.confirm-received', $order->id)); ?>" method="POST"
                                  onsubmit="return confirm('Konfirmasi pesanan sudah diterima?')">
                                <?php echo csrf_field(); ?>
                                <button type="submit" class="btn btn-primary" style="margin-bottom: 12px;">Konfirmasi Diterima</button>
                            </form>
                        <?php endif; ?>

                        <?php if($order->status === 'shipped' && $curTask < 3): ?>
                            <div class="info-box" style="margin-bottom: 12px;">Menunggu konfirmasi kurir</div>
                        <?php endif; ?>

                        <?php if($order->payment_status === 'paid' && !$canPay && !$canConfirm && $order->status !== 'completed'): ?>
                            <div class="info-box" style="margin-bottom: 12px; background: #dcfce7; color: #166534;">
                                ✓ Pembayaran telah diterima
                            </div>
                        <?php endif; ?>

                        <?php if($order->status === 'completed'): ?>
                            <div class="info-box" style="margin-bottom: 12px; background: #dcfce7; color: #166534;">
                                ✓ Pesanan selesai
                            </div>
                        <?php endif; ?>

                        <?php if($order->cancel_request_status === 'pending'): ?>
                            <div class="info-box" style="margin-bottom: 12px; background: #fef3c7; color: #92400e;">
                                ⏳ Permintaan pembatalan menunggu persetujuan
                                <?php if($order->cancel_reason): ?>
                                    <div style="font-size: 0.7rem; margin-top: 4px;">Alasan: <?php echo e($order->cancel_reason); ?></div>
                                <?php endif; ?>
                            </div>
                        <?php elseif($order->cancel_request_status === 'rejected'): ?>
                            <div class="info-box" style="margin-bottom: 12px; background: #fef2f2; color: #dc2626;">
                                ❌ Permintaan pembatalan ditolak
                                <?php if($order->cancel_reject_reason): ?>
                                    <div style="font-size: 0.7rem; margin-top: 4px;"><?php echo e($order->cancel_reject_reason); ?></div>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>

                        <?php if($cancellable): ?>
                            <button type="button" class="btn btn-danger"
                                    onclick="document.getElementById('modalCancel').classList.add('active')">
                                Ajukan Pembatalan
                            </button>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <div class="modal" id="modalCancel">
        <div class="modal-content">
            <div class="modal-title">Ajukan Pembatalan</div>
            <div class="modal-sub">Pesanan #<?php echo e($order->order_number); ?></div>
            <form action="<?php echo e(route('customer.orders.request-cancel', $order->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <textarea name="cancel_reason" class="modal-textarea" required
                          placeholder="Alasan pembatalan..."></textarea>
                <div class="modal-actions">
                    <button type="button" class="modal-btn modal-btn-cancel"
                            onclick="document.getElementById('modalCancel').classList.remove('active')">Batal</button>
                    <button type="submit" class="modal-btn modal-btn-submit">Kirim</button>
                </div>
            </form>
        </div>
    </div>

    
    <?php if($canPay && $order->snap_token): ?>
    <script src="<?php echo e(config('midtrans.is_production') ? 'https://app.midtrans.com/snap/snap.js' : 'https://app.sandbox.midtrans.com/snap/snap.js'); ?>"
            data-client-key="<?php echo e(config('midtrans.client_key')); ?>"></script>
    <script>
        document.getElementById('btn-pay')?.addEventListener('click', function() {
            window.snap.pay('<?php echo e($order->snap_token); ?>', {
                onSuccess: () => {
                    fetch('<?php echo e(route("customer.orders.mark-paid", $order->id)); ?>', {
                        method: 'POST',
                        headers: { 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>', 'Content-Type': 'application/json' }
                    }).then(() => window.location.reload());
                },
                onPending: () => window.location.reload(),
                onError:   () => window.location.reload(),
                onClose:   () => {}
            });
        });

        function copyResi() {
            navigator.clipboard.writeText('<?php echo e($order->tracking_number); ?>');
            const btn = event.target;
            btn.textContent = '✓';
            setTimeout(() => btn.textContent = '📋 Salin', 1500);
        }
    </script>
    <?php endif; ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH C:\laragon\www\toko_app\resources\views/customer/orders/order-detail.blade.php ENDPATH**/ ?>