@extends('layouts.admin')

@section('title', 'Dashboard Admin')
@section('page-title', 'Overview Sistem')

@section('content')
<section class="row">
    <div class="col-12">
        <div class="row">
            {{-- Statistik Petani Aktif --}}
            <div class="col-6 col-lg-3 col-md-6">
                <div class="card">
                    <div class="card-body px-3 py-4-5">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="stats-icon purple"><i class="bi bi-people-fill"></i></div>
                            </div>
                            <div class="col-md-8">
                                <h6 class="text-muted font-semibold">Petani Aktif</h6>
                                <h6 class="font-extrabold mb-0">{{ $totalPetani }}</h6>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Statistik Menunggu Verifikasi --}}
            <div class="col-6 col-lg-3 col-md-6">
                <div class="card">
                    <div class="card-body px-3 py-4-5">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="stats-icon red"><i class="bi bi-person-plus-fill"></i></div>
                            </div>
                            <div class="col-md-8">
                                <h6 class="text-muted font-semibold">Verifikasi Pending</h6>
                                <h6 class="font-extrabold mb-0">{{ $petaniPending }}</h6>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Statistik Total Produk --}}
            <div class="col-6 col-lg-3 col-md-6">
                <div class="card">
                    <div class="card-body px-3 py-4-5">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="stats-icon green"><i class="bi bi-basket-fill"></i></div>
                            </div>
                            <div class="col-md-8">
                                <h6 class="text-muted font-semibold">Total Produk</h6>
                                <h6 class="font-extrabold mb-0">{{ $totalProduk }}</h6>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Statistik Total Transaksi --}}
            <div class="col-6 col-lg-3 col-md-6">
                <div class="card">
                    <div class="card-body px-3 py-4-5">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="stats-icon blue"><i class="bi bi-receipt"></i></div>
                            </div>
                            <div class="col-md-8">
                                <h6 class="text-muted font-semibold">Total Transaksi</h6>
                                <h6 class="font-extrabold mb-0">{{ $totalTransaksi }}</h6>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        {{-- Tabel Ringkasan Transaksi Terbaru --}}
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4>Transaksi Terbaru di Platform</h4>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Invoice</th>
                                        <th>Pembeli</th>
                                        <th>Total</th>
                                        <th>Status</th>
                                        <th>Tanggal</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse($transaksiTerbaru as $trx)
                                    <tr>
                                        <td>#{{ $trx->kode_invoice }}</td>
                                        <td>{{ $trx->pembeli->nama_lengkap }}</td>
                                        <td>Rp {{ number_format($trx->total_harga, 0, ',', '.') }}</td>
                                        <td>
                                            <span class="badge bg-{{ $trx->status == 'selesai' ? 'success' : ($trx->status == 'batal' ? 'danger' : 'warning') }}">
                                                {{ ucfirst($trx->status) }}
                                            </span>
                                        </td>
                                        <td>{{ $trx->created_at->diffForHumans() }}</td>
                                    </tr>
                                    @empty
                                    <tr><td colspan="5" class="text-center">Belum ada transaksi.</td></tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>
                        <div class="text-center mt-3">
                            <a href="{{ route('admin.monitoring') }}" class="btn btn-sm btn-primary">Lihat Semua Data</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
@endsection