<script lang="ts">
	// story-only helper: injects a fake auth context so form stories can exercise
	// a real (failing) submission without a live session. the fake agent's fetch
	// handler always rejects, so putIssue/putComment land in the form's catch block.
	import { setContext, type Snippet } from "svelte";
	import { AUTH_KEY, type Auth } from "$lib/auth.svelte";

	interface Props {
		// message the fake agent rejects submissions with
		failWith?: string;
		children: Snippet;
	}

	let { failWith = "MockAuthProvider: network request failed, this error is intentional.", children }: Props = $props();

	const agent = {
		sub: "did:plc:alice",
		handle: () => Promise.reject(new Error(failWith))
	};

	const auth = {
		agent,
		currentDid: "did:plc:alice",
		currentUser: { did: "did:plc:alice", handle: "alice.pds.tngl.boltless.dev" }
	} as unknown as Auth;

	setContext(AUTH_KEY, auth);
</script>

{@render children()}
