import Link from "@/components/TempDesignSystem/Link"

import type { EmbedByUid } from "@/types/transitionTypes/jsontohtml"
import { RTEItemTypeEnum, RTETypeEnum } from "@/types/transitionTypes/rte/enums"
import type { RTENext, RTENode } from "@/types/transitionTypes/rte/node"
import type { RenderOptions } from "@/types/transitionTypes/rte/option"

export const renderOptions: RenderOptions = {
  [RTETypeEnum.reference]: (
    node: RTENode,
    embeds: EmbedByUid,
    next: RTENext,
    fullRenderOptions: RenderOptions
  ) => {
    if ("attrs" in node) {
      const type = node.attrs.type
      if (type !== RTEItemTypeEnum.asset) {
        const href = node.attrs?.locale
          ? `/${node.attrs.locale}${node.attrs.href}`
          : node.attrs.href

        return (
          <Link href={href} key={node.uid} textDecoration="underline">
            {next(node.children, embeds, fullRenderOptions)}
          </Link>
        )
      }

      return null
    }
  },
}
