@extends('layouts.app')

@section('title', 'Yarn Stock')

@section('breadcrumb')
    @include('components.breadcrumb', ['items' => ['Stock Management' => null, 'Yarn Stock' => 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">Yarn Stock Inventory</h1>
            <p class="text-sm text-slate-500 dark:text-slate-400 mt-1">Real-time stock valuation and status</p>
        </div>
        <div class="flex flex-wrap items-center gap-2">
            <x-button variant="outline" icon="printer">Print</x-button>
            <x-button variant="success" icon="file-spreadsheet">Export</x-button>
        </div>
    </div>

    <div class="grid grid-cols-2 lg:grid-cols-5 gap-4 mb-6">
        <x-stat-card title="Yarn Types" :value="$summary['total_types']" prefix="" icon="package" iconBg="primary" />
        <x-stat-card title="Total Bags" :value="$summary['total_bags']" prefix="" icon="boxes" iconBg="info" />
        <x-stat-card title="Total Qty" :value="$summary['total_qty']" prefix="" icon="weight" iconBg="purple" />
        <x-stat-card title="Total Value" :value="$summary['total_value']" icon="circle-dollar-sign" iconBg="success" />
        <x-stat-card title="Low Stock" :value="$summary['low_stock'] + $summary['out_of_stock']" prefix="" icon="alert-triangle" iconBg="warning" />
    </div>

    <x-card :padding="false">
        <div class="p-4 border-b border-slate-200 dark:border-slate-800 flex flex-col sm:flex-row gap-3">
            <div class="flex-1 relative">
                <i data-lucide="search" class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"></i>
                <input type="text" placeholder="Search by yarn name or code..." class="w-full pl-10 pr-3 py-2 text-sm bg-slate-50 dark:bg-slate-800 border-0 rounded-xl focus:ring-2 focus:ring-primary-500" />
            </div>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="bg-slate-50 dark:bg-slate-900/50 border-b border-slate-200 dark:border-slate-800">
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase tracking-wider text-slate-500">Yarn</th>
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase tracking-wider text-slate-500">Code</th>
                        <th class="px-4 py-3 text-right text-[11px] font-bold uppercase tracking-wider text-slate-500">Bags</th>
                        <th class="px-4 py-3 text-right text-[11px] font-bold uppercase tracking-wider text-slate-500">Quantity (kg)</th>
                        <th class="px-4 py-3 text-right text-[11px] font-bold uppercase tracking-wider text-slate-500">Avg Cost</th>
                        <th class="px-4 py-3 text-right text-[11px] font-bold uppercase tracking-wider text-slate-500">Current Value</th>
                        <th class="px-4 py-3 text-center text-[11px] font-bold uppercase tracking-wider text-slate-500">Status</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
                    @forelse($stocks as $stock)
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50 transition">
                            <td class="px-4 py-3.5">
                                <div class="font-semibold text-slate-900 dark:text-white">{{ $stock->name }}</div>
                                <div class="text-xs text-slate-500">{{ $stock->category ?? '—' }} · {{ $stock->code }}</div>
                            </td>
                            <td class="px-4 py-3.5 text-xs font-mono text-slate-600">{{ $stock->code }}</td>
                            <td class="px-4 py-3.5 text-right text-sm font-semibold counter-num">{{ number_format($stock->bags) }}</td>
                            <td class="px-4 py-3.5 text-right text-sm counter-num">{{ number_format($stock->quantity) }} kg</td>
                            <td class="px-4 py-3.5 text-right text-sm counter-num">৳{{ number_format($stock->avg_cost) }}</td>
                            <td class="px-4 py-3.5 text-right text-sm font-bold text-primary-600 counter-num">৳{{ number_format($stock->stock_value) }}</td>
                            <td class="px-4 py-3.5 text-center">
                                <x-badge :variant="match($stock->status) { 'in_stock' => 'success', 'low_stock' => 'warning', default => 'danger' }">
                                    {{ ucwords(str_replace('_', ' ', $stock->status)) }}
                                </x-badge>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="text-center py-8 text-sm text-slate-500">No stock records found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </x-card>
</div>
@endsection
