import { HeaderRefResponse } from "@/types/header" import { Edges } from "@/types/requests/utils/edges" import { NodeRefs } from "@/types/requests/utils/refs" 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 }