<!--
Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
Command: npx @threlte/gltf@2.0.1 nature_edit/PalmTree_1.gltf --types -s -T --root nature_edit/
-->

<script lang="ts">
	import type * as THREE from 'three';
	import { Group } from 'three';
	import { T, type Props, type Events, type Slots, forwardEventHandlers } from '@threlte/core';
	import { useGltf } from '@threlte/extras';

	type $$Props = Props<THREE.Group> & {
    leafsColor?: THREE.Color | string | number;
    leafsDarkColor?: THREE.Color | string | number;
    barkColor?: THREE.Color | string | number;
    coconutColor?: THREE.Color | string | number;
    variant?: 1 | 2 | 3 | 4;
    coconuts?: boolean;
  }
	type $$Events = Events<THREE.Group>;
	type $$Slots = Slots<THREE.Group> & { fallback: {}; error: { error: any } };

	export const ref = new Group();

  
	export let leafsColor: THREE.Color | string | number | undefined = undefined;
	export let leafsDarkColor: THREE.Color | string | number | undefined = undefined;

	export let barkColor: THREE.Color | string | number | undefined = undefined;
  export let coconutColor: THREE.Color | string | number | undefined = undefined;

	export let variant: 1 | 2 | 3 | 4 = 1;

	export let coconuts: boolean = false;

	type GLTFResult = {
		nodes: {
			PalmTree_1: THREE.Mesh;
			PalmTree_2: THREE.Mesh;
			PalmTree_3: THREE.Mesh;
			PalmTree_4: THREE.Mesh;
		};
		materials: {
			Bark: THREE.MeshStandardMaterial;
			Leaves: THREE.MeshStandardMaterial;
			LeavesAccent: THREE.MeshStandardMaterial;
			Coconuts: THREE.MeshStandardMaterial;
		};
	};

	const gltf = useGltf<GLTFResult>(`nature/PalmTree_${variant}.glb`, { useDraco: true });

	const component = forwardEventHandlers();
</script>

<T is={ref} dispose={false} {...$$restProps} bind:this={$component}>
	{#await gltf}
		<slot name="fallback" />
	{:then gltf}
		<T.Group rotation={[-Math.PI / 2, 0, 0]} scale={100}>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.PalmTree_1.geometry}
				material={gltf.materials.Bark.clone()}
        material.metalness={0}
        material.roughness={1}
        material.color={barkColor}
			/>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.PalmTree_2.geometry}
				material={gltf.materials.Leaves.clone()}
        material.metalness={0}
        material.roughness={1}
        material.color={leafsColor}
			/>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.PalmTree_3.geometry}
				material={gltf.materials.LeavesAccent.clone()}
        material.metalness={0}
        material.roughness={1}
        material.color={leafsDarkColor}
			/>
			{#if coconuts && (variant === 4 || variant === 3)}
				<T.Mesh
					castShadow
					receiveShadow
					geometry={gltf.nodes.PalmTree_4.geometry}
					material={gltf.materials.Coconuts.clone()}
          material.metalness={0}
          material.roughness={1}
          material.color={coconutColor}
				/>
			{/if}
		</T.Group>
	{:catch error}
		<slot name="error" {error} />
	{/await}

	<slot {ref} />
</T>
