@extends('layouts.app')

@section('title', 'History · '.$asset->asset_tag)

@section('content')
    <x-page-header
        title="Activity History"
        :subtitle="$asset->asset_tag.' · '.$asset->name">
        <x-slot:breadcrumbs>
            <li class="breadcrumb-item"><a href="{{ route('assets.index') }}">Assets</a></li>
            <li class="breadcrumb-item"><a href="{{ route('assets.show', $asset) }}">{{ $asset->asset_tag }}</a></li>
            <li class="breadcrumb-item active" aria-current="page">History</li>
        </x-slot:breadcrumbs>

        <a href="{{ route('assets.show', $asset) }}" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left" aria-hidden="true"></i>Back to Asset
        </a>
    </x-page-header>

    {{--
        Everything the Auditable trail knows today — created, edited, status
        changes, deleted, restored. This is the same feed Phase 5 assignment
        and return events land in once AssignmentService starts writing them,
        so this page needs no change when that day comes — it just gets fuller.
    --}}
    <x-table.wrapper>
        <x-slot:head>
            <tr>
                <th scope="col">Event</th>
                <th scope="col">Details</th>
                <th scope="col">By</th>
                <th scope="col">When</th>
            </tr>
        </x-slot:head>

        @forelse ($logs as $log)
            <tr>
                <td class="text-nowrap">
                    <x-badge :color="$log->event->color()" :icon="$log->event->icon()">
                        {{ $log->event->label() }}
                    </x-badge>
                </td>

                <td class="ams-cell-secondary">{{ $log->description }}</td>

                <td class="text-nowrap ams-cell-secondary">{{ $log->user?->name ?? 'System' }}</td>

                <td class="text-nowrap ams-cell-secondary">
                    {{ $log->created_at?->format(setting('datetime_format', 'd M Y, H:i')) }}
                </td>
            </tr>
        @empty
            <tr>
                <td colspan="4" class="p-0">
                    <x-table.empty-state
                        icon="clock-history"
                        title="No activity recorded yet"
                        message="Every change to this asset — created, edited, status changes — will appear here." />
                </td>
            </tr>
        @endforelse

        @if ($logs->hasPages())
            <x-slot:footer>
                <x-table.count :paginator="$logs" noun="event" />
                {{ $logs->links() }}
            </x-slot:footer>
        @endif
    </x-table.wrapper>
@endsection
