<script module lang="ts">
	import { defineMeta } from "@storybook/addon-svelte-csf";
	import MockAuthProvider from "$lib/components/testing/MockAuthProvider.svelte";
	import Timeline from "./Timeline.svelte";
	import type * as ShTangledFeedGetTimeline from "$lib/api/lexicons/types/sh/tangled/feed/getTimeline";

	const owner = { did: "did:plc:3p7ejjxnufohsygt5vbyxb2i", handle: "tangled.org" };
	const alice = { did: "did:plc:oky5czdrnfjpqslsw2a5iclo", handle: "alice.tngl.sh" };

	const repo = {
		did: "did:plc:3p7ejjxnufohsygt5vbyxb2i",
		slug: "core",
		owner,
		createdAt: "2025-06-01T10:30:00Z",
		description: "The knot server, appview, and everything that makes tangled tick.",
		starCount: 42
	};

	const feed = [
		{
			event: {
				$type: "sh.tangled.feed.getTimeline#repoEvent",
				cid: "bafyreib1",
				uri: "at://did:plc:3p7ejjxnufohsygt5vbyxb2i/sh.tangled.repo/core",
				repo
			},
			eventAt: "2025-06-04T09:00:00Z"
		},
		{
			event: {
				$type: "sh.tangled.feed.getTimeline#starEvent",
				cid: "bafyreib2",
				uri: "at://did:plc:oky5czdrnfjpqslsw2a5iclo/sh.tangled.feed.star/3l",
				actor: alice,
				repo
			},
			eventAt: "2025-06-03T18:20:00Z"
		},
		{
			event: {
				$type: "sh.tangled.feed.getTimeline#followEvent",
				cid: "bafyreib3",
				uri: "at://did:plc:oky5czdrnfjpqslsw2a5iclo/sh.tangled.graph.follow/3l",
				actor: alice,
				subject: {
					did: "did:plc:3p7ejjxnufohsygt5vbyxb2i",
					handle: "joshka.net",
					description: "Rust, TUIs, and the occasional git plumbing yak-shave.",
					followersCount: 128,
					followsCount: 87
				}
			},
			eventAt: "2025-06-02T12:00:00Z"
		},
		{
			event: {
				$type: "sh.tangled.feed.getTimeline#repoEvent",
				cid: "bafyreib4",
				uri: "at://did:plc:3p7ejjxnufohsygt5vbyxb2i/sh.tangled.repo/core-fork",
				repo: { ...repo, slug: "core-fork" },
				source: repo
			},
			eventAt: "2025-06-01T08:00:00Z"
		}
	] as unknown as ShTangledFeedGetTimeline.$output["feed"];

	const { Story } = defineMeta({
		title: "Timeline/Timeline",
		component: Timeline,
		tags: ["autodocs"],
		args: { feed }
	});
</script>

<Story name="Default">
	{#snippet template(args)}
		<MockAuthProvider>
			<Timeline {...args} />
		</MockAuthProvider>
	{/snippet}
</Story>

<Story name="Empty" args={{ feed: [], emptyMessage: "Nothing here yet." }} />
