<script lang="ts">
	import { goto } from "$app/navigation";
	import { resolve } from "$app/paths";
	import Button from "$lib/components/ui/Button.svelte";
	import Input from "$lib/components/ui/Input.svelte";
	import DrillDown from "$lib/components/settings/DrillDown.svelte";
	import SettingsList from "$lib/components/settings/SettingsList.svelte";
	import FormRow from "$lib/components/settings/FormRow.svelte";
	import FormActions from "$lib/components/settings/FormActions.svelte";
	import Plus from "$icon/plus";
	import X from "$icon/x";

	let email = $state("");
	const valid = $derived(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim()));

	// mocked — sends nothing until the G4 email service is wired up
	const submit = () => goto(resolve("/settings/emails"));
</script>

<DrillDown
	backLabel="Emails"
	backHref="/settings/emails"
	title="Add email"
	description="Commits using this email will be associated with your profile."
>
	<SettingsList padding="tight">
		<FormRow label="Email" for="email-address">
			<Input id="email-address" type="email" bind:value={email} placeholder="your@email.com" />
		</FormRow>
	</SettingsList>

	<FormActions>
		<Button href="/settings/emails" icon={X}>Cancel</Button>
		<Button variant="primary" icon={Plus} disabled={!valid} onclick={submit}>Add</Button>
	</FormActions>
</DrillDown>
