@extends('layouts.admin')

@section('title', 'Edit ' . $vehicle->full_name . ' – Admin CRM')
@section('page_title', 'Edit Vehicle: ' . $vehicle->full_name)

@section('content')
<div class="max-w-4xl space-y-6">
    
    <div class="flex items-center justify-between">
        <a href="{{ route('admin.inventory.index') }}" class="text-xs font-bold text-slate-400 hover:text-white flex items-center gap-1.5">
            <i class="fa-solid fa-arrow-left"></i>
            <span>Back to Inventory</span>
        </a>
        <span class="font-mono text-xs text-red-400 font-bold">Stock #{{ $vehicle->stock_number }}</span>
    </div>

    @if($errors->any())
        <div class="p-4 rounded-xl bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs space-y-1">
            <span class="font-bold block">Validation Errors:</span>
            <ul class="list-disc pl-5 space-y-0.5">
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form method="POST" action="{{ route('admin.inventory.update', $vehicle->id) }}" class="bg-slate-900 border border-white/10 rounded-2xl p-6 sm:p-8 shadow-xl space-y-6">
        @csrf
        @method('PUT')

        <h3 class="text-base font-bold text-white font-heading border-b border-white/10 pb-3">Edit Specifications & Pricing</h3>

        <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Make / Brand *</label>
                <input type="text" name="make" value="{{ old('make', $vehicle->make) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Model *</label>
                <input type="text" name="model" value="{{ old('model', $vehicle->model) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Variant / Trim</label>
                <input type="text" name="variant" value="{{ old('variant', $vehicle->variant) }}" class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
        </div>

        <div class="grid grid-cols-2 sm:grid-cols-4 gap-4">
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Year *</label>
                <input type="number" name="year" value="{{ old('year', $vehicle->year) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Chassis Number *</label>
                <input type="text" name="chassis_number" value="{{ old('chassis_number', $vehicle->chassis_number) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none uppercase">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Displacement (CC) *</label>
                <input type="number" name="engine_cc" value="{{ old('engine_cc', $vehicle->engine_cc) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Mileage (KM) *</label>
                <input type="number" name="mileage" value="{{ old('mileage', $vehicle->mileage) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">
            </div>
        </div>

        <div class="grid grid-cols-2 sm:grid-cols-4 gap-4">
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Fuel Type *</label>
                <select name="fuel_type" class="w-full bg-slate-950 border border-white/10 rounded-xl px-3 py-2.5 text-white text-xs font-semibold">
                    <option value="Hybrid" {{ $vehicle->fuel_type === 'Hybrid' ? 'selected' : '' }}>Hybrid</option>
                    <option value="Petrol" {{ $vehicle->fuel_type === 'Petrol' ? 'selected' : '' }}>Petrol</option>
                    <option value="Diesel" {{ $vehicle->fuel_type === 'Diesel' ? 'selected' : '' }}>Diesel</option>
                    <option value="Electric" {{ $vehicle->fuel_type === 'Electric' ? 'selected' : '' }}>Electric</option>
                </select>
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Transmission *</label>
                <input type="text" name="transmission" value="{{ old('transmission', $vehicle->transmission) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Drive Type *</label>
                <select name="drive_type" class="w-full bg-slate-950 border border-white/10 rounded-xl px-3 py-2.5 text-white text-xs font-semibold">
                    <option value="2WD" {{ $vehicle->drive_type === '2WD' ? 'selected' : '' }}>2WD</option>
                    <option value="4WD" {{ $vehicle->drive_type === '4WD' ? 'selected' : '' }}>4WD</option>
                    <option value="AWD" {{ $vehicle->drive_type === 'AWD' ? 'selected' : '' }}>AWD</option>
                </select>
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Body Type *</label>
                <input type="text" name="body_type" value="{{ old('body_type', $vehicle->body_type) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
        </div>

        <div class="grid grid-cols-2 sm:grid-cols-4 gap-4">
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Color *</label>
                <input type="text" name="color" value="{{ old('color', $vehicle->color) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Auction Grade *</label>
                <input type="text" name="auction_grade" value="{{ old('auction_grade', $vehicle->auction_grade) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Selling Price (BDT) *</label>
                <input type="number" name="selling_price_bdt" value="{{ old('selling_price_bdt', $vehicle->selling_price_bdt) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Discount (BDT)</label>
                <input type="number" name="discount_bdt" value="{{ old('discount_bdt', $vehicle->discount_bdt) }}" class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
            </div>
        </div>

        <div>
            <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Main Vehicle Image URL *</label>
            <input type="url" name="main_image" value="{{ old('main_image', $vehicle->main_image) }}" required class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold">
        </div>

        <div class="grid grid-cols-2 gap-4">
            <div>
                <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Inventory Status *</label>
                <select name="status" class="w-full bg-slate-950 border border-white/10 rounded-xl px-3 py-2.5 text-white text-xs font-semibold">
                    <option value="available" {{ $vehicle->status === 'available' ? 'selected' : '' }}>Available in Showroom</option>
                    <option value="reserved" {{ $vehicle->status === 'reserved' ? 'selected' : '' }}>Reserved / Deposit Paid</option>
                    <option value="sold" {{ $vehicle->status === 'sold' ? 'selected' : '' }}>Sold</option>
                    <option value="arriving" {{ $vehicle->status === 'arriving' ? 'selected' : '' }}>Arriving at Port</option>
                </select>
            </div>
            <div class="flex items-center pt-5">
                <label class="flex items-center gap-2 cursor-pointer text-xs font-semibold text-white">
                    <input type="checkbox" name="is_featured" value="1" {{ $vehicle->is_featured ? 'checked' : '' }} class="rounded accent-red-600">
                    <span>Feature on Homepage Showcase</span>
                </label>
            </div>
        </div>

        <div>
            <label class="block text-xs font-bold uppercase tracking-wider text-slate-300 mb-1">Description & Factory Options</label>
            <textarea name="description" rows="3" class="w-full bg-slate-950 border border-white/10 rounded-xl px-4 py-2.5 text-white text-xs font-semibold focus:border-red-500 focus:outline-none">{{ old('description', $vehicle->description) }}</textarea>
        </div>

        <button type="submit" class="px-6 py-3 rounded-xl bg-red-600 hover:bg-red-700 text-white font-bold text-xs shadow-lg shadow-red-900/30 transition flex items-center gap-2">
            <i class="fa-solid fa-floppy-disk"></i>
            <span>Update Vehicle Record</span>
        </button>
    </form>

</div>
@endsection
