<script>
	import { FrontmatterProperty, FrontmatterTaxonomy } from './';

	/**
	 * @typedef {import("../utilities/processMarkdownFiles").MarkdownFile} MarkdownFile
	 */

	/**
	 * @type {{props: {properties: MarkdownFile}}}
	 */
	let { props } = $props();
	// TODO: Normalize frontmatter props
	let { properties, website } = $derived(props);

	const excludedProperties = [
		'title',
		'description',
		'type',
		'ast',
		'url',
		'frontmatter',
		'published',
		'date',
		'image',
		'breadcrumb',
		'imputedProperties'
	];

	// const { website } = $page.data;

	/**
	 * Fetch a given property from a page.
	 * @param {MarkdownFile} properties - A markdown file.
	 * @param {string} key - The name of a property
	 * @returns {any}
	 */
	function getProperty(properties, key) {
		// @ts-ignore
		return properties[key];
	}
</script>

{#if properties}
	{#each Object.keys(properties) as key}
		{#if !excludedProperties.includes(key)}
			{@const property = getProperty(properties, key)}
			{#if website.hasOwnProperty(key)}
				<FrontmatterTaxonomy {property} {key} {website} />
			{:else}
				<FrontmatterProperty {property} {key} />
			{/if}
		{/if}
	{/each}
{/if}
