<script lang="ts">
	import { createPropertyStore } from "@ui/stores/metadata.svelte";
	import Stat from "./Stat.svelte";

	type Props = {
		label: string;
		property: string;
	};

	const { label, property }: Props = $props();
	const store = createPropertyStore(property);
	const avg = $derived.by(() => {
		if (store.propertyData.length === 0) {
			return 0;
		}

		const sum = store.propertyData.reduce((acc, f) => acc + f.value, 0);
		return sum / store.propertyData.length;
	});
</script>

<Stat {label} value={avg} />
