<div class="mx-auto grid w-full max-w-7xl grid-cols-1 gap-4 px-4 py-4 lg:grid-cols-3 md:px-6">
    <section class="rounded-md border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800 lg:col-span-2">
        <div class="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
            <div>
                <h2 class="text-sm font-bold text-gray-900 dark:text-gray-100">Manual Sync</h2>
                <p class="mt-1 text-xs leading-5 text-gray-500 dark:text-gray-300">Queue a provider import for the configured sync window. Imported records appear in Management > Fuel Transactions.</p>
            </div>
            <Button @icon="rotate" @text="Sync Transactions" @type="primary" @size="sm" @isLoading={{this.syncTransactions.isRunning}} @onClick={{perform this.syncTransactions}} />
        </div>
        <div class="mt-4 rounded-md border border-gray-200 p-3 text-xs leading-5 dark:border-gray-700">
            <div class="font-semibold text-gray-900 dark:text-gray-100">Configured window</div>
            <div class="mt-1 text-gray-500 dark:text-gray-300">{{n-a @model.connection.sync_settings.window_days}} days</div>
        </div>
        <div class="mt-4 overflow-hidden rounded-md border border-gray-200 dark:border-gray-700">
            <table class="min-w-full divide-y divide-gray-200 text-xs dark:divide-gray-700">
                <thead class="bg-gray-50 dark:bg-gray-900">
                    <tr>
                        <th class="px-3 py-2 text-left font-semibold text-gray-500">Status</th>
                        <th class="px-3 py-2 text-left font-semibold text-gray-500">Window</th>
                        <th class="px-3 py-2 text-left font-semibold text-gray-500">Imported</th>
                        <th class="px-3 py-2 text-left font-semibold text-gray-500">Matched</th>
                        <th class="px-3 py-2 text-left font-semibold text-gray-500">Finished</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100 dark:divide-gray-800">
                    {{#each this.syncRuns as |run|}}
                        <tr>
                            <td class="px-3 py-2"><Badge @status={{run.status}}>{{run.status}}</Badge></td>
                            <td class="px-3 py-2 text-gray-600 dark:text-gray-300">{{n-a (format-date-fns run.from "dd MMM")}} - {{n-a (format-date-fns run.to "dd MMM")}}</td>
                            <td class="px-3 py-2 text-gray-600 dark:text-gray-300">{{run.imported}}</td>
                            <td class="px-3 py-2 text-gray-600 dark:text-gray-300">{{run.matched}}</td>
                            <td class="px-3 py-2 text-gray-600 dark:text-gray-300">{{n-a (format-date-fns run.finished_at "dd MMM HH:mm")}}</td>
                        </tr>
                    {{else}}
                        <tr>
                            <td colspan="5" class="px-3 py-6 text-center text-gray-500 dark:text-gray-300">No sync runs have been recorded yet.</td>
                        </tr>
                    {{/each}}
                </tbody>
            </table>
        </div>
    </section>

    <aside class="rounded-md border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
        <h2 class="text-sm font-bold text-gray-900 dark:text-gray-100">Last Sync State</h2>
        <pre class="mt-3 max-h-80 overflow-auto rounded-md bg-gray-900 p-3 text-[11px] leading-5 text-gray-100">{{this.lastSyncStateJson}}</pre>
    </aside>
</div>
