@extends('layouts.admin')

@section('title', 'Pesanan Masuk')
@section('page-title', 'Daftar Pesanan Masuk')

@section('content')
    <div class="card">
        <div class="card-header">
            <h4>Kelola Pesanan</h4>
        </div>
        <div class="card-body">
            @if(session('success'))
                <div class="alert alert-success border-0 shadow-sm rounded-3 d-flex align-items-center">{{ session('success') }}</div>
            @endif

            <div class="table-responsive">
                <table class="table table-hover" id="table1">
                    <thead>
                        <tr>
                            <th>Invoice</th>
                            <th>Pembeli</th>
                            <th>Barang</th>
                            <th>Alamat</th>
                            <th>Total</th>
                            <th>Status</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($pesanans as $pesanan)
                            <tr>
                                <td class="text-primary font-bold">#{{ $pesanan->kode_invoice }}</td>
                                <td>
                                    {{ $pesanan->pembeli->nama_lengkap }}<br>
                                    <small class="text-muted">{{ $pesanan->pembeli->no_hp }}</small>
                                </td>
                                <td>
                                    <ul class="list-unstyled mb-0">
                                        @foreach($pesanan->detailTransaksis as $detail)
                                            <li>- {{ $detail->produk->nama_produk }} ({{ $detail->jumlah }})</li>
                                        @endforeach
                                    </ul>
                                </td>
                                <td><small>{{ Str::limit($pesanan->alamat_pengiriman, 30) }}</small></td>
                                <td class="font-bold">Rp {{ number_format($pesanan->total_harga, 0, ',', '.') }}</td>
                                <td>
                                    @if($pesanan->status == 'menunggu konfirmasi')
                                        <span class="badge bg-warning">Perlu Konfirmasi</span>
                                    @elseif($pesanan->status == 'diproses')
                                        <span class="badge bg-info">Diproses</span>
                                    @elseif($pesanan->status == 'dikirim')
                                        <span class="badge bg-primary">Dikirim</span>
                                    @elseif($pesanan->status == 'selesai')
                                        <span class="badge bg-success">Selesai</span>
                                    @else
                                        <span class="badge bg-danger">Batal</span>
                                    @endif
                                </td>
                                <td>
                                    <a href="{{ route('petani.pesanan.detail', $pesanan->id) }}"
                                        class="btn btn-sm btn-outline-primary rounded-pill px-3">
                                        Detail
                                    </a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="text-center">Belum ada pesanan masuk.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl)
        })
    </script>
@endsection