<script lang="ts">
    import type { CrawlerStatus } from '$lib/api/admin';

    let {
        status,
        busy,
        onRunPass,
        onReconcile,
        onOpenRestart,
        onOpenSession,
        onClearExpired
    }: {
        status: CrawlerStatus;
        busy: boolean;
        onRunPass: () => void;
        onReconcile: () => void;
        onOpenRestart: () => void;
        onOpenSession: () => void;
        onClearExpired: () => void;
    } = $props();
</script>

<section class="controls">
    <button onclick={onRunPass} disabled={busy || status.daemon !== 'running'}
        >Run metadata pass now</button
    >
    <button
        onclick={onReconcile}
        disabled={busy || status.daemon !== 'running'}
        title="Full list-only walk; enqueues mangas missing from the DB"
        >Reconcile missing</button
    >
    <button onclick={onOpenRestart} disabled={busy || status.daemon !== 'running'}
        >Restart browser</button
    >
    <button onclick={onOpenSession} disabled={busy || status.daemon !== 'running'}
        >Manage session…</button
    >
    {#if status.session.expired}
        <button onclick={onClearExpired} disabled={busy}>Clear expired flag</button>
    {/if}
</section>

<style>
    .controls {
        display: flex;
        gap: var(--space-2);
        flex-wrap: wrap;
        margin-bottom: var(--space-4);
    }
</style>
