import { cdnUrls } from "../core/consts.js";
import { isObject } from "../utils/assertion.js";
import { useLinks } from "../core/links.js";
import { useEffect, useState } from "react";

//#region src/footer/helpers.ts
/** Loads templates for Footer links and enriches them with urls from LinksContext. */
function useFooterLinks(env) {
	const [templates, setTemplates] = useState({});
	const [links] = useLinks();
	useEffect(() => {
		loadFooterLinks();
		async function loadFooterLinks() {
			try {
				const response = await fetch(`${cdnUrls[env]}/common/data/links/footer.json`);
				if (!response.ok) return;
				const data = await response.json();
				if (isObject(data)) setTemplates(data);
			} catch {
				console.error("Failed to retrieve footer data.");
			}
		}
	}, [env]);
	return {
		columns: templates.columns?.map((column) => column.map((section) => ({
			...section,
			links: section.links?.map((link) => ({
				...link,
				url: links?.[link?.id ?? ""]
			}))
		}))),
		linkedIn: templates.linkedIn
	};
}

//#endregion
export { useFooterLinks };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=helpers.js.map