import { jsx } from "react/jsx-runtime";
import { Box } from "@mui/material";
import apollo_core, { FontVariantToken } from "@uipath/apollo-core";
import react from "react";
import { ApLink } from "../../../../ap-link/index.js";
import { ApTypography } from "../../../../ap-typography/index.js";
import { useChatState } from "../../../providers/chat-state-provider.js";
import { fontByVariant } from "../../../utils/font-by-variant.js";
const TypographyContext = /*#__PURE__*/ react.createContext(void 0);
const Text = ({ children, variant, customStyle, headingLevel })=>{
    const { spacing } = useChatState();
    if (Array.isArray(children) && 1 === children.length && '' === children[0]) return null;
    const roleInfo = headingLevel ? {
        role: 'heading',
        'aria-level': headingLevel
    } : {};
    return /*#__PURE__*/ jsx(TypographyContext.Provider, {
        value: variant ?? spacing.primaryFontToken,
        children: /*#__PURE__*/ jsx(ApTypography, {
            variant: variant,
            color: 'var(--color-foreground)',
            style: {
                maxWidth: 'fit-content',
                ...customStyle
            },
            ...roleInfo,
            children: /*#__PURE__*/ jsx("div", {
                style: {
                    display: headingLevel ? 'flex' : 'inline'
                },
                ...roleInfo,
                children: children
            })
        })
    });
};
const getTextForVariant = (variant, headingLevel)=>/*#__PURE__*/ react.memo(({ children })=>Text({
            children,
            variant,
            headingLevel
        }));
const Break = /*#__PURE__*/ react.memo(()=>/*#__PURE__*/ jsx("br", {}));
const Blockquote = /*#__PURE__*/ react.memo(({ children })=>{
    const { spacing } = useChatState();
    return /*#__PURE__*/ jsx(Box, {
        component: "blockquote",
        sx: {
            borderLeft: "6px solid var(--color-border)",
            padding: `${apollo_core.Spacing.SpacingBase} 0 ${apollo_core.Spacing.SpacingBase} ${apollo_core.Spacing.SpacingL}`,
            color: 'var(--color-foreground-emp)',
            lineHeight: apollo_core.FontFamily.FontMicroLineHeight,
            display: 'flex',
            margin: 0,
            '& .MuiTypography-root': {
                fontFamily: fontByVariant(spacing.markdownTokens.citation)?.fontFamily,
                fontSize: fontByVariant(spacing.markdownTokens.citation)?.fontSize,
                fontWeight: fontByVariant(spacing.markdownTokens.citation)?.fontWeight,
                lineHeight: fontByVariant(spacing.markdownTokens.citation)?.lineHeight
            }
        },
        children: children
    });
});
const Emphazised = /*#__PURE__*/ react.memo(({ children })=>{
    const parentVariant = react.useContext(TypographyContext);
    const { spacing } = useChatState();
    return Text({
        children: /*#__PURE__*/ jsx("em", {
            children: children
        }),
        customStyle: {
            display: 'inline'
        },
        variant: parentVariant ?? spacing.primaryFontToken
    });
});
const Strong = /*#__PURE__*/ react.memo(({ children })=>{
    const parentVariant = react.useContext(TypographyContext);
    const { spacing } = useChatState();
    return Text({
        children: /*#__PURE__*/ jsx("strong", {
            children: children
        }),
        customStyle: {
            display: 'inline'
        },
        variant: parentVariant ?? spacing.primaryFontToken
    });
});
const Del = /*#__PURE__*/ react.memo(({ children })=>{
    const parentVariant = react.useContext(TypographyContext);
    const { spacing } = useChatState();
    return Text({
        children: /*#__PURE__*/ jsx("del", {
            children: children
        }),
        customStyle: {
            display: 'inline'
        },
        variant: parentVariant ?? spacing.primaryFontToken
    });
});
const Pre = /*#__PURE__*/ react.memo(({ children })=>/*#__PURE__*/ jsx(Box, {
        component: "pre",
        sx: {
            margin: 0
        },
        children: children
    }));
const Hr = /*#__PURE__*/ react.memo(()=>/*#__PURE__*/ jsx(Box, {
        component: "hr",
        sx: {
            border: 'none',
            borderTop: "1px solid var(--color-foreground)",
            width: '100%',
            margin: 0
        }
    }));
const Link = /*#__PURE__*/ react.memo(({ href, children })=>{
    const parentVariant = react.useContext(TypographyContext);
    const { spacing } = useChatState();
    return /*#__PURE__*/ jsx(Text, {
        variant: parentVariant ?? spacing.primaryFontToken,
        customStyle: {
            display: 'inline'
        },
        children: /*#__PURE__*/ jsx(ApLink, {
            href: href,
            target: "_blank",
            variant: FontVariantToken.fontSizeM,
            children: children
        })
    });
});
export { Blockquote, Break, Del, Emphazised, Hr, Link, Pre, Strong, Text, TypographyContext, getTextForVariant };
