@extends('admin.layouts.app')

@section('content')
<div class="bg-gray-100 min-h-full p-4">
    
    <!-- Header Tab -->
    <div class="bg-[#ff9800] text-white px-4 py-2 font-bold flex items-center shadow-sm">
        <i class="fa-solid fa-list-ul mr-2"></i> 
        <span>Add/Edit Machine</span>
    </div>

    <!-- Main Container -->
    <div class="bg-white p-6 shadow-sm min-h-[500px] border border-gray-200 border-t-0">
        
        <form action="{{ route('machines.update', $machine->id) }}" method="POST">
            @csrf
            @method('PUT')
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                
                <!-- Col 1 -->
                <div class="space-y-4">
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Machine No <span class="text-red-500">*</span></label>
                        <input type="number" name="machine_no" value="{{ old('machine_no', $machine->machine_no) }}" required class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                    </div>
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Port No.</label>
                        <input type="text" name="port_no" value="{{ old('port_no', $machine->port_no) }}" class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                    </div>
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Select Country Time Zone <span class="text-red-500">*</span></label>
                        <select name="timezone" required class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                            <option value="">Select a TimeZone</option>
                            <option value="Asia/Kolkata" {{ old('timezone', $machine->timezone) == 'Asia/Kolkata' ? 'selected' : '' }}>Asia/Kolkata (IST)</option>
                            <option value="UTC" {{ old('timezone', $machine->timezone) == 'UTC' ? 'selected' : '' }}>UTC</option>
                        </select>
                    </div>
                </div>

                <!-- Col 2 -->
                <div class="space-y-4">
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Machine Type</label>
                        <select name="machine_type_id" required class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                            @foreach($machineTypes as $type)
                                <option value="{{ $type->id }}" {{ old('machine_type_id', $machine->machine_type_id) == $type->id ? 'selected' : '' }}>{{ $type->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Machine Name</label>
                        <input type="text" name="machine_name" value="{{ old('machine_name', $machine->machine_name) }}" class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                    </div>
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">In/Out Only for Access Control</label>
                        <select name="in_out_mode" class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                            <option value="In" {{ old('in_out_mode', $machine->in_out_mode) == 'In' ? 'selected' : '' }}>In</option>
                            <option value="Out" {{ old('in_out_mode', $machine->in_out_mode) == 'Out' ? 'selected' : '' }}>Out</option>
                            <option value="Both" {{ old('in_out_mode', $machine->in_out_mode) == 'Both' ? 'selected' : '' }}>Both</option>
                        </select>
                    </div>
                </div>

                <!-- Col 3 -->
                <div class="space-y-4">
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Serial No</label>
                        <input type="text" name="serial_no" value="{{ old('serial_no', $machine->serial_no) }}" class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                    </div>
                    <div>
                        <label class="block text-xs font-bold text-gray-800 mb-1">Branch Name <span class="text-red-500">*</span></label>
                        <select name="branch_id" required class="w-full border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:border-[#ff9800]">
                            <option value="">Select Branch...</option>
                            @foreach($branches as $branch)
                                <option value="{{ $branch->id }}" {{ old('branch_id', $machine->branch_id) == $branch->id ? 'selected' : '' }}>{{ $branch->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

            </div>

            <!-- Form Action Buttons -->
            <div class="mt-12 text-center space-x-2 pb-4">
                <button type="submit" class="bg-[#4caf50] hover:bg-[#43a047] text-white px-6 py-1.5 rounded shadow text-sm font-semibold">Update</button>
                <a href="{{ route('machines.index') }}" class="bg-[#f44336] hover:bg-[#e53935] text-white px-6 py-1.5 rounded shadow text-sm font-semibold inline-block">Cancel</a>
            </div>
        </form>

    </div>
</div>
@endsection
