import { ChevronEnd } from '@transferwise/icons';
import { clsx } from 'clsx';
import { forwardRef } from 'react';
import CardContainer from '../CardContainer';
import { Typography } from '../common';
import Link from '../Link';
import Title from '../Title';
import type { CardWidgetHeader, CardWidgetProps } from './CardWidget.types';
import CardWidgetAction, {
isCardWidgetActionButton,
type CardWidgetActionSlot,
} from './CardWidgetAction';
const renderAction = (action: CardWidgetHeader['action'], slot: CardWidgetActionSlot) =>
isCardWidgetActionButton(action) ? : action;
const CardWidgetHeaderComponent = ({
title,
as = 'h3',
titleAction,
action,
actionSecondary,
}: CardWidgetHeader) => (
{titleAction ? (
{title}
{/* The word joiner keeps the chevron on the title's last line instead of wrapping alone. */}
{'\u2060'}
) : (
title
)}
{(action || actionSecondary) && (
);
/**
* A `CardContainer` with an optional header — a title, a title link and up to two actions — above
* its content. The card shows as hovered or pressed while the title link is, and as hovered while
* the link has keyboard focus. Hovering or pressing the rest of the card, or its actions, leaves it
* at rest.
*/
const CardWidget = forwardRef(
({ header, children, className, ...props }, ref) => (
{header && }
{children != null &&