@extends('layouts.aura-main')

@section('main-content')
<div class="max-w-3xl mx-auto pb-20">
    <div class="mb-8 border-b border-slate-200 pb-4">
        <h1 class="text-2xl font-black text-slate-900 tracking-tighter">New Stock Adjustment</h1>
        <p class="text-[10px] font-bold text-slate-400 tracking-widest uppercase">Manual reconciliation for found or damaged items</p>
    </div>

    <form action="{{ route('inventory.adjustments.store') }}" 
          method="POST" 
          x-data="{ 
            prices: {{ $products->pluck('last_price', 'id') }},
            selectedPrice: 0,
            updatePrice(id) { 
                this.selectedPrice = this.prices[id] || 0;
            }
          }"
          class="bg-white border border-slate-300 p-8 rounded-sm shadow-sm">
        @csrf
        <div class="grid grid-cols-1 gap-6">
            
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Target Item</label>
                    <select name="product_id" 
                            @change="updatePrice($event.target.value)"
                            class="w-full border-slate-300 text-sm font-bold rounded-sm focus:ring-indigo-600 focus:border-indigo-600" 
                            required>
                        <option value="">Select Product...</option>
                        @foreach($products as $product)
                            <option value="{{ $product->id }}">{{ $product->name }} ({{ $product->sku }})</option>
                        @endforeach
                    </select>
                </div>
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Storage Location</label>
                    <select name="warehouse_id" class="w-full border-slate-300 text-sm font-bold rounded-sm" required>
                        @foreach($warehouses as $wh)
                            <option value="{{ $wh->id }}">{{ $wh->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="grid grid-cols-3 gap-4">
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Adjustment Mode</label>
                    <select name="adjustment_type" class="w-full border-slate-300 text-sm font-bold rounded-sm">
                        <option value="add">Quantity Addition (+)</option>
                        <option value="subtract">Quantity Reduction (-)</option>
                    </select>
                </div>
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Quantity</label>
                    <input type="number" step="0.01" name="quantity" class="w-full border-slate-300 text-sm font-mono font-bold rounded-sm" placeholder="0.00" required>
                </div>
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Unit Cost (ZMW)</label>
                    <input type="number" 
                           step="0.01" 
                           name="unit_cost" 
                           x-model="selectedPrice"
                           class="w-full border-slate-300 text-sm font-mono font-bold rounded-sm bg-slate-50 focus:bg-white transition" 
                           placeholder="0.00" 
                           required>
                </div>
            </div>

            <div class="grid grid-cols-2 gap-4">
                 <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Adjustment Date</label>
                    <input type="date" name="date" value="{{ date('Y-m-d') }}" class="w-full border-slate-300 text-sm font-bold rounded-sm" required>
                </div>
                <div>
                    <label class="block text-[10px] font-black text-slate-500 mb-2 uppercase">Reason / Description</label>
                    <input type="text" name="reason" class="w-full border-slate-300 text-sm font-medium rounded-sm" placeholder="e.g. Broken in transit" required>
                </div>
            </div>

            <div class="pt-6 border-t border-slate-100 flex justify-end gap-3">
                <a href="{{ route('inventory.adjustments.index') }}" class="px-6 py-2 text-[10px] font-black tracking-widest text-slate-400 hover:text-slate-900 transition uppercase">Cancel</a>
                <button type="submit" class="bg-slate-900 text-white px-8 py-2 text-[10px] font-black tracking-widest shadow-lg hover:bg-indigo-600 transition-all uppercase">
                    Save Adjustment
                </button>
            </div>
        </div>
    </form>
</div>
@endsection