@extends('layouts.app')

@section('content')
    <div class="rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[0.03] p-5 lg:p-6">
        <div class="mb-6">
            <h2 class="text-xl font-semibold text-gray-800 dark:text-white/90">{{ $title }}</h2>
        </div>

        <form action="{{ route('stock.incoming.store') }}" method="POST" class="space-y-5">
            @csrf
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-5">
                <x-form.select 
                    name="material_id" 
                    label="Bahan"
                    placeholder="Pilih Bahan"
                    :value="old('material_id')"
                    :options="$materials->mapWithKeys(fn($m) => [$m->id => $m->name . ' (' . $m->unit . ') - Stok: ' . number_format($m->stock, 2, ',', '.')])->toArray()"
                    :searchable="true"
                    :required="true"
                />

                <div>
                    <label for="quantity" class="mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300">
                        Jumlah <span class="text-error-500">*</span>
                    </label>
                    <input type="number" name="quantity" id="quantity" value="{{ old('quantity') }}" min="0.01" step="any"
                        class="h-11 block w-full rounded-lg border border-gray-300 bg-transparent px-4 py-2.5 text-sm text-gray-800 focus:border-brand-500 focus:ring-brand-500 dark:border-gray-600 dark:text-white/90"
                        required>
                    @error('quantity')
                        <p class="mt-1 text-xs text-error-500">{{ $message }}</p>
                    @enderror
                </div>

                <div>
                    <label for="unit_price" class="mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300">
                        Harga Satuan (Modal)
                    </label>
                    <input type="number" name="unit_price" id="unit_price" value="{{ old('unit_price', 0) }}" min="0" step="any"
                        class="h-11 block w-full rounded-lg border border-gray-300 bg-transparent px-4 py-2.5 text-sm text-gray-800 focus:border-brand-500 focus:ring-brand-500 dark:border-gray-600 dark:text-white/90">
                </div>

                <div>
                    <label for="notes" class="mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300">
                        Catatan
                    </label>
                    <input type="text" name="notes" id="notes" value="{{ old('notes') }}" placeholder="Contoh: Pembelian dari Supplier A"
                        class="h-11 block w-full rounded-lg border border-gray-300 bg-transparent px-4 py-2.5 text-sm text-gray-800 focus:border-brand-500 focus:ring-brand-500 dark:border-gray-600 dark:text-white/90">
                </div>
            </div>

            <div class="flex items-center justify-end gap-3 pt-4">
                <a href="{{ route('stock.incoming.index') }}"
                    class="rounded-lg border border-gray-300 px-4 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800">
                    Batal
                </a>
                <button type="submit"
                    class="rounded-lg bg-success-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-success-600">
                    Tambah Stok
                </button>
            </div>
        </form>
    </div>
@endsection
