@layout('theme::layouts/admin')

@section('title')History — {{ $theme['name'] }}@endsection
@section('page_title'){{ $theme['name'] }} — history@endsection

@section('header_actions')
<a href="/admin/themes/{{ $theme['id'] }}" class="admin-btn admin-btn-outline">Back to the theme</a>
@endsection

@section('content')

@notempty($notice ?? null)
<div class="admin-alert admin-alert-success">{{ $notice }}</div>
@endnotempty

<div class="admin-card">
    <div class="admin-card-header">Earlier versions</div>

    @empty($revisions)
    <div class="admin-empty">
        <p>No history yet. A version is kept every time this theme is saved.</p>
    </div>
    @endempty

    @notempty($revisions)
    <div class="admin-card-body">
        <p class="form-hint">
            Each row is what the theme looked like <em>before</em> that save, so restoring
            one puts it back. <strong>Restoring is itself recorded</strong>, which means it
            can be undone the same way — the history only ever moves forwards.
        </p>
        <p class="form-hint">
            The most recent {{ $keep }} are kept; older ones are dropped as new ones arrive.
        </p>
    </div>

    <table class="admin-table">
        <thead>
            <tr>
                <th class="col-narrow">Accent</th>
                <th>Saved</th>
                <th>Was called</th>
                <th>By</th>
                <th class="col-actions">Actions</th>
            </tr>
        </thead>
        <tbody>
            @each ($revisions as $revision)
            <tr>
                <td><span class="theme-swatch" style="background: {{ $revision['accent'] }}"></span></td>
                <td>
                    {{ date('M j, Y g:ia', strtotime($revision['created_at'])) }}
                    @notempty($revision['note'])
                    <div class="ext-description">{{ $revision['note'] }}</div>
                    @endnotempty
                </td>
                <td>{{ $revision['name_then'] }}</td>
                <td>{{ $revision['author'] ?? '—' }}</td>
                <td>
                    <form method="POST" action="/admin/themes/{{ $theme['id'] }}/history/{{ $revision['id'] }}/restore"
                          onsubmit="return confirm('Put the theme back to how it was on {{ date('M j, Y g:ia', strtotime($revision['created_at'])) }}?')">
                        @csrf
                        <button type="submit" class="admin-btn admin-btn-outline admin-btn-sm">Restore</button>
                    </form>
                </td>
            </tr>
            @endeach
        </tbody>
    </table>
    @endnotempty
</div>
@endsection
