<script module lang="ts">
	import { defineMeta } from "@storybook/addon-svelte-csf";
	import ChevronRight from "$icon/chevron-right";
	import GitFork from "$icon/git-fork";
	import Star from "$icon/star";
	import Button from "./Button.svelte";

	const { Story } = defineMeta({
		title: "UI/Button",
		component: Button,
		tags: ["autodocs"],
		argTypes: {
			variant: {
				control: { type: "select" },
				options: ["default", "primary", "ghost", "danger", "success", "warning"]
			},
			size: {
				control: { type: "inline-radio" },
				options: ["sm", "md", "lg"]
			},
			iconSide: {
				control: { type: "inline-radio" },
				options: ["left", "right"]
			},
			insetShadow: { control: "boolean" },
			disabled: { control: "boolean" },
			loading: { control: "boolean" }
		},
		args: {
			variant: "default",
			size: "md",
			iconSide: "left",
			insetShadow: false,
			disabled: false,
			loading: false
		}
	});
</script>

<!-- Button content comes through its `children` snippet, provided here as Story slot content. -->
<Story name="Default">Button</Story>
<Story name="Primary" args={{ variant: "primary" }}>Save</Story>
<Story name="Ghost" args={{ variant: "ghost" }}>Cancel</Story>
<Story name="Danger" args={{ variant: "danger" }}>Delete</Story>
<Story name="Success" args={{ variant: "success" }}>Confirm</Story>
<Story name="Warning" args={{ variant: "warning" }}>Careful</Story>
<Story name="Loading" args={{ variant: "primary", loading: true }}>Saving</Story>
<Story name="Disabled" args={{ disabled: true }}>Button</Story>
<Story name="Link" args={{ href: "/" }}>Go home</Story>

<Story name="Inset shadow" asChild>
	<div class="flex items-center gap-3">
		<Button insetShadow>Button</Button>
		<Button variant="primary" insetShadow>Save</Button>
	</div>
</Story>

<Story name="Sizes" asChild>
	<div class="flex items-center gap-3">
		<Button size="sm">Small</Button>
		<Button size="md">Medium</Button>
		<Button size="lg">Large</Button>
	</div>
</Story>

<Story name="With icon" args={{ icon: Star }}>Star</Story>
<Story name="Icon right" args={{ icon: ChevronRight, iconSide: "right" }}>Next</Story>
<Story name="Icon only" args={{ icon: Star, "aria-label": "Star" }} />

<!-- the icon rides the same gap and scales with the size variant: size-4 up to lg, size-5 at lg. -->
<Story name="Icon sizes" asChild>
	<div class="flex items-center gap-3">
		<Button size="sm" icon={Star}>Small</Button>
		<Button size="md" icon={Star}>Medium</Button>
		<Button size="lg" icon={Star}>Large</Button>
	</div>
</Story>

<!-- press these: the icon and label sink together while the button box stays put. -->
<Story name="Icons with inset shadow" asChild>
	<div class="flex items-center gap-3">
		<Button insetShadow icon={Star}>Star</Button>
		<Button variant="primary" insetShadow icon={GitFork}>Fork</Button>
		<Button insetShadow icon={ChevronRight} iconSide="right">Next</Button>
		<Button insetShadow icon={Star} aria-label="Star" />
	</div>
</Story>
