import { AccountPageEnum } from "@/types/enums/accountPage"
import type { System } from "@/types/requests/system"
import type { AccountPageRefs } from "@/types/trpc/routers/contentstack/accountPage"

export function getConnections({ account_page }: AccountPageRefs) {
  const connections: System["system"][] = [account_page.system]

  if (account_page.content) {
    account_page.content.forEach((block) => {
      switch (block.__typename) {
        case AccountPageEnum.ContentStack.blocks.ShortCuts: {
          if (block.shortcuts.shortcuts.length) {
            connections.push(...block.shortcuts.shortcuts)
          }
          break
        }
        case AccountPageEnum.ContentStack.blocks.DynamicContent: {
          if (block.dynamic_content.link) {
            connections.push(block.dynamic_content.link)
          }
          break
        }
      }
    })
  }

  return connections
}
