<script lang="ts">
	import type { AddCharacterInput } from '$gql/graphql';
	import { addCharacter } from '$gql/Mutations';
	import Dialog from '$lib/components/Dialog.svelte';
	import CharacterForm from '$lib/forms/CharacterForm.svelte';
	import { toastFinally } from '$lib/Toasts';
	import { getContextClient } from '@urql/svelte';
	import type { ModalProps } from 'svelte-modals';

	const client = getContextClient();

	let modal: ModalProps = $props();
	const initial = { name: '' };

	function submit(input: AddCharacterInput) {
		addCharacter(client, { input }).then(modal.close).catch(toastFinally);
	}
</script>

<Dialog title="Add Character" {...modal}>
	<CharacterForm {initial} {submit} />
</Dialog>
