@extends('layouts.admin')

@section('title', 'Dashboard Petani')
@section('page-title', 'Panel Petani')

@section('content')
    <div class="page-heading">
        <h3>Statistik Toko</h3>
    </div>
    <div class="page-content">
        <section class="row">
            <div class="col-12 col-lg-12">

                {{-- Baris Statistik --}}
                <div class="row">
                    <!-- Statistik 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 purple mb-2">
                                            {{-- Ikon Produk --}}
                                            <i class="bi bi-box-seam-fill text-white"></i>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <h6 class="text-muted font-semibold">Produk Aktif</h6>
                                        <h6 class="font-extrabold mb-0">
                                            {{ \App\Models\Produk::where('petani_id', Auth::guard('petani')->id())->count() }}
                                        </h6>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Statistik Pesanan -->
                    <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 mb-2">
                                            <i class="bi bi-cart-check-fill text-white"></i>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <h6 class="text-muted font-semibold">Pesanan Masuk</h6>

                                        {{-- LOGIKA HITUNG PESANAN --}}
                                        @php
                                            $jumlahPesanan = \App\Models\Transaksi::whereHas(
                                                'details.produk',
                                                function ($q) {
                                                    $q->where('petani_id', Auth::guard('petani')->id());
                                                },
                                            )
                                                ->where('status', '!=', 'selesai')
                                                ->count();
                                        @endphp

                                        <h6 class="font-extrabold mb-0">{{ $jumlahPesanan }}</h6>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </section>
    </div>
@endsection
