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

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

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

@section('content')
    @php require resource_path('views/admin/partials/list-theme.php'); @endphp

    <div class="{{ $adminListPageClass }}">
        <div class="{{ $adminListHeaderCardClass }}">
            <div class="flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between">
                <div>
                    <a href="{{ route('admin.appointments.index') }}" class="text-sm font-semibold text-indigo-600 hover:text-indigo-700">← 返回任命管理</a>
                    <h2 class="mt-2 {{ $adminListHeaderTitleClass }}">历史任职记录</h2>
                    <p class="{{ $adminListHeaderSubtitleClass }}">已撤销的职务记录（共 {{ $history->total() }} 条）</p>
                </div>
            </div>
        </div>

        <div class="{{ $adminListCardClass }}">
            <div class="{{ $adminListSectionHeadClass }}">
                <h3 class="{{ $adminListSectionTitleClass }}">任职历史列表</h3>
                <p class="{{ $adminListSectionDescClass }}">按撤销后的记录保留完整的任命与撤销链路，便于审计追踪。</p>
            </div>
            <div class="{{ $adminListTableWrapClass }}">
                <table class="{{ $adminListTableClass }} whitespace-nowrap">
                    <thead>
                        <tr class="{{ $adminListTableHeadRowClass }}">
                            <th class="{{ $adminListTableHeadCellClass }}">用户</th>
                            <th class="{{ $adminListTableHeadCellClass }}">职务</th>
                            <th class="{{ $adminListTableHeadCellClass }}">任命人</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">任命时间</th>
                            <th class="{{ $adminListTableHeadCellClass }}">撤销人</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">撤销时间</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">在职天数</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($history as $up)
                            <tr class="{{ $adminListTableRowClass }}">
                                <td class="px-4 py-3 {{ $adminListPrimaryTextClass }}">{{ $up->user->username }}</td>
                                <td class="px-4 py-3">
                                    <div class="flex items-center gap-1">
                                        <span>{{ $up->position->icon }}</span>
                                        <span class="text-sm font-semibold" style="color: {{ $up->position->department->color }}">{{ $up->position->name }}</span>
                                        <span class="{{ $adminListSecondaryTextClass }}">{{ $up->position->department->name }}</span>
                                    </div>
                                </td>
                                <td class="px-4 py-3 {{ $adminListBodyTextClass }}">{{ $up->appointedBy?->username ?? '系统' }}</td>
                                <td class="px-4 py-3 text-center {{ $adminListSecondaryTextClass }}">{{ $up->appointed_at->format('Y-m-d') }}</td>
                                <td class="px-4 py-3 {{ $adminListBodyTextClass }}">{{ $up->revokedBy?->username ?? '系统' }}</td>
                                <td class="px-4 py-3 text-center {{ $adminListSecondaryTextClass }}">{{ $up->revoked_at?->format('Y-m-d') ?? '—' }}</td>
                                <td class="px-4 py-3 text-center">
                                    <span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-semibold text-gray-600">{{ $up->duration_days }} 天</span>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="{{ $adminListEmptyClass }}">暂无历史记录</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if ($history->hasPages())
                <div class="{{ $adminListPaginationClass }}">{{ $history->links() }}</div>
            @endif
        </div>
    </div>
@endsection
