<script lang="ts">
    import Pager from '$lib/components/Pager.svelte';
    import type { MissingCover } from '$lib/api/admin';
    import SearchBar from './SearchBar.svelte';

    let {
        covers,
        total,
        page,
        totalPages,
        search = $bindable(''),
        onSearch,
        onPageChange
    }: {
        covers: MissingCover[];
        total: number;
        page: number;
        totalPages: number;
        search?: string;
        onSearch: () => void;
        onPageChange: (p: number) => void;
    } = $props();
</script>

<section class="backlog">
    <div class="deadhead">
        <h2>Queued covers ({total})</h2>
        <div class="deadtools">
            <SearchBar bind:value={search} {onSearch} />
        </div>
    </div>
    {#if covers.length === 0}
        <p class="muted">No covers queued 🎉</p>
    {:else}
        <table class="dead">
            <thead>
                <tr><th>Manga</th></tr>
            </thead>
            <tbody>
                {#each covers as c (c.manga_id)}
                    <tr><td>{c.manga_title}</td></tr>
                {/each}
            </tbody>
        </table>
        <Pager {page} {totalPages} onChange={onPageChange} />
    {/if}
</section>

<style>
    h2 {
        margin: 0 0 var(--space-3) 0;
        font-size: var(--font-sm);
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
    table {
        width: 100%;
        border-collapse: collapse;
    }
    th,
    td {
        padding: var(--space-2);
        text-align: left;
        border-bottom: 1px solid var(--border);
        font-size: var(--font-sm);
    }
    .deadhead {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--space-3);
        flex-wrap: wrap;
    }
    .deadtools {
        display: flex;
        gap: var(--space-2);
    }
    .muted {
        color: var(--text-muted);
    }
    .backlog {
        margin-top: var(--space-4);
    }
</style>
