@extends('layouts.app')

@section('title', 'Manajemen Jenis Ketunaan')

@section('content')
<div class="container-fluid">
    <div class="row mb-3">
        <div class="col-12">
            <h2 class="h4 mb-0">Manajemen Jenis Ketunaan</h2>
            <p class="text-muted">Kelola data jenis ketunaan siswa</p>
        </div>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    @if(session('error'))
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
            <h5 class="mb-0">Daftar Jenis Ketunaan</h5>
            <a href="{{ route('superadmin.disability-types.create') }}" class="btn btn-light btn-sm">
                <i class="bi bi-plus-circle me-1"></i> Tambah Jenis Ketunaan
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <thead class="table-light">
                        <tr>
                            <th style="width: 5%">#</th>
                            <th style="width: 15%">Kode</th>
                            <th style="width: 25%">Nama</th>
                            <th style="width: 35%">Deskripsi</th>
                            <th style="width: 10%" class="text-center">Status</th>
                            <th style="width: 10%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($disabilityTypes as $index => $type)
                            <tr>
                                <td>{{ $disabilityTypes->firstItem() + $index }}</td>
                                <td><strong>{{ $type->code }}</strong></td>
                                <td>{{ $type->name }}</td>
                                <td>{{ Str::limit($type->description ?? '-', 50) }}</td>
                                <td class="text-center">
                                    @if($type->is_active)
                                        <span class="badge bg-success">Aktif</span>
                                    @else
                                        <span class="badge bg-secondary">Nonaktif</span>
                                    @endif
                                </td>
                                <td class="text-center">
                                    <div class="btn-group btn-group-sm" role="group">
                                        <a href="{{ route('superadmin.disability-types.edit', $type) }}" 
                                           class="btn btn-outline-primary" 
                                           title="Edit">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form action="{{ route('superadmin.disability-types.toggle-active', $type) }}" 
                                              method="POST" 
                                              class="d-inline">
                                            @csrf
                                            @method('PATCH')
                                            <button type="submit" 
                                                    class="btn btn-outline-{{ $type->is_active ? 'warning' : 'success' }}" 
                                                    title="{{ $type->is_active ? 'Nonaktifkan' : 'Aktifkan' }}">
                                                <i class="bi bi-{{ $type->is_active ? 'eye-slash' : 'eye' }}"></i>
                                            </button>
                                        </form>
                                        <form action="{{ route('superadmin.disability-types.destroy', $type) }}" 
                                              method="POST" 
                                              class="d-inline"
                                              onsubmit="return confirm('Yakin ingin menghapus jenis ketunaan ini?')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" 
                                                    class="btn btn-outline-danger" 
                                                    title="Hapus">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center py-4">
                                    <i class="bi bi-inbox text-muted" style="font-size: 3rem;"></i>
                                    <p class="text-muted mt-2">Belum ada data jenis ketunaan</p>
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            @if($disabilityTypes->hasPages())
                <div class="mt-3">
                    {{ $disabilityTypes->links() }}
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
