@extends('layouts.app')

@section('content')
<div class="space-y-6 p-2">
    <div class="flex flex-col md:flex-row md:items-center md:justify-between bg-white p-6 rounded-2xl border border-gray-100 shadow-sm gap-4">
        <div>
            <h1 class="text-2xl font-black text-gray-800 tracking-tight">Selamat Datang Kembali, {{ auth()->user()->name }}!</h1>
            <p class="text-sm text-gray-500 mt-1">Berikut adalah ringkasan performa operasional dan produksi Tempe Zhi hari ini.</p>
        </div>
        <div class="text-sm font-bold text-green-800 bg-green-50 px-4 py-2 rounded-xl border border-green-100 self-start md:self-auto">
            {{ \Carbon\Carbon::now()->isoFormat('D MMMM YYYY') }}
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
        <div class="bg-white p-8 rounded-3xl border border-gray-100 shadow-sm flex justify-between items-center">
            <div>
                <p class="text-[11px] font-black text-blue-600 uppercase tracking-widest mb-1">Total Stok Bahan Baku</p>
                <h3 class="text-4xl font-black text-gray-800">{{ $totalBahan }} <span class="text-base text-gray-400 font-medium">item</span></h3>
            </div>
            <div class="w-14 h-14 bg-blue-50 rounded-2xl flex items-center justify-center text-blue-600">
                <svg class="w-7 h-7" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/></svg>
            </div>
        </div>

        <div class="bg-white p-8 rounded-3xl border border-gray-100 shadow-sm flex justify-between items-center">
            <div>
                <p class="text-[11px] font-black text-orange-600 uppercase tracking-widest mb-1">Perlu Restock</p>
                <h3 class="text-4xl font-black text-gray-800">{{ $bahanKritis->count() }} <span class="text-base text-gray-400 font-medium">jenis bahan</span></h3>
            </div>
            <div class="w-14 h-14 bg-orange-50 rounded-2xl flex items-center justify-center text-orange-600">
                <svg class="w-7 h-7" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
            </div>
        </div>
    </div>

    @if($bahanKritis->count() > 0)
    <div class="bg-red-50 p-6 rounded-3xl border border-red-100 shadow-sm">
        <h4 class="font-bold text-red-800 mb-6 flex items-center gap-2">
            <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"><path d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"/></svg>
            Perhatian: Bahan Baku Hampir Habis!
        </h4>
        
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            @foreach($bahanKritis as $bahan)
                <div class="bg-white p-4 rounded-xl border border-red-100 shadow-sm flex justify-between items-center hover:shadow-md transition">
                    <div>
                        <p class="text-xs font-bold text-gray-400 uppercase">Nama Bahan</p>
                        <p class="font-bold text-gray-800">{{ $bahan->bahanbaku->nama_bahan ?? 'Bahan Tidak Ditemukan' }}</p>
                    </div>
                    <div class="text-right">
                        <p class="text-xs font-bold text-gray-400 uppercase">Sisa Stok</p>
                        <p class="font-black text-red-600">{{ $bahan->stok }}</p>
                    </div>
                </div>
            @endforeach
        </div>
    </div>
    @else
    <div class="bg-green-50 p-6 rounded-3xl border border-green-100 text-center">
        <p class="text-green-700 font-bold">Semua stok bahan baku dalam kondisi aman. Tidak ada yang perlu direstock.</p>
    </div>
    @endif
</div>
@endsection