import React from 'react' import Block from '../Primitives/Block/Block' import Text from '../Text/Text' import Button from '../Button/Button' import { ButtonSubType } from '../Button/types' import { CardVariant, CardAlignment } from './types' import type { CardProps } from './types' import type { CardTokenType } from './card.tokens' import { getHeaderBoxStyles, getHeaderTitleStyles, getSubHeaderStyles, getBodyTitleStyles, getBodyContentStyles, getBodyStyles, getHeaderSpacing, getHeaderMarginBottom, getSubHeaderMarginBottom, getBodySlot1MarginBottom, getBodyTitleMarginBottom, getContentMarginBottom, getBodySlot2MarginBottom, isInlineActionButton, } from './utils' type CardComponentProps = { props: Extract cardToken: CardTokenType maxHeight?: string baseId: string } type AlignedCardComponentProps = { props: Extract cardToken: CardTokenType maxHeight?: string baseId: string } type CustomCardComponentProps = { props: Extract cardToken: CardTokenType maxHeight?: string baseId?: string } const isPlainTextContent = (content: React.ReactNode) => typeof content === 'string' || typeof content === 'number' const CardBodyContent = ({ content, contentId, cardToken, describedBy, }: { content: React.ReactNode contentId: string cardToken: CardTokenType describedBy?: string }) => { const sharedProps = { id: contentId, style: getBodyContentStyles(cardToken), 'aria-describedby': describedBy, } if (isPlainTextContent(content)) { return ( {content} ) } return {content} } export const DefaultCard: React.FC = ({ props, cardToken, maxHeight, baseId, }) => { const { headerSlot1, headerTitle, headerTag, headerSlot2, subHeader, bodySlot1, bodyTitle, content, bodySlot2, actionButton, } = props const variant = CardVariant.DEFAULT const hasHeader = Boolean( headerSlot1 || headerTitle || headerTag || headerSlot2 ) const hasSubHeader = Boolean(subHeader) const hasBodySlot1 = Boolean(bodySlot1) const hasBodyTitle = Boolean(bodyTitle) const hasContent = Boolean(content) const hasBodySlot2 = Boolean(bodySlot2) const hasActionButton = Boolean(actionButton) const isInlineButton = isInlineActionButton(actionButton, false) // Generate unique IDs for ARIA relationships const headerTitleId = `${baseId}-header-title` const subHeaderId = `${baseId}-subheader` const bodyTitleId = `${baseId}-body-title` const contentId = `${baseId}-content` const contentDataId = isPlainTextContent(content) ? String(content) : undefined return ( <> {hasHeader && ( {headerSlot1 && ( )} {headerTitle && ( {headerTitle} )} {headerTag && {headerTag}} {hasSubHeader && ( {subHeader} )} {headerSlot2 && {headerSlot2}} )} {hasBodySlot1 && ( {bodySlot1} )} {hasBodyTitle && ( {bodyTitle} )} {hasContent && ( )} {hasBodySlot2 && ( {bodySlot2} )} {hasActionButton && (