
@extends('layouts.frontend')

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

@section('content')
<div class="container py-5">
    <h2 class="mb-4 fw-bold text-primary">Riwayat Pesanan</h2>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="fa fa-check-circle me-2"></i> {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <div class="card border-0 shadow-sm rounded">
        <div class="card-body">
            @if($transaksis->isEmpty())
                <div class="text-center py-5">
                    <i class="fas fa-shopping-basket fa-4x text-muted mb-3"></i>
                    <p class="text-muted">Belum ada pesanan.</p>
                    <a href="{{ route('shop') }}" class="btn btn-primary rounded-pill">Mulai Belanja</a>
                </div>
            @else
                <div class="table-responsive">
                    <table class="table table-hover align-middle">
                        <thead class="bg-light">
                            <tr>
                                <th>Invoice</th>
                                <th>Tanggal</th>
                                <th>Produk</th>
                                <th>Total</th>
                                <th>Status</th>
                                <th>Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($transaksis as $trx)
                            <tr>
                                <td class="fw-bold text-primary">#{{ $trx->kode_invoice }}</td>
                                <td>{{ \Carbon\Carbon::parse($trx->tanggal_transaksi)->format('d M Y') }}</td>
                                <td>
                                    @foreach($trx->details as $detail)
                                        <div class="d-flex align-items-center mb-1">
                                            <img src="{{ $detail->produk->foto_produk ? asset('storage/'.$detail->produk->foto_produk) : asset('template/frontend/img/fruite-item-5.jpg') }}" width="40" class="rounded me-2">
                                            <div>
                                                <small class="d-block fw-bold">{{ $detail->produk->nama_produk }}</small>
                                                <small class="text-muted">{{ $detail->jumlah }} x Rp {{ number_format($detail->harga_satuan, 0, ',', '.') }}</small>
                                            </div>
                                        </div>
                                    @endforeach
                                </td>
                                <td class="fw-bold">Rp {{ number_format($trx->total_harga, 0, ',', '.') }}</td>
                                <td>
                                    @if($trx->status == 'menunggu_konfirmasi')
                                        <span class="badge bg-warning text-dark">Menunggu Konfirmasi</span>
                                    @elseif($trx->status == 'diproses')
                                        <span class="badge bg-info text-white">Sedang Diproses</span>
                                    @elseif($trx->status == 'dikirim')
                                        <span class="badge bg-primary">Sedang Dikirim</span>
                                    @elseif($trx->status == 'selesai')
                                        <span class="badge bg-success">Selesai</span>
                                    @else
                                        <span class="badge bg-danger">Dibatalkan</span>
                                    @endif
                                </td>
                                <td>
                                    <a href="#" class="btn btn-sm btn-outline-primary rounded-pill">Detail</a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection