<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 { data } = $props();

	const back = $derived(`/${data.repo.ownerHandle}/${data.repo.name}/settings/access`);

	let user = $state("");
	const valid = $derived(user.trim().length > 0);

	// mocked — collaborator management is not wired up yet
	const submit = () => goto(resolve(back as "/"));
</script>

<DrillDown
	backLabel="Access"
	backHref={back}
	title="Add collaborator"
	description="Collaborators can push to this repository."
>
	<SettingsList padding="tight">
		<FormRow label="User" for="collaborator">
			<Input id="collaborator" bind:value={user} placeholder="user.tngl.sh" />
		</FormRow>
	</SettingsList>

	<FormActions>
		<Button href={resolve(back as "/")} icon={X}>Cancel</Button>
		<Button variant="primary" icon={Plus} disabled={!valid} onclick={submit}>Add</Button>
	</FormActions>
</DrillDown>
