{{--
    文件功能：历史任职记录页面
    展示所有已撤销的职务记录（is_active=false），含任命人和撤销人信息

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '历史任职记录')

@section('content')
    <div class="mb-6">
        <a href="{{ route('admin.appointments.index') }}" class="text-sm text-indigo-600 hover:underline">← 返回任命管理</a>
        <h2 class="text-lg font-bold text-gray-800 mt-2">历史任职记录</h2>
        <p class="text-sm text-gray-500 mt-1">已撤销的职务记录（共 {{ $history->total() }} 条）</p>
    </div>

    <div class="bg-white rounded-xl shadow-sm border overflow-hidden">
        <table class="w-full text-sm">
            <thead class="bg-gray-50 text-gray-600 text-xs">
                <tr>
                    <th class="px-4 py-3 text-left">用户</th>
                    <th class="px-4 py-3 text-left">职务</th>
                    <th class="px-4 py-3 text-left">任命人</th>
                    <th class="px-4 py-3 text-center">任命时间</th>
                    <th class="px-4 py-3 text-left">撤销人</th>
                    <th class="px-4 py-3 text-center">撤销时间</th>
                    <th class="px-4 py-3 text-center">在职天数</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                @forelse ($history as $up)
                    <tr class="hover:bg-gray-50">
                        <td class="px-4 py-3 font-bold text-gray-800">{{ $up->user->username }}</td>
                        <td class="px-4 py-3">
                            <span class="mr-1">{{ $up->position->icon }}</span>
                            <span style="color: {{ $up->position->department->color }}">{{ $up->position->name }}</span>
                            <span class="text-xs text-gray-400 ml-1">{{ $up->position->department->name }}</span>
                        </td>
                        <td class="px-4 py-3 text-gray-500">{{ $up->appointedBy?->username ?? '系统' }}</td>
                        <td class="px-4 py-3 text-center text-gray-500 text-xs">{{ $up->appointed_at->format('Y-m-d') }}
                        </td>
                        <td class="px-4 py-3 text-gray-500">{{ $up->revokedBy?->username ?? '系统' }}</td>
                        <td class="px-4 py-3 text-center text-gray-500 text-xs">
                            {{ $up->revoked_at?->format('Y-m-d') ?? '—' }}</td>
                        <td class="px-4 py-3 text-center">
                            <span class="text-xs bg-gray-100 text-gray-600 px-2 py-0.5 rounded">{{ $up->duration_days }}
                                天</span>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="7" class="px-4 py-12 text-center text-gray-400">暂无历史记录</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $history->links() }}</div>
@endsection
