import { ReactNode } from 'react';

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

import { StyledHeader } from './styled';

export interface CardHeaderProps extends CommonProps {
  /** Content of header */
  children: ReactNode;
  id?: string;
}

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

  const testIdAttribute = useTestIdAttribute();

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