@extends('admin.layout')

@section('title', 'Riwayat Pergerakan Stok')

@section('content')
    <div class="card">
        <h1 style="margin-top:0">Riwayat Pergerakan Stok</h1>

        <form method="get" class="search-box">
            <select name="type" style="width:auto">
                <option value="">Semua Tipe</option>
                <option value="in" @selected(request('type') === 'in')>Masuk</option>
                <option value="out" @selected(request('type') === 'out')>Keluar</option>
                <option value="adjustment" @selected(request('type') === 'adjustment')>Penyesuaian</option>
            </select>
            <button class="btn" type="submit">Filter</button>
            <a class="btn ghost" href="{{ route('admin.stock-movements.index') }}">Reset</a>
        </form>

        <table>
            <thead>
                <tr>
                    <th>Tanggal</th>
                    <th>Produk</th>
                    <th>Tipe</th>
                    <th>Jumlah</th>
                    <th>Stok Sebelum</th>
                    <th>Stok Sesudah</th>
                    <th>Catatan</th>
                </tr>
            </thead>
            <tbody>
                @forelse($movements as $m)
                    <tr>
                        <td>{{ $m->created_at->format('d/m/Y H:i') }}</td>
                        <td>{{ $m->product->name ?? '-' }}</td>
                        <td>
                            @if($m->type === 'in')
                                <span class="badge badge-ok">{{ $m->type_label }}</span>
                            @elseif($m->type === 'out')
                                <span class="badge badge-low">{{ $m->type_label }}</span>
                            @else
                                <span class="badge badge-over">{{ $m->type_label }}</span>
                            @endif
                        </td>
                        <td>{{ $m->type === 'out' ? '-' : '+' }}{{ $m->quantity }}</td>
                        <td>{{ $m->stock_before }}</td>
                        <td>{{ $m->stock_after }}</td>
                        <td>{{ $m->notes ?? '-' }}</td>
                    </tr>
                @empty
                    <tr><td colspan="7" style="text-align:center;color:#6b7280">Belum ada riwayat pergerakan stok.</td></tr>
                @endforelse
            </tbody>
        </table>

        <div style="margin-top:12px">{{ $movements->links() }}</div>
    </div>
@endsection
