@extends('layouts.app')

@section('content')
<div class="space-y-6 p-2">
    
    <div class="flex flex-col sm:flex-row sm:items-center sm: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-400 font-medium mt-1">Berikut adalah ringkasan performa operasional dan produksi Tempe Zhi hari ini.</p>
        </div>
        <div class="text-sm font-bold text-green-700 bg-green-50 px-4 py-2 rounded-xl border border-green-100 self-start sm:self-auto">
            {{ \Carbon\Carbon::now()->isoFormat('D MMMM YYYY') }}
        </div>
    </div>

    <div class="w-full bg-white p-6 rounded-2xl border border-gray-100 shadow-sm flex justify-between items-center">
        <div>
            <p class="text-xs font-black text-green-600 uppercase tracking-wider mb-2">Total Produksi Hari Ini</p>
            <h3 class="text-4xl font-black text-gray-800 tracking-tight">
                {{ number_format($produksiHariIni) }} <span class="text-base text-gray-400 font-bold tracking-normal">pcs</span>
            </h3>
        </div>
        <div class="w-14 h-14 bg-green-50 text-green-600 rounded-2xl flex items-center justify-center shrink-0">
            <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="M13 10V3L4 14h7v7l9-11h-7z" />
            </svg>
        </div>
    </div>

    <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm">
        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between mb-4 gap-2">
            <h3 class="text-base font-black text-gray-800 tracking-tight">Tren Produksi 7 Hari Terakhir</h3>
            
            <a href="{{ route('staffproduksi.produksi.create') }}" class="px-4 py-2 bg-green-700 hover:bg-green-800 text-white font-black text-xs tracking-wider uppercase rounded-xl transition-colors inline-flex items-center gap-1.5 self-start sm:self-auto">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M12 4v16m8-8H4"/></svg>
                Input Produksi
            </a>
        </div>
        <div class="h-96 w-full">
            <canvas id="trenProduksiBarChart"></canvas>
        </div>
    </div>

</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const ctx = document.getElementById('trenProduksiBarChart').getContext('2d');
        new Chart(ctx, {
            type: 'bar',
            data: {
                labels: {!! json_encode($labelGrafik) !!},
                datasets: [{
                    label: 'Jumlah Produksi (Pcs)',
                    data: {!! json_encode($dataGrafik) !!},
                    backgroundColor: '#15803d',
                    borderRadius: 8,
                    borderSkipped: false,
                    barThickness: 60 // Ukuran batang diperlebar sedikit agar pas dengan layout penuh
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: { display: false }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        grid: { color: '#f3f4f6' },
                        ticks: { color: '#9ca3af', font: { weight: 'bold' } }
                    },
                    x: {
                        grid: { display: false },
                        ticks: { color: '#4b5563', font: { weight: 'bold' } }
                    }
                }
            }
        });
    });
</script>
@endsection