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

    @author   ChatRoom Laravel
    @version  1.0.0
--}}

@extends('admin.layouts.app')

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

@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">
            {{ $userPosition->position->icon }} {{ $userPosition->user->username }} · {{ $userPosition->position->name }}
        </h2>
        <p class="text-sm text-gray-500 mt-1">权限操作记录（共 {{ $logs->total() }} 条）</p>
    </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="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-center">操作类型</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>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                @forelse ($logs as $log)
                    @php $colorClass = $actionColors[$log->action_type] ?? 'bg-gray-100 text-gray-600'; @endphp
                    <tr class="hover:bg-gray-50">
                        <td class="px-4 py-3 text-gray-500 text-xs">{{ $log->created_at->format('m-d H:i:s') }}</td>
                        <td class="px-4 py-3 text-center">
                            <span class="text-xs px-2 py-0.5 rounded font-bold {{ $colorClass }}">
                                {{ $log->action_label }}
                            </span>
                        </td>
                        <td class="px-4 py-3 font-bold text-gray-700">{{ $log->targetUser->username ?? '—' }}</td>
                        <td class="px-4 py-3 text-gray-500">{{ $log->targetPosition?->name ?? '—' }}</td>
                        <td class="px-4 py-3 text-center text-yellow-600 font-bold">
                            {{ $log->amount ? number_format($log->amount) . ' 金币' : '—' }}
                        </td>
                        <td class="px-4 py-3 text-gray-400 text-xs">{{ $log->remark ?? '—' }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="px-4 py-12 text-center text-gray-400">暂无权限操作记录</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $logs->links() }}</div>
@endsection
