import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// ============================================================================
// Tool Response Card
// ============================================================================
import { Card, CardBody, CardTitle, Divider, ExpandableSection } from '@patternfly/react-core';
import { useState } from 'react';
import MarkdownContent from '../MarkdownContent';
export const ToolResponse = ({ body, cardProps, expandableSectionProps, subheading, cardBody, cardTitle, cardBodyProps, toggleContent, isDefaultExpanded = true, toolResponseCardBodyProps, toolResponseCardDividerProps, toolResponseCardProps, toolResponseCardTitleProps, isToggleContentMarkdown, isSubheadingMarkdown, isBodyMarkdown, isCardBodyMarkdown, isCardTitleMarkdown, markdownContentProps, shouldRetainStyles = false }) => {
    const [isExpanded, setIsExpanded] = useState(isDefaultExpanded);
    const onToggle = (_event, isExpanded) => {
        setIsExpanded(isExpanded);
    };
    const renderToggleContent = () => {
        if (isToggleContentMarkdown && typeof toggleContent === 'string') {
            return (_jsx(MarkdownContent, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: toggleContent }, markdownContentProps)));
        }
        return toggleContent;
    };
    const renderSubheading = () => {
        if (!subheading) {
            return null;
        }
        if (isSubheadingMarkdown) {
            return _jsx(MarkdownContent, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: subheading }, markdownContentProps));
        }
        return subheading;
    };
    const renderBody = () => {
        if (!body) {
            return null;
        }
        if (isBodyMarkdown && typeof body === 'string') {
            return _jsx(MarkdownContent, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: body }, markdownContentProps));
        }
        return body;
    };
    const renderCardTitle = () => {
        if (!cardTitle) {
            return null;
        }
        if (isCardTitleMarkdown && typeof cardTitle === 'string') {
            return _jsx(MarkdownContent, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardTitle }, markdownContentProps));
        }
        return cardTitle;
    };
    const renderCardBody = () => {
        if (!cardBody) {
            return null;
        }
        if (isCardBodyMarkdown && typeof cardBody === 'string') {
            return _jsx(MarkdownContent, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardBody }, markdownContentProps));
        }
        return cardBody;
    };
    return (_jsx(Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response" }, cardProps, { children: _jsx(CardBody, Object.assign({}, cardBodyProps, { children: _jsx(ExpandableSection, Object.assign({ toggleContent: renderToggleContent(), onToggle: onToggle, isExpanded: isExpanded, isIndented: true, className: "pf-chatbot__tool-response-expandable-section" }, expandableSectionProps, { children: _jsxs("div", { className: "pf-chatbot__tool-response-section", children: [subheading && (_jsx("div", { className: "pf-chatbot__tool-response-subheading", children: _jsx("span", { children: renderSubheading() }) })), body && _jsx("div", { className: "pf-chatbot__tool-response-body", children: renderBody() }), (cardTitle || cardBody) && (_jsxs(Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response-card" }, toolResponseCardProps, { children: [cardTitle && _jsx(CardTitle, Object.assign({}, toolResponseCardTitleProps, { children: renderCardTitle() })), cardTitle && cardBody && _jsx(Divider, Object.assign({}, toolResponseCardDividerProps)), cardBody && _jsx(CardBody, Object.assign({}, toolResponseCardBodyProps, { children: renderCardBody() }))] })))] }) })) })) })));
};
export default ToolResponse;
