<script lang="ts">
  import Table from '$lib/components/data-table/Table.svelte';
  import type { Column } from '$lib/components/data-table/types';
  import type { UserListPage } from "./+page";

  export let data: UserListPage;

  const columns: Column[] = [
    {
      field: 'id',
      heading: 'ID',
      type: 'number',
    },
    {
      field: 'email',
      heading: 'Email',
      isLink: true,
      linkTarget: '/users/%id%',
    },
    {
      field: 'first_name',
      heading: 'First Name',
    },
    {
      field: 'last_name',
      heading: 'Last Name',
    },
    {
      field: 'created',
      heading: 'Created',
      type: 'date',
    },
    {
      field: 'updated',
      heading: 'Updated',
      type: 'date',
    },
    {
      field: 'is_admin',
      heading: 'Admin',
      type: 'boolean',
    },
  ]

  const table = {
    caption: "List of users",
    columns: columns,
    getItemsEndpoint: data.endpointFactory.createReadUsersEndpoint(),
    getItemCountEndpoint: data.endpointFactory.createReadUserCountEndpoint(),
    defaultSortField: 'id',
    defaultSortOrder: 'asc',
  };
</script>

<Table {...table} />
