import { ReactNode } from 'react';

import { useTestIdAttribute } from '../../../../hooks/useTestIdAttribute';
import { CommonProps } from '../../../../types';
import { assertEmptyObject } from '../../../../utils/assertEmptyObject';

import { StyledBody } from './styled';

export interface CardBodyProps extends CommonProps {
  /** Content of body */
  children: ReactNode;
}

/**
 * Body of {@link Card}
 *
 * ```tsx
 * import { Card, CardHeader, CardBody } from 'ui-kit';
 *
 * <Card>
 *   <CardHeader>Contact Information</CardHeader>
 *   <CardBody>Some content</CardBody>
 * </Card>
 * ```
 */
export function CardBody(props: CardBodyProps) {
  const { children, className, testId, ariaDescribedBy, ...rest } = props;
  assertEmptyObject(rest);

  const testIdAttribute = useTestIdAttribute();

  return (
    <StyledBody aria-describedby={ariaDescribedBy} className={className} {...{ [testIdAttribute]: testId }}>
      {children}
    </StyledBody>
  );
}
