import { HeaderRefResponse } from "@/types/header" import { Edges } from "@/types/requests/utils/edges" import { NodeRefs } from "@/types/requests/utils/refs" import type { FooterLinkItem } from "./output" export function getConnections(refs: HeaderRefResponse) { const connections: Edges[] = [] const headerData = refs.all_header.items[0] const topLink = headerData.top_link if (topLink) { connections.push(topLink.linkConnection) } headerData.menu_items.forEach( ({ linkConnection, see_all_link, cardConnection, submenu }) => { const card = cardConnection.edges[0]?.node connections.push(linkConnection) if (see_all_link) { connections.push(see_all_link.linkConnection) } if (card) { if (card.primary_button) { connections.push(card.primary_button.linkConnection) } if (card.secondary_button) { connections.push(card.secondary_button.linkConnection) } } submenu.forEach(({ links }) => { links.forEach(({ linkConnection }) => { connections.push(linkConnection) }) }) } ) return connections } export function transformPageConnectionLinks(links: FooterLinkItem[]) { if (!links) return [] return links.flatMap((link) => { if (link.pageConnection?.edges.length) { return link.pageConnection.edges.map((edge) => ({ title: edge.node.title || "", url: edge.node.url || "", openInNewTab: link.open_in_new_tab, isExternal: false, })) } else if (link.link) { return [ { title: link.link.title, url: link.link.href, openInNewTab: link.open_in_new_tab, isExternal: true, }, ] } return [] }) }