"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.camelize = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const rocket_icon_1 = __importDefault(require("@patternfly/react-icons/dist/js/icons/rocket-icon"));
const outlined_bookmark_icon_1 = __importDefault(require("@patternfly/react-icons/dist/js/icons/outlined-bookmark-icon"));
const react_core_1 = require("@patternfly/react-core");
const outlined_clock_icon_1 = __importDefault(require("@patternfly/react-icons/dist/js/icons/outlined-clock-icon"));
const QuickStartTileHeader_1 = __importDefault(require("./QuickStartTileHeader"));
const QuickStartTileDescription_1 = __importDefault(require("./QuickStartTileDescription"));
const FallbackImg_1 = __importDefault(require("./FallbackImg"));
const camelize = (str) => str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
    if (+match === 0) {
        return '';
    } // or if (/\s+/.test(match)) for white spaces
    return index === 0 ? match.toLowerCase() : match.toUpperCase();
});
exports.camelize = camelize;
const QuickStartTile = ({ className, quickStart, onClick, onSelectQuickStart, minuteWord = 'minute', minuteWordPlural = 'minutes', prerequisiteWord, prerequisiteWordPlural, quickStartButtonAriaLabel, action, isCompact }) => {
    const { metadata: { name: id }, spec: { icon, displayName, description, durationMinutes, prerequisites, link, type } } = quickStart;
    let quickStartIcon;
    if (typeof icon === 'object') {
        quickStartIcon = (0, jsx_runtime_1.jsx)(react_core_1.Icon, { size: "2xl", children: icon });
    }
    else {
        quickStartIcon = ((0, jsx_runtime_1.jsx)(react_core_1.Icon, { size: "2xl", children: (0, jsx_runtime_1.jsx)(FallbackImg_1.default, { src: icon, alt: "", className: "pfext-catalog-item-icon__img", fallback: (0, jsx_runtime_1.jsx)(rocket_icon_1.default, {}) }) }));
    }
    const onSelect = () => {
        if (!link) {
            onSelectQuickStart(id);
        }
        else {
            window.open(link.href, '_blank', 'noopener,noreferrer');
        }
        onClick && onClick();
    };
    const ActionIcon = (action === null || action === void 0 ? void 0 : action.icon) || outlined_bookmark_icon_1.default;
    const additionalAction = action ? ((0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ "aria-label": action['aria-label'], icon: (0, jsx_runtime_1.jsx)(ActionIcon, {}), variant: "plain", onClick: action.onClick }, action.buttonProps))) : undefined;
    return ((0, jsx_runtime_1.jsxs)(react_core_1.Card, { className: `pf-chatbot__quickstarts-tile ${className ? className : ''}`, id: `${id}-chatbot-qs-tile`, style: { height: '100%' }, "data-testid": `chatbot-qs-card-${(0, exports.camelize)(displayName)}`, isCompact: isCompact, children: [(0, jsx_runtime_1.jsx)(react_core_1.CardHeader, Object.assign({}, (action && {
                actions: { actions: additionalAction }
            }), { children: quickStartIcon })), (0, jsx_runtime_1.jsx)(react_core_1.CardTitle, { children: (0, jsx_runtime_1.jsx)(QuickStartTileHeader_1.default, { name: displayName, onSelect: onSelect, quickStartId: id }) }), (0, jsx_runtime_1.jsx)(react_core_1.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Stack, { hasGutter: true, children: [(0, jsx_runtime_1.jsxs)(react_core_1.Flex, { spaceItems: { default: 'spaceItemsSm' }, children: [type && (0, jsx_runtime_1.jsx)(react_core_1.Label, { color: type.color, children: type.text }), durationMinutes && ((0, jsx_runtime_1.jsx)(react_core_1.Label, { variant: "outline", "data-test": "duration", icon: (0, jsx_runtime_1.jsx)(outlined_clock_icon_1.default, {}), children: (0, react_core_1.pluralize)(durationMinutes, minuteWord, minuteWordPlural) }))] }), (0, jsx_runtime_1.jsx)(QuickStartTileDescription_1.default, { description: description, prerequisites: prerequisites, prerequisiteWord: prerequisiteWord, prerequisiteWordPlural: prerequisiteWordPlural, quickStartButtonAriaLabel: quickStartButtonAriaLabel })] }) }), (0, jsx_runtime_1.jsx)(react_core_1.CardFooter, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, { variant: "link", isInline: true, onClick: onSelect, children: (0, jsx_runtime_1.jsx)("span", { className: "pf-v6-c-button__text", children: "Start" }) }) })] }));
};
exports.default = QuickStartTile;
