var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
// Import Patternfly components
import { Button, Content, ContentVariants, Flex } from '@patternfly/react-core';
// Import Patternfly icons
import { InfoCircleIcon } from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
import { ExternalLinkAltIcon } from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';
// Import Chatbot components
import ChatbotPopover from '../ChatbotPopover/ChatbotPopover';
export const ChatbotFootnote = (_a) => {
    var _b, _c, _d, _e, _f;
    var { label, popover, className } = _a, props = __rest(_a, ["label", "popover", "className"]);
    // Popover visibility state
    const [isVisible, setIsVisible] = useState(false);
    // Define popover body content
    const popoverBodyContent = (_jsxs(_Fragment, { children: [(popover === null || popover === void 0 ? void 0 : popover.bannerImage) && _jsx("img", { src: popover.bannerImage.src, alt: popover.bannerImage.alt }), _jsx(Content, { component: ContentVariants.h3, children: popover === null || popover === void 0 ? void 0 : popover.title }), _jsx(Content, { component: ContentVariants.p, children: popover === null || popover === void 0 ? void 0 : popover.description })] }));
    // Define popover footer content
    const popoverFooterContent = (_jsxs(Flex, { gap: { default: 'gapSm' }, children: [(popover === null || popover === void 0 ? void 0 : popover.cta) && (_jsx(Button, { variant: "secondary", onClick: () => {
                    var _a;
                    setIsVisible(false);
                    (_a = popover.cta) === null || _a === void 0 ? void 0 : _a.onClick();
                }, children: ((_b = popover.cta) === null || _b === void 0 ? void 0 : _b.label) || 'Dismiss' })), (popover === null || popover === void 0 ? void 0 : popover.link) && (_jsx(Button, { variant: "link", component: "a", href: popover.link.url, target: "_blank", icon: _jsx(ExternalLinkAltIcon, {}), iconPosition: "end", children: popover.link.label }))] }));
    return (_jsxs("div", Object.assign({ className: `pf-chatbot__footnote ${className !== null && className !== void 0 ? className : ''}` }, props, { children: [popover && (_jsx(ChatbotPopover, Object.assign({ className: "pf-chatbot__popover--footnote", "aria-label": ((_c = popover.popoverProps) === null || _c === void 0 ? void 0 : _c['aria-label']) || 'More information', isVisible: isVisible, shouldOpen: (_event, _fn) => setIsVisible(true), shouldClose: (_event, _fn) => setIsVisible(false), bodyContent: popoverBodyContent, footerContent: popoverFooterContent, minWidth: ((_d = popover.popoverProps) === null || _d === void 0 ? void 0 : _d.minWidth) || '432', maxWidth: ((_e = popover.popoverProps) === null || _e === void 0 ? void 0 : _e.maxWidth) || '432', distance: ((_f = popover.popoverProps) === null || _f === void 0 ? void 0 : _f.distance) || 16, showClose: false }, popover.popoverProps, { children: _jsxs(Button, { variant: "link", size: "sm", children: [label, " ", _jsx(InfoCircleIcon, {})] }) }))), !popover && _jsx(Content, { component: ContentVariants.small, children: label })] })));
};
export default ChatbotFootnote;
