@extends('admin.layouts.app')

@section('content')
<div class="bg-gray-100 min-h-full p-4">
    
    <!-- Header Tab for List -->
    <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>List of Machine's</span>
    </div>

    <!-- Main Container -->
    <div class="bg-white p-6 shadow-sm min-h-[500px] border border-gray-200 border-t-0 flex flex-col justify-between">
        
        <!-- Table View -->
        <div class="flex-1">
            <div class="overflow-x-auto">
                <table class="w-full text-left border-collapse">
                    <thead>
                        <tr class="bg-gray-50 border-b">
                            <th class="p-3 text-sm font-semibold text-gray-700">Machine No</th>
                            <th class="p-3 text-sm font-semibold text-gray-700">Machine Name</th>
                            <th class="p-3 text-sm font-semibold text-gray-700">Type</th>
                            <th class="p-3 text-sm font-semibold text-gray-700">Branch</th>
                            <th class="p-3 text-sm font-semibold text-gray-700 text-right">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($machines as $machine)
                        <tr class="border-b hover:bg-gray-50">
                            <td class="p-3 text-sm text-gray-800">{{ $machine->machine_no }}</td>
                            <td class="p-3 text-sm text-gray-800">{{ $machine->machine_name }}</td>
                            <td class="p-3 text-sm text-gray-800">{{ $machine->machineType->name ?? '' }}</td>
                            <td class="p-3 text-sm text-gray-800">{{ $machine->branch->name ?? '' }}</td>
                            <td class="p-3 text-sm text-gray-800 text-right space-x-2">
                                <a href="{{ route('machines.edit', $machine->id) }}" class="text-blue-500 hover:text-blue-700"><i class="fa-solid fa-pen"></i></a>
                                <form action="{{ route('machines.destroy', $machine->id) }}" method="POST" class="inline-block">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-500 hover:text-red-700"><i class="fa-solid fa-trash"></i></button>
                                </form>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="5" class="p-8 text-center text-gray-500">No machines found.</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Table Action Buttons -->
        <div class="text-center space-x-2 pt-6">
            <a href="{{ route('machines.create') }}" class="bg-[#4caf50] hover:bg-[#43a047] text-white px-6 py-1.5 rounded shadow text-sm font-semibold inline-block">Add</a>
            <button class="bg-[#f44336] hover:bg-[#e53935] text-white px-6 py-1.5 rounded shadow text-sm font-semibold inline-block">Clear</button>
        </div>

    </div>
</div>
@endsection
