"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pluralizeWord = pluralizeWord;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_core_1 = require("@patternfly/react-core");
const info_circle_icon_1 = __importDefault(require("@patternfly/react-icons/dist/js/icons/info-circle-icon"));
/** This function is a helper for pluralizing strings stolen from React.
 *
 * @param {number} i The quantity of the string you want to pluralize
 * @param {string} singular The singular version of the string
 * @param {string} plural The change to the string that should occur if the quantity is not equal to 1.
 *                 Defaults to adding an 's'.
 */
function pluralizeWord(i, singular, plural) {
    if (!plural) {
        plural = `${singular}s`;
    }
    return `${i === 1 ? singular : plural}`;
}
const QuickStartTileDescription = ({ description, prerequisites, prerequisiteWord = 'Prerequisite', prerequisiteWordPlural = 'Prerequisites', quickStartButtonAriaLabel = 'Show prerequisites' }) => {
    const prereqs = prerequisites === null || prerequisites === void 0 ? void 0 : prerequisites.filter((p) => p);
    const buttonRef = (0, react_1.useRef)(null);
    const pluralizedPrereq = pluralizeWord((prereqs === null || prereqs === void 0 ? void 0 : prereqs.length) || 0, prerequisiteWord, prerequisiteWordPlural);
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [description, prereqs && prereqs.length > 0 && ((0, jsx_runtime_1.jsxs)(react_core_1.Flex, { spaceItems: { default: 'spaceItemsSm' }, children: [(0, jsx_runtime_1.jsx)("h5", { children: (0, react_core_1.pluralize)(prereqs.length, prerequisiteWord, prerequisiteWordPlural) }), (0, jsx_runtime_1.jsx)(react_core_1.Button, { variant: "link", isInline: true, "data-testid": "qs-card-prereqs", ref: buttonRef, onClick: (e) => {
                            e.preventDefault();
                            e.stopPropagation();
                        }, "aria-label": quickStartButtonAriaLabel, children: (0, jsx_runtime_1.jsx)(info_circle_icon_1.default, {}) }), (0, jsx_runtime_1.jsx)(react_core_1.Popover, { "aria-label": pluralizedPrereq, headerContent: pluralizedPrereq, triggerRef: buttonRef, bodyContent: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("ul", { "aria-label": pluralizedPrereq, children: prereqs.map((prerequisite, index) => (
                                // eslint-disable-next-line react/no-array-index-key
                                (0, jsx_runtime_1.jsx)("li", { children: prerequisite }, index))) }) }) })] }))] }));
};
exports.default = QuickStartTileDescription;
