<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 address = $state("");
	const valid = $derived(address.trim().length > 0);

	// mocked — spindle registration is not wired up yet
	const submit = () => goto(resolve("/settings/spindles"));
</script>

<DrillDown
	backLabel="Spindles"
	backHref="/settings/spindles"
	title="Register a spindle"
	description="Enter the hostname of your spindle to get started."
>
	<SettingsList padding="tight">
		<FormRow label="Spindle address" for="spindle-address">
			<Input id="spindle-address" bind:value={address} placeholder="spindle.example.com" />
		</FormRow>
	</SettingsList>

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