<script lang="ts">
	import { page } from "$app/state";
	import { toCommitDetail } from "$lib/api/repo";
	import CommitView from "$lib/components/repo/CommitView.svelte";
	import type { DiffStyle } from "$lib/components/repo/pierre";

	let { data } = $props();

	const diffStyle = $derived<DiffStyle>(
		page.url.searchParams.get("diff") === "split" ? "split" : "unified"
	);
	// the load guarantees a commit, the fallback only satisfies the type
	const wire = $derived(data.commitDiff.commit ?? {});
	const commit = $derived(toCommitDetail(wire));
</script>

<CommitView
	ownerHandle={data.repo.ownerHandle}
	repoName={data.repo.name}
	ref={data.ref}
	{commit}
	parent={wire.parent ?? ""}
	changeId={wire.change_id ?? ""}
	files={data.commitDiff.diff ?? []}
	stat={data.commitDiff.stat}
	{diffStyle}
	prerendered={data.prerendered}
/>
