<script lang="ts">
	import type { AddArtistInput } from '$gql/graphql';
	import { addArtist } from '$gql/Mutations';
	import Dialog from '$lib/components/Dialog.svelte';
	import ArtistForm from '$lib/forms/ArtistForm.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: AddArtistInput) {
		addArtist(client, { input }).then(modal.close).catch(toastFinally);
	}
</script>

<Dialog title="Add Artist" {...modal}>
	<ArtistForm {initial} {submit} />
</Dialog>
