📄 src/routes/guide/[labelIndex]/+page.svelte
<script lang="ts">
  import { historyStore } from "$lib/history";
  import { labelsStore } from "$lib/labels";
  import PatchBanner from "$lib/components/PatchBanner.svelte";
  import HistoryEntry from "$lib/components/HistoryEntry.svelte";

  let { data } = $props();

  const label = $derived($labelsStore[data.labelIndex]);
  const detections = $derived(
    $historyStore.filter((e) => e.labelIndex === data.labelIndex),
  );
</script>

<PatchBanner text={label?.commonName ?? "Unknown Bird"} />

<div class="species-info">
  {#if label}
    <p class="scientific">{label.scientificName}</p>
  {/if}
  <p class="stat">
    {detections.length}
    {detections.length === 1 ? "detection" : "detections"}
  </p>
</div>

{#if detections.length > 0}
  <ol>
    {#each detections as entry (entry.detectedAt)}
      <HistoryEntry {entry} />
    {/each}
  </ol>
{:else}
  <p class="empty">Not detected yet. Go listen!</p>
{/if}

<style>
  .species-info {
    padding: 1.25rem 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .scientific {
    font-style: italic;
    font-size: 0.9rem;
    opacity: 0.7;
  }

  .stat {
    font-weight: 700;
    color: var(--brand-red);
  }

  .empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--accent-rust);
  }

  ol {
    list-style: none;
    padding: 1rem;
    padding-top: 0.75rem;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 1rem);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
</style>