import { useEffect, useState } from 'react';
import { cdnUrls, useLinks } from '../core';
import { isObject } from '../utils';
/** Loads templates for Footer links and enriches them with urls from LinksContext. */
export 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]);
    const columns = templates.columns?.map(column => column.map(section => ({
        ...section,
        links: section.links?.map(link => ({ ...link, url: links?.[link?.id ?? ''] })),
    })));
    return { columns, linkedIn: templates.linkedIn };
}
//# sourceMappingURL=helpers.js.map