{{--
    文件功能：在职期间权限操作日志子页
    展示某任职记录期间该用户的所有权限操作（任命/撤销/奖励/警告/踢出/禁言/封IP等）

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

@section('title', '权限操作日志 · ' . $userPosition->user->username)

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

    <div class="{{ $adminListPageClass }}">
        <div class="{{ $adminListHeaderCardClass }}">
            <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 }}">
                    {{ $userPosition->position->icon }} {{ $userPosition->user->username }} · {{ $userPosition->position->name }}
                </h2>
                <p class="{{ $adminListHeaderSubtitleClass }}">权限操作记录（共 {{ $logs->total() }} 条）</p>
            </div>
        </div>

    @php
        $actionColors = [
            'appoint' => 'bg-green-100 text-green-700',
            'revoke' => 'bg-red-100 text-red-700',
            'reward' => 'bg-yellow-100 text-yellow-700',
            'warn' => 'bg-orange-100 text-orange-700',
            'kick' => 'bg-red-100 text-red-700',
            'mute' => 'bg-purple-100 text-purple-700',
            'banip' => 'bg-gray-200 text-gray-700',
            'other' => 'bg-gray-100 text-gray-600',
        ];
    @endphp

        <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 }} text-center">操作类型</th>
                            <th class="{{ $adminListTableHeadCellClass }}">操作对象</th>
                            <th class="{{ $adminListTableHeadCellClass }}">目标职务</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">奖励金额</th>
                            <th class="{{ $adminListTableHeadCellClass }}">备注</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($logs as $log)
                            @php $colorClass = $actionColors[$log->action_type] ?? 'bg-gray-100 text-gray-600'; @endphp
                            <tr class="{{ $adminListTableRowClass }}">
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }}">{{ $log->created_at->format('m-d H:i:s') }}</td>
                                <td class="px-4 py-3 text-center">
                                    <span class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-semibold {{ $colorClass }}">
                                        {{ $log->action_label }}
                                    </span>
                                </td>
                                <td class="px-4 py-3 {{ $adminListPrimaryTextClass }}">{{ $log->targetUser->username ?? '—' }}</td>
                                <td class="px-4 py-3 {{ $adminListBodyTextClass }}">{{ $log->targetPosition?->name ?? '—' }}</td>
                                <td class="px-4 py-3 text-center text-sm font-semibold text-yellow-600">
                                    {{ $log->amount ? number_format($log->amount) . ' 金币' : '—' }}
                                </td>
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }}">{{ $log->remark ?? '—' }}</td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="{{ $adminListEmptyClass }}">暂无权限操作记录</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if ($logs->hasPages())
                <div class="{{ $adminListPaginationClass }}">{{ $logs->links() }}</div>
            @endif
        </div>
    </div>
@endsection
