<div class="bg-white rounded-lg shadow-sm overflow-hidden">
    <x-table-swipe>
    <table class="min-w-full">
    <thead class="bg-gray-50 border-b">
        <tr>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">부서 코드</th>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">부서명</th>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">상위 부서</th>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">상태</th>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">정렬순서</th>
            <th class="px-6 py-3 text-left text-sm font-semibold text-gray-700 uppercase tracking-wider">작업</th>
        </tr>
    </thead>
    <tbody class="bg-white divide-y divide-gray-200">
        @forelse($departments as $department)
            <tr class="{{ $department->trashed() ? 'bg-red-50' : 'hover:bg-gray-50' }}">
                <td class="px-6 py-4 whitespace-nowrap text-sm {{ $department->trashed() ? 'text-gray-400' : 'text-gray-900' }}">
                    {{ $department->code }}
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <div class="text-sm font-medium {{ $department->trashed() ? 'text-gray-400' : 'text-gray-900' }}">{{ $department->name }}</div>
                    @if($department->description)
                        <div class="text-sm {{ $department->trashed() ? 'text-gray-300' : 'text-gray-500' }}">{{ Str::limit($department->description, 50) }}</div>
                    @endif
                </td>
                <td class="px-6 py-4 whitespace-nowrap text-sm {{ $department->trashed() ? 'text-gray-400' : 'text-gray-500' }}">
                    {{ $department->parent?->name ?? '-' }}
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    @if($department->trashed())
                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                            삭제됨
                        </span>
                    @elseif($department->is_active)
                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                            활성
                        </span>
                    @else
                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
                            비활성
                        </span>
                    @endif
                </td>
                <td class="px-6 py-4 whitespace-nowrap text-sm {{ $department->trashed() ? 'text-gray-400' : 'text-gray-500' }}">
                    {{ $department->sort_order }}
                </td>
                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                    @if($department->trashed())
                        <!-- 삭제된 항목 - 복원은 일반관리자도 가능, 영구삭제는 슈퍼관리자만 -->
                        <button onclick="confirmRestore({{ $department->id }}, '{{ $department->name }}')" class="text-green-600 hover:text-green-900 mr-3">
                            복원
                        </button>
                        @if(auth()->user()?->is_super_admin)
                        <button onclick="confirmForceDelete({{ $department->id }}, '{{ $department->name }}')" class="text-red-600 hover:text-red-900">
                            영구삭제
                        </button>
                        @endif
                    @else
                        <a href="{{ route('departments.edit', $department->id) }}" class="text-blue-600 hover:text-blue-900 mr-3">
                            수정
                        </a>
                        <button onclick="confirmDelete({{ $department->id }}, '{{ $department->name }}')" class="text-red-600 hover:text-red-900">
                            삭제
                        </button>
                    @endif
                </td>
            </tr>
        @empty
            <tr>
                <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                    부서가 없습니다.
                </td>
            </tr>
        @endforelse
    </tbody>
</table>
    </x-table-swipe>
</div>

<!-- 페이지네이션 -->
@include('partials.pagination', [
    'paginator' => $departments,
    'target' => '#department-table',
    'includeForm' => '#filterForm'
])