<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Daftar Semester') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <div class="flex justify-between items-center mb-4">
                        <h2 class="text-xl font-bold text-gray-900">Daftar Semester</h2>
                        <a href="{{ route('semesters.create') }}" class="btn-primary">Tambah Semester</a>
                    </div>
                    
                    @if(session('success'))
                        <div class="alert-success mb-4">{{ session('success') }}</div>
                    @endif
                    
                    <div class="overflow-x-auto">
                        <table class="table w-full border rounded-lg overflow-hidden">
                            <thead>
                                <tr class="table-header">
                                    <th class="px-3 py-2">No</th>
                                    <th class="px-3 py-2">Semester</th>
                                    <th class="px-3 py-2">Tahun Ajaran</th>
                                    <th class="px-3 py-2">Status</th>
                                    <th class="px-3 py-2">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($semesters as $i => $semester)
                                <tr class="table-row">
                                    <td class="px-3 py-2">{{ $i+1 }}</td>
                                    <td class="px-3 py-2">{{ $semester->semester }}</td>
                                    <td class="px-3 py-2">{{ $semester->tahun_ajaran }}</td>
                                    <td class="px-3 py-2">
                                        @if($semester->is_active)
                                            <span class="badge bg-success">Aktif</span>
                                        @else
                                            <span class="badge bg-secondary">Tidak Aktif</span>
                                        @endif
                                    </td>
                                    <td class="px-3 py-2 space-x-1">
                                        <a href="{{ route('semesters.edit', $semester) }}" class="btn-accent btn-sm">Edit</a>
                                        <form action="{{ route('semesters.destroy', $semester) }}" method="POST" style="display:inline-block">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn-primary btn-sm" onclick="return confirm('Yakin hapus?')">Delete</button>
                                        </form>
                                        @if(!$semester->is_active)
                                        <form action="{{ route('semesters.activate', $semester) }}" method="POST" style="display:inline-block">
                                            @csrf
                                            @method('PATCH')
                                            <button type="submit" class="btn-accent btn-sm">Aktifkan</button>
                                        </form>
                                        @endif
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout> 
