"use strict";
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Chatbot Main - Messages - Sources Card
// ============================================================================
const react_1 = __importDefault(require("react"));
// Import PatternFly components
const react_core_1 = require("@patternfly/react-core");
const SourcesCard = (_a) => {
    var { className, isDisabled, ofWord = 'of', paginationAriaLabel = 'Pagination', sources, sourceWord = 'source', sourceWordPlural = 'sources', toNextPageAriaLabel = 'Go to next page', toPreviousPageAriaLabel = 'Go to previous page', onNextClick, onPreviousClick, onSetPage } = _a, props = __rest(_a, ["className", "isDisabled", "ofWord", "paginationAriaLabel", "sources", "sourceWord", "sourceWordPlural", "toNextPageAriaLabel", "toPreviousPageAriaLabel", "onNextClick", "onPreviousClick", "onSetPage"]);
    const [page, setPage] = react_1.default.useState(1);
    const handleNewPage = (_evt, newPage) => {
        setPage(newPage);
        onSetPage && onSetPage(_evt, newPage);
    };
    const renderTitle = (title) => {
        if (title) {
            return react_1.default.createElement(react_core_1.Truncate, { content: title });
        }
        return `Source ${page}`;
    };
    return (react_1.default.createElement("div", { className: "pf-chatbot__source" },
        react_1.default.createElement("span", null, (0, react_core_1.pluralize)(sources.length, sourceWord, sourceWordPlural)),
        react_1.default.createElement(react_core_1.Card, Object.assign({ className: "pf-chatbot__sources-card" }, props),
            react_1.default.createElement(react_core_1.CardTitle, { className: "pf-chatbot__sources-card-title" },
                react_1.default.createElement("a", { href: sources[page - 1].link }, renderTitle(sources[page - 1].title))),
            sources[page - 1].body && (react_1.default.createElement(react_core_1.CardBody, { className: `pf-chatbot__sources-card-body ${sources.length === 1 && 'pf-chatbot__sources-card-no-footer'}` }, sources[page - 1].body)),
            sources.length > 1 && (react_1.default.createElement(react_core_1.CardFooter, { className: "pf-chatbot__sources-card-footer-container" },
                react_1.default.createElement("div", { className: "pf-chatbot__sources-card-footer" },
                    react_1.default.createElement("nav", { className: `pf-chatbot__sources-card-footer-buttons ${className}`, "aria-label": paginationAriaLabel },
                        react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.plain, isDisabled: isDisabled || page === 1, "data-action": "previous", onClick: (event) => {
                                const newPage = page >= 1 ? page - 1 : 1;
                                onPreviousClick && onPreviousClick(event, newPage);
                                handleNewPage(event, newPage);
                            }, "aria-label": toPreviousPageAriaLabel },
                            react_1.default.createElement(react_core_1.Icon, { iconSize: "lg" },
                                react_1.default.createElement("svg", { className: "pf-v6-svg", viewBox: "0 0 280 500", fill: "currentColor", "aria-hidden": "true", role: "img", width: "1em", height: "1em" },
                                    react_1.default.createElement("path", { d: "M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z" })))),
                        react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.plain, isDisabled: isDisabled || page === sources.length, "aria-label": toNextPageAriaLabel, "data-action": "next", onClick: (event) => {
                                const newPage = page + 1 <= sources.length ? page + 1 : sources.length;
                                onNextClick && onNextClick(event, newPage);
                                handleNewPage(event, newPage);
                            } },
                            react_1.default.createElement(react_core_1.Icon, { isInline: true, iconSize: "lg" },
                                react_1.default.createElement("svg", { className: "pf-v6-svg", viewBox: "0 0 180 500", fill: "currentColor", "aria-hidden": "true", role: "img", width: "1em", height: "1em" },
                                    react_1.default.createElement("path", { d: "M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z" }))))),
                    react_1.default.createElement("span", { "aria-hidden": "true" },
                        page,
                        " ",
                        ofWord,
                        " ",
                        sources.length)))))));
};
exports.default = SourcesCard;
