"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 React = __importStar(require("react"));
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 }) => {
    const { metadata: { name: id }, spec: { icon, displayName, description, durationMinutes, prerequisites, link, type } } = quickStart;
    let quickStartIcon;
    if (typeof icon === 'object') {
        quickStartIcon = React.createElement(react_core_1.Icon, { size: "2xl" }, icon);
    }
    else {
        quickStartIcon = (React.createElement(react_core_1.Icon, { size: "2xl" },
            React.createElement(FallbackImg_1.default, { src: icon, alt: "", className: "pfext-catalog-item-icon__img", fallback: React.createElement(rocket_icon_1.default, null) })));
    }
    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 ? (React.createElement(react_core_1.Button, Object.assign({ "aria-label": action['aria-label'], icon: React.createElement(ActionIcon, null), variant: "plain", onClick: action.onClick }, action.buttonProps))) : undefined;
    return (React.createElement(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)}` },
        React.createElement(react_core_1.CardHeader, Object.assign({}, (action && {
            actions: { actions: additionalAction }
        })), quickStartIcon),
        React.createElement(react_core_1.CardTitle, null,
            React.createElement(QuickStartTileHeader_1.default, { name: displayName, onSelect: onSelect, quickStartId: id })),
        React.createElement(react_core_1.CardBody, null,
            React.createElement(react_core_1.Stack, { hasGutter: true },
                React.createElement(react_core_1.Flex, { spaceItems: { default: 'spaceItemsSm' } },
                    type && React.createElement(react_core_1.Label, { color: type.color }, type.text),
                    durationMinutes && (React.createElement(react_core_1.Label, { variant: "outline", "data-test": "duration", icon: React.createElement(outlined_clock_icon_1.default, null) }, (0, react_core_1.pluralize)(durationMinutes, minuteWord, minuteWordPlural)))),
                React.createElement(QuickStartTileDescription_1.default, { description: description, prerequisites: prerequisites, prerequisiteWord: prerequisiteWord, prerequisiteWordPlural: prerequisiteWordPlural, quickStartButtonAriaLabel: quickStartButtonAriaLabel }))),
        React.createElement(react_core_1.CardFooter, null,
            React.createElement(react_core_1.Button, { variant: "link", isInline: true, onClick: onSelect },
                React.createElement("span", { className: "pf-v6-c-button__text" }, "Start")))));
};
exports.default = QuickStartTile;
