import * as React from 'react';
import RocketIcon from '@patternfly/react-icons/dist/js/icons/rocket-icon';
import OutlinedBookmarkIcon from '@patternfly/react-icons/dist/js/icons/outlined-bookmark-icon';
import { Card, CardBody, CardHeader, CardFooter, CardTitle, Icon, Button, Flex, Stack, Label, pluralize } from '@patternfly/react-core';
import OutlinedClockIcon from '@patternfly/react-icons/dist/js/icons/outlined-clock-icon';
import QuickStartTileHeader from './QuickStartTileHeader';
import QuickStartTileDescription from './QuickStartTileDescription';
import FallbackImg from './FallbackImg';
export 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();
});
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 = React.createElement(Icon, { size: "2xl" }, icon);
    }
    else {
        quickStartIcon = (React.createElement(Icon, { size: "2xl" },
            React.createElement(FallbackImg, { src: icon, alt: "", className: "pfext-catalog-item-icon__img", fallback: React.createElement(RocketIcon, 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) || OutlinedBookmarkIcon;
    const additionalAction = action ? (React.createElement(Button, Object.assign({ "aria-label": action['aria-label'], icon: React.createElement(ActionIcon, null), variant: "plain", onClick: action.onClick }, action.buttonProps))) : undefined;
    return (React.createElement(Card, { className: `pf-chatbot__quickstarts-tile ${className ? className : ''}`, id: `${id}-chatbot-qs-tile`, style: { height: '100%' }, "data-testid": `chatbot-qs-card-${camelize(displayName)}`, isCompact: isCompact },
        React.createElement(CardHeader, Object.assign({}, (action && {
            actions: { actions: additionalAction }
        })), quickStartIcon),
        React.createElement(CardTitle, null,
            React.createElement(QuickStartTileHeader, { name: displayName, onSelect: onSelect, quickStartId: id })),
        React.createElement(CardBody, null,
            React.createElement(Stack, { hasGutter: true },
                React.createElement(Flex, { spaceItems: { default: 'spaceItemsSm' } },
                    type && React.createElement(Label, { color: type.color }, type.text),
                    durationMinutes && (React.createElement(Label, { variant: "outline", "data-test": "duration", icon: React.createElement(OutlinedClockIcon, null) }, pluralize(durationMinutes, minuteWord, minuteWordPlural)))),
                React.createElement(QuickStartTileDescription, { description: description, prerequisites: prerequisites, prerequisiteWord: prerequisiteWord, prerequisiteWordPlural: prerequisiteWordPlural, quickStartButtonAriaLabel: quickStartButtonAriaLabel }))),
        React.createElement(CardFooter, null,
            React.createElement(Button, { variant: "link", isInline: true, onClick: onSelect },
                React.createElement("span", { className: "pf-v6-c-button__text" }, "Start")))));
};
export default QuickStartTile;
