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

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

	const showsBoth = async ({ canvas }: PlayContext) => {
		await expect(canvas.getByText("+12")).toBeVisible();
		await expect(canvas.getByText("-4")).toBeVisible();
	};

	const rendersNothing = async ({ canvasElement }: PlayContext) => {
		await expect(canvasElement.textContent?.trim()).toBe("");
	};

	const { Story } = defineMeta({
		title: "Repo/DiffStatPill",
		component: DiffStatPill,
		tags: ["autodocs"],
		args: {
			stat: { insertions: 12, deletions: 4, files_changed: 3 }
		}
	});
</script>

<Story name="Insertions and deletions" play={showsBoth} />

<Story name="Insertions only" args={{ stat: { insertions: 12, deletions: 0, files_changed: 1 } }} />

<Story name="Deletions only" args={{ stat: { insertions: 0, deletions: 4, files_changed: 1 } }} />

<Story
	name="Empty"
	args={{ stat: { insertions: 0, deletions: 0, files_changed: 0 } }}
	play={rendersNothing}
/>
