<script lang="ts">
	import { boxWith, mergeProps } from "svelte-toolbelt";
	import { TimeFieldLabelState } from "../time-field.svelte.js";
	import type { TimeFieldLabelProps } from "../types.js";
	import { createId } from "../../../internal/create-id.js";

	const uid = $props.id();

	let {
		id = createId(uid),
		ref = $bindable(null),
		children,
		child,
		...restProps
	}: TimeFieldLabelProps = $props();

	const labelState = TimeFieldLabelState.create({
		id: boxWith(() => id),
		ref: boxWith(
			() => ref,
			(v) => (ref = v)
		),
	});

	const mergedProps = $derived(mergeProps(restProps, labelState.props));
</script>

{#if child}
	{@render child({ props: mergedProps })}
{:else}
	<div {...mergedProps}>
		{@render children?.()}
	</div>
{/if}
