<script module lang="ts">
	import { defineMeta, type StoryContext } from "@storybook/addon-svelte-csf";
	import { expect } from "storybook/test";
	import TagCard from "./TagCard.svelte";
	import type { TagSummary } from "./types";

	const annotated: TagSummary = {
		name: "v1.2.0",
		hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		commitHash: "0123456789abcdef0123456789abcdef01234567",
		when: "2026-07-28T09:00:00Z",
		taggerName: "dawn",
		message: "release v1.2.0\n\nships the mobile fixes"
	};

	const lightweight: TagSummary = {
		name: "nightly",
		hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
		commitHash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
	};

	type PlayContext = Pick<StoryContext<Record<string, unknown>>, "canvas">;

	const annotatedLayout = async ({ canvas }: PlayContext) => {
		const nameLinks = canvas.getAllByRole("link", { name: /v1\.2\.0/ });
		await expect(nameLinks[0]).toHaveAttribute("href", "/dawn/tangled/tags/v1.2.0");
		const shaLinks = canvas.getAllByRole("link", { name: /01234567/ });
		await expect(shaLinks[0]).toHaveAttribute(
			"href",
			"/dawn/tangled/commit/0123456789abcdef0123456789abcdef01234567"
		);
		await expect(canvas.getByText("release v1.2.0")).toBeInTheDocument();
		await expect(canvas.getByText("ships the mobile fixes")).toBeInTheDocument();
	};

	const lightweightLayout = async ({ canvas }: PlayContext) => {
		await expect(canvas.getByText("No message")).toBeInTheDocument();
	};

	const { Story } = defineMeta({
		title: "Repo/TagCard",
		component: TagCard,
		tags: ["autodocs"],
		args: {
			ownerHandle: "dawn",
			repoName: "tangled",
			tag: annotated
		}
	});
</script>

<Story name="Annotated" play={annotatedLayout} />
<Story name="Lightweight" args={{ tag: lightweight }} play={lightweightLayout} />
