import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useRef } from 'react';
import { Button, Flex, pluralize, Popover } from '@patternfly/react-core';
import InfoCircleIcon from '@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'.
 */
export 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 = useRef(null);
    const pluralizedPrereq = pluralizeWord((prereqs === null || prereqs === void 0 ? void 0 : prereqs.length) || 0, prerequisiteWord, prerequisiteWordPlural);
    return (_jsxs(_Fragment, { children: [description, prereqs && prereqs.length > 0 && (_jsxs(Flex, { spaceItems: { default: 'spaceItemsSm' }, children: [_jsx("h5", { children: pluralize(prereqs.length, prerequisiteWord, prerequisiteWordPlural) }), _jsx(Button, { variant: "link", isInline: true, "data-testid": "qs-card-prereqs", ref: buttonRef, onClick: (e) => {
                            e.preventDefault();
                            e.stopPropagation();
                        }, "aria-label": quickStartButtonAriaLabel, children: _jsx(InfoCircleIcon, {}) }), _jsx(Popover, { "aria-label": pluralizedPrereq, headerContent: pluralizedPrereq, triggerRef: buttonRef, bodyContent: _jsx("div", { children: _jsx("ul", { "aria-label": pluralizedPrereq, children: prereqs.map((prerequisite, index) => (
                                // eslint-disable-next-line react/no-array-index-key
                                _jsx("li", { children: prerequisite }, index))) }) }) })] }))] }));
};
export default QuickStartTileDescription;
