@extends('layout')
@section('title', 'Maintenance')
@section('content')
<div class="page-header"><h1>Maintenance</h1></div>

<div class="card" style="max-width:520px;">
    <h3 style="margin-top:0;">Purge old snapshots</h3>
    <p class="muted">Deletes punch snapshot image files older than the retention window and clears their
        <code>snapshot_path</code>. Runs immediately (synchronously) — no cron required.</p>
    <form method="POST" action="{{ route('maintenance.purge-snapshots') }}">
        @csrf
        <label for="days">Retention window (days)</label>
        <input type="number" id="days" name="days" min="1" max="3650" value="60" required>
        <button type="submit" class="btn btn-primary btn-block">Purge now</button>
    </form>
</div>

<div class="card" style="max-width:720px;">
    <h3 style="margin-top:0;">No-cron scheduled tasks</h3>
    <p class="muted">This host may have no cron access at all. Reports/dashboard figures already compute
        on the fly on every page load, so nothing below is <em>required</em> — but if you want periodic
        housekeeping without visiting this page, point a free external pinger (e.g.
        <a href="https://cron-job.org" target="_blank" rel="noopener">cron-job.org</a>) at these URLs:</p>

    @if($tasksToken)
        <table>
            <tbody>
                <tr>
                    <td>Purge snapshots (daily)</td>
                    <td style="font-family:monospace;word-break:break-all;">{{ $appUrl }}/tasks/purge-snapshots?token={{ $tasksToken }}&days=60</td>
                </tr>
                <tr>
                    <td>Compute yesterday's attendance (daily safety net)</td>
                    <td style="font-family:monospace;word-break:break-all;">{{ $appUrl }}/tasks/compute-attendance?token={{ $tasksToken }}</td>
                </tr>
            </tbody>
        </table>
    @else
        <p class="alert alert-error">No tasks token found in storage/app/installed.lock — this shouldn't
            happen on an installed instance; check the file wasn't manually deleted.</p>
    @endif
</div>
@endsection
