@extends('admin.layouts.app')

@section('title', 'FILE APP PORTAL - Modules Management')

@section('breadcrumbs')
    <i class="fa-solid fa-chevron-right mx-3 text-[8px]"></i>
    <span class="text-slate-900">Modules</span>
@endsection

@section('content')

<div class="space-y-6">
    <div class="flex items-center justify-between">
        <h1 class="text-2xl font-bold" style="color: #43B9B2;">Modules Management</h1>
        <a href="{{ route('admin.modules.create') }}" 
           class="rounded-lg px-4 py-2 text-white transition-colors hover:opacity-90" 
           style="background-color: #43B9B2;">
            <i class="fas fa-plus mr-2"></i>Add New Module
        </a>
    </div>

    <div class="rounded-lg bg-white shadow-md overflow-hidden">
        <table class="min-w-full divide-y divide-gray-200">
            <thead style="background-color: #EDF8F7;">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Name</th>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Slug</th>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Description</th>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Version</th>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Status</th>
                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider" style="color: #43B9B2;">Actions</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @forelse($modules as $module)
                    <tr>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">{{ $module->name }}</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">{{ $module->slug }}</div>
                        </td>
                        <td class="px-6 py-4">
                            <div class="text-sm text-gray-500">{{ Str::limit($module->description, 50) }}</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-500">{{ $module->version }}</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {{ $module->is_active ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' }}">
                                {{ $module->is_active ? 'Active' : 'Inactive' }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                            <form action="{{ route('admin.modules.toggle-status', $module) }}" method="POST" class="inline mr-2">
                                @csrf
                                <button type="submit" 
                                        class="text-yellow-600 hover:text-yellow-900"
                                        title="{{ $module->is_active ? 'Deactivate' : 'Activate' }}">
                                    <i class="fas fa-{{ $module->is_active ? 'pause' : 'play' }}"></i>
                                </button>
                            </form>
                            <a href="{{ route('admin.modules.edit', $module) }}" 
                               class="mr-3 text-blue-600 hover:text-blue-900">
                                <i class="fas fa-edit"></i>
                            </a>
                            <form action="{{ route('admin.modules.destroy', $module) }}" method="POST" class="inline">
                                @csrf
                                @method('DELETE')
                                <button type="submit" 
                                        class="text-red-600 hover:text-red-900"
                                        onclick="return confirm('Are you sure you want to delete this module?')">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                            No modules found. <a href="{{ route('admin.modules.create') }}" class="text-blue-600 hover:underline">Create one</a>
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection

