import { PropsWithChildren } from "react";
import { Box } from "@mui/material";
import { Typography } from "../Atoms/Typography";
import Markdown from "react-markdown";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import remarkGfm from "remark-gfm";
import remarkBreaks from "remark-breaks";
type GovernanceActionCardElementProps = {
title: string;
description: string;
type: string;
dataTestId: string;
};
export default function GovernanceActionCardElement({
title,
description,
type,
dataTestId,
}: GovernanceActionCardElementProps) {
const renderContent = () => {
if (type === "text") {
return (
{description}
);
}
if (type === "markdown") {
const truncateMarkdown = (markdown: string) => {
return markdown.split("\n").slice(0, 2).join("\n");
};
const truncatedDescription = truncateMarkdown(
description?.toString() || ""
);
return (
{children}
);
},
}}
remarkPlugins={[remarkMath, remarkBreaks, remarkGfm]}
rehypePlugins={[rehypeKatex]}
>
{truncatedDescription}
);
}
};
return (
{title}
{renderContent()}
);
}