<script lang="ts">
	import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
	import { api } from "astro-typesafe-api/client";
	import Cookies from "js-cookie";

	$: userRequest = api.user.GET.fetch({
		email,
		take: 25
	}, {
		headers: {
			"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
		}
	})

	let email: string = "";
</script>

<input type="email" bind:value={email}>

{#await userRequest}
	
{:then users} 
	<div class="flex flex-col gap-2 my-2">
		{#each users as user}
		<div class="flex flex-row justify-between border p-2 rounded-sm">
			<div class="flex flex-col">
				<span>{user.vorname} {user.name}</span>
				<span class="text-xs">{user.email}</span>
			</div>
			<a href="/dashboard/admin/impersonate?id={user.id}" class="button text-sm">Einloggen</a>
		</div>
		{/each}
	</div>
{/await}