<script lang="ts">
    import CollectionsGrid from '$lib/components/CollectionsGrid.svelte';

    let { data } = $props();
    const collections = $derived(data.collections);
</script>

{#if data.error}
    <p class="error" role="alert" data-testid="profile-collections-error">
        Couldn't load collections: {data.error}
    </p>
{:else if !data.authenticated}
    <p class="hint" data-testid="profile-collections-signin">
        <a href="/login?next=/profile/collections">Sign in</a> to see your collections.
    </p>
{:else if collections.length === 0}
    <p class="hint" data-testid="profile-collections-empty">
        You don't have any collections yet. Open any manga and use
        <strong>Add to collection</strong> to start one.
    </p>
{:else}
    <CollectionsGrid {collections} />
{/if}

<style>
    .hint {
        color: var(--text-muted);
    }
    .error {
        color: var(--danger);
    }
</style>
