"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolResponse = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
// ============================================================================
// Tool Response Card
// ============================================================================
const react_core_1 = require("@patternfly/react-core");
const react_1 = require("react");
const MarkdownContent_1 = __importDefault(require("../MarkdownContent"));
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] = (0, react_1.useState)(isDefaultExpanded);
    const onToggle = (_event, isExpanded) => {
        setIsExpanded(isExpanded);
    };
    const renderToggleContent = () => {
        if (isToggleContentMarkdown && typeof toggleContent === 'string') {
            return ((0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: toggleContent }, markdownContentProps)));
        }
        return toggleContent;
    };
    const renderSubheading = () => {
        if (!subheading) {
            return null;
        }
        if (isSubheadingMarkdown) {
            return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: subheading }, markdownContentProps));
        }
        return subheading;
    };
    const renderBody = () => {
        if (!body) {
            return null;
        }
        if (isBodyMarkdown && typeof body === 'string') {
            return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: body }, markdownContentProps));
        }
        return body;
    };
    const renderCardTitle = () => {
        if (!cardTitle) {
            return null;
        }
        if (isCardTitleMarkdown && typeof cardTitle === 'string') {
            return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardTitle }, markdownContentProps));
        }
        return cardTitle;
    };
    const renderCardBody = () => {
        if (!cardBody) {
            return null;
        }
        if (isCardBodyMarkdown && typeof cardBody === 'string') {
            return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardBody }, markdownContentProps));
        }
        return cardBody;
    };
    return ((0, jsx_runtime_1.jsx)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response" }, cardProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({}, cardBodyProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.ExpandableSection, Object.assign({ toggleContent: renderToggleContent(), onToggle: onToggle, isExpanded: isExpanded, isIndented: true, className: "pf-chatbot__tool-response-expandable-section" }, expandableSectionProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: "pf-chatbot__tool-response-section", children: [subheading && ((0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__tool-response-subheading", children: (0, jsx_runtime_1.jsx)("span", { children: renderSubheading() }) })), body && (0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__tool-response-body", children: renderBody() }), (cardTitle || cardBody) && ((0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response-card" }, toolResponseCardProps, { children: [cardTitle && (0, jsx_runtime_1.jsx)(react_core_1.CardTitle, Object.assign({}, toolResponseCardTitleProps, { children: renderCardTitle() })), cardTitle && cardBody && (0, jsx_runtime_1.jsx)(react_core_1.Divider, Object.assign({}, toolResponseCardDividerProps)), cardBody && (0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({}, toolResponseCardBodyProps, { children: renderCardBody() }))] })))] }) })) })) })));
};
exports.ToolResponse = ToolResponse;
exports.default = exports.ToolResponse;
