<script lang="ts">
	import type { Snippet } from 'svelte'

	import { provide3DModels } from '../hooks/use3DModels.svelte'
	import { provideArmClient } from '../hooks/useArmClient.svelte'
	import { provideArmKinematics } from '../hooks/useArmKinematics.svelte'
	import { provideConfigFrames } from '../hooks/useConfigFrames.svelte'
	import {
		type CameraPose,
		provideCameraControls,
		provideTransformControls,
	} from '../hooks/useControls.svelte'
	import { provideDrawAPI } from '../hooks/useDrawAPI.svelte'
	import { provideFramelessComponents } from '../hooks/useFramelessComponents.svelte'
	import { provideFrames } from '../hooks/useFrames.svelte'
	import { provideGeometries } from '../hooks/useGeometries.svelte'
	import { provideLinkedEntities } from '../hooks/useLinked.svelte'
	import { provideLogs } from '../hooks/useLogs.svelte'
	import { provideMachineSettings } from '../hooks/useMachineSettings.svelte'
	import { usePartID } from '../hooks/usePartID.svelte'
	import { providePointcloudObjects } from '../hooks/usePointcloudObjects.svelte'
	import { providePointclouds } from '../hooks/usePointclouds.svelte'
	import { provideResourceByName } from '../hooks/useResourceByName.svelte'
	import { provideSelection } from '../hooks/useSelection.svelte'
	import { provideVisibility } from '../hooks/useVisibility.svelte'
	import { provideWorldStates } from '../hooks/useWorldState.svelte'

	import { provideOrigin } from './xr/useOrigin.svelte'

	interface Props {
		cameraPose?: CameraPose
		children: Snippet<[{ focus: boolean }]>
	}

	let { cameraPose, children }: Props = $props()

	const partID = usePartID()

	provideCameraControls(() => cameraPose)
	provideTransformControls()
	provideVisibility()
	provideMachineSettings()
	provideLogs()

	provideOrigin()
	provideDrawAPI()

	provideResourceByName(() => partID.current)
	provideConfigFrames()
	provideFrames(() => partID.current)
	provideGeometries(() => partID.current)
	provide3DModels(() => partID.current)
	providePointclouds(() => partID.current)
	providePointcloudObjects(() => partID.current)
	provideArmClient(() => partID.current)
	provideArmKinematics(() => partID.current)
	provideWorldStates()
	provideFramelessComponents()

	const { focus } = provideSelection()
	provideLinkedEntities()
</script>

{@render children({ focus: focus.current !== undefined })}
