<script lang="ts">
	import { showToast, type ToastType } from '$lib/stores/toast.svelte';

	interface Props {
		message?: string | null | false;
		type?: ToastType;
	}

	let { message, type = 'success' }: Props = $props();

	let lastShown = $state<string | null>(null);

	$effect(() => {
		const msg = message ? String(message).trim() : '';
		if (!msg) {
			lastShown = null;
			return;
		}
		if (msg === lastShown) return;
		lastShown = msg;
		showToast({ message: msg, type });
	});
</script>
