{{--
    文件功能：亲密度变更日志审计页

    @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-4 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <h2 class="{{ $adminListHeaderTitleClass }}">💞 亲密度变更日志</h2>
                    <p class="{{ $adminListHeaderSubtitleClass }}">按统一后台列表样式审计婚姻亲密度的增减来源与余额变化。</p>
                </div>
                <a href="{{ route('admin.marriages.index') }}" class="{{ $adminListSecondaryButtonClass }}">返回总览</a>
            </div>
        </div>

        <div class="{{ $adminListFilterCardClass }}">
            <div class="{{ $adminListFilterInnerClass }}">
                <form method="GET" class="{{ $adminListFilterFormClass }}">
                    <div>
                        <label class="{{ $adminListFilterLabelClass }}">搜索用户名</label>
                        <input type="text" name="search" value="{{ request('search') }}" placeholder="双方任一用户名..."
                            class="w-44 {{ $adminListFilterInputClass }}">
                    </div>
                    <div>
                        <label class="{{ $adminListFilterLabelClass }}">来源（Source）</label>
                        <select name="source" class="{{ $adminListFilterInputClass }}">
                            <option value="">全部</option>
                            @foreach (\App\Enums\IntimacySource::cases() as $src)
                                <option value="{{ $src->value }}" @selected(request('source') === $src->value)>
                                    {{ $src->label() }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <button type="submit" class="{{ $adminListPrimaryButtonClass }}">筛选</button>
                    <a href="{{ route('admin.marriages.intimacy-logs') }}" class="{{ $adminListSecondaryButtonClass }}">重置</a>
                </form>
            </div>
        </div>

        <div class="{{ $adminListCardClass }}">
            <div class="{{ $adminListSectionHeadClass }}">
                <div>
                    <h3 class="{{ $adminListSectionTitleClass }}">亲密度日志</h3>
                    <p class="{{ $adminListSectionDescClass }}">保留增减与来源的颜色语义，其他样式对齐统一列表页。</p>
                </div>
            </div>
            <div class="{{ $adminListTableWrapClass }}">
                <table class="{{ $adminListTableClass }}">
                    <thead>
                        <tr class="{{ $adminListTableHeadRowClass }}">
                            <th class="{{ $adminListTableHeadCellClass }}">ID</th>
                            <th class="{{ $adminListTableHeadCellClass }}">婚姻双方</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">变动量</th>
                            <th class="{{ $adminListTableHeadCellClass }} text-center">变后余额</th>
                            <th class="{{ $adminListTableHeadCellClass }}">来源</th>
                            <th class="{{ $adminListTableHeadCellClass }}">备注</th>
                            <th class="{{ $adminListTableHeadCellClass }}">时间</th>
                        </tr>
                    </thead>
                    <tbody class="{{ $adminListTableBodyClass }}">
                        @forelse ($logs as $log)
                            <tr class="{{ $adminListTableRowClass }}">
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }} {{ $adminListNumericTextClass }}">{{ $log->id }}</td>
                                <td class="px-4 py-3">
                                    <span class="{{ $adminListPrimaryTextClass }}">{{ $log->marriage?->user?->username }}</span>
                                    <span class="mx-1 text-gray-400">×</span>
                                    <span class="{{ $adminListPrimaryTextClass }}">{{ $log->marriage?->partner?->username }}</span>
                                </td>
                                <td class="px-4 py-3 text-center font-semibold {{ $log->amount >= 0 ? 'text-green-600' : 'text-red-500' }}">
                                    {{ $log->amount >= 0 ? '+' : '' }}{{ $log->amount }}
                                </td>
                                <td class="px-4 py-3 text-center font-semibold text-indigo-600">
                                    {{ number_format($log->balance_after) }}
                                </td>
                                <td class="px-4 py-3">
                                    <span class="{{ $adminListBadgeBaseClass }} border-purple-200 bg-purple-50 text-purple-700">
                                        {{ \App\Enums\IntimacySource::tryFrom($log->source)?->label() ?? $log->source }}
                                    </span>
                                </td>
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }}">{{ $log->remark ?? '—' }}</td>
                                <td class="px-4 py-3 {{ $adminListSecondaryTextClass }}">
                                    {{ $log->created_at?->format('m-d H:i') }}
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="{{ $adminListEmptyClass }}">暂无记录</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if ($logs->hasPages())
                <div class="{{ $adminListPaginationClass }}">{{ $logs->links() }}</div>
            @endif
        </div>
    </div>

@endsection
