import React from "react" import { snakeCaseDeep } from "../../helpers/convert-object-property-case" import { omit } from "../../helpers/omit" import { ReacordElement } from "../element.js" import type { MessageOptions } from "../message" import { Node } from "../node.js" import { EmbedChildNode } from "./embed-child.js" import type { EmbedOptions } from "./embed-options" export type EmbedProps = { title?: string description?: string url?: string color?: number fields?: Array<{ name: string; value: string; inline?: boolean }> author?: { name: string; url?: string; iconUrl?: string } thumbnail?: { url: string } image?: { url: string } video?: { url: string } footer?: { text: string; iconUrl?: string } timestamp?: string | number | Date children?: React.ReactNode } export function Embed(props: EmbedProps) { return ( new EmbedNode(props)}> {props.children} ) } class EmbedNode extends Node { override modifyMessageOptions(options: MessageOptions): void { const embed: EmbedOptions = { ...snakeCaseDeep(omit(this.props, ["children", "timestamp"])), timestamp: this.props.timestamp ? new Date(this.props.timestamp).toISOString() : undefined, } for (const child of this.children) { if (child instanceof EmbedChildNode) { child.modifyEmbedOptions(embed) } } options.embeds.push(embed) } }