<script lang="ts">
  import type { PageData } from "./$types";

  import HideDelete from "$lib/components/form/HideDelete.svelte";
  import PatientForm from "$lib/components/form/PatientForm.svelte";
  import FilteredEntryTable from "$lib/components/table/FilteredEntryTable.svelte";

  export let data: PageData;

  $: hasEntries = data.patient.n_entries > 0;
</script>

<svelte:head>
  <title>Patient #{data.patient.id}</title>
</svelte:head>

<PatientForm formData={data.form} patient={data.patient}>
  <HideDelete hasEntries={data.patient.n_entries > 0} hidden={data.patient.hidden} />
</PatientForm>

{#if hasEntries}
  <h1 class="heading mt-8 mb-4">Einträge ({data.patient.n_entries})</h1>

  <FilteredEntryTable
    baseUrl="/patient/{data.patient.id}"
    entries={data.entries}
    patientId={data.patient.id}
    query={data.query}
  />
{/if}
