@extends('layouts.app')

@section('title', 'Pesanan Saya')

@section('content')
<div class="row">
    <div class="col-12">
        <h2 class="mb-4"><i class="fas fa-history me-2"></i>Riwayat Pesanan</h2>
    </div>
</div>

@if($orders->count() > 0)
<div class="row">
    @foreach($orders as $order)
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-start mb-3">
                    <div>
                        <h5 class="card-title mb-1">Pesanan #{{ $order->id }}</h5>
                        <small class="text-muted">{{ $order->created_at->format('d M Y, H:i') }}</small>
                    </div>
                    <span class="status-badge status-{{ $order->status }}">
                        @switch($order->status)
                            @case('pending') Menunggu @break
                            @case('confirmed') Dikonfirmasi @break
                            @case('processing') Diproses @break
                            @case('completed') Selesai @break
                            @case('cancelled') Dibatalkan @break
                        @endswitch
                    </span>
                </div>
                
                <div class="mb-3">
                    @foreach($order->orderItems as $item)
                    <div class="d-flex justify-content-between">
                        <span>{{ $item->quantity }}x {{ $item->menu->name }}</span>
                        <span>Rp {{ number_format($item->price * $item->quantity, 0, ',', '.') }}</span>
                    </div>
                    @endforeach
                </div>
                
                <hr>
                
                <div class="d-flex justify-content-between align-items-center">
                    <strong>Total</strong>
                    <strong class="text-success">Rp {{ number_format($order->total_price, 0, ',', '.') }}</strong>
                </div>
                
                @if($order->payment_method)
                <div class="mt-2">
                    <small class="text-muted">
                        <i class="fas fa-credit-card me-1"></i>Pembayaran: 
                        {{ $order->payment_method === 'cash' ? 'Cash' : 'QRIS' }}
                    </small>
                </div>
                @endif
                
                @if($order->notes)
                <div class="mt-2">
                    <small class="text-muted">Catatan: {{ $order->notes }}</small>
                </div>
                @endif
                
                <div class="mt-3">
                    <a href="{{ route('menu.order-detail', $order) }}" class="btn btn-sm btn-outline-primary">
                        <i class="fas fa-eye me-1"></i>Lihat Detail
                    </a>
                </div>
            </div>
        </div>
    </div>
    @endforeach
</div>

@else
<div class="text-center py-5">
    <i class="fas fa-clipboard-list fa-4x text-muted mb-3"></i>
    <h4 class="text-muted">Belum ada pesanan</h4>
    <p>Silakan pilih menu terlebih dahulu</p>
    <a href="{{ route('menu.index') }}" class="btn btn-primary">
        <i class="fas fa-utensils me-2"></i>Lihat Menu
    </a>
</div>
@endif
@endsection
