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