@extends('layouts.app')
@section('title', 'Stock Ledger')
@section('breadcrumb')
    @include('components.breadcrumb', ['items' => ['Stock' => route('stock.index'), 'Ledger' => null]])
@endsection
@section('content')
<div>
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
        <div><h1 class="text-2xl font-bold text-slate-900 dark:text-white">Stock Ledger</h1><p class="text-sm text-slate-500 mt-1">Full audit trail of all stock movements</p></div>
        <div class="flex flex-wrap gap-2">
            <x-button variant="outline" icon="printer">Print</x-button>
            <x-button variant="success" icon="file-spreadsheet">Export</x-button>
        </div>
    </div>
    <x-card :padding="false">
        <table class="w-full text-sm">
            <thead><tr class="bg-slate-50 dark:bg-slate-900/50 border-b border-slate-200">
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Date</th>
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Vch</th>
                <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Particulars</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">In</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Out</th>
                <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Balance</th>
            </tr></thead>
            <tbody class="divide-y divide-slate-100">
                @forelse($entries as $e)
                <tr class="hover:bg-slate-50/50">
                    <td class="px-4 py-3 text-xs text-slate-500">{{ $e->transaction_date->format('d M Y') }}</td>
                    <td class="px-4 py-3 text-xs font-mono text-primary-600 font-semibold">{{ $e->voucher_no ?? '—' }}</td>
                    <td class="px-4 py-3 text-sm">{{ $e->yarn->name ?? '—' }}</td>
                    <td class="px-4 py-3 text-right text-emerald-600 font-semibold counter-num">{{ $e->in_qty > 0 ? '+' . number_format($e->in_qty) : '—' }}</td>
                    <td class="px-4 py-3 text-right text-rose-600 font-semibold counter-num">{{ $e->out_qty > 0 ? '-' . number_format($e->out_qty) : '—' }}</td>
                    <td class="px-4 py-3 text-right font-bold counter-num">{{ number_format($e->balance_qty) }}</td>
                </tr>
                @empty
                <tr><td colspan="6" class="text-center py-8 text-slate-500">No ledger entries.</td></tr>
                @endforelse
            </tbody>
        </table>
        @if($entries->hasPages())
        <div class="px-4 py-3 border-t border-slate-200">{{ $entries->withQueryString()->links() }}</div>
        @endif
    </x-card>
</div>
@endsection
