import { ReactNode } from 'react';

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

import { StyledModalFooterButtonGroup } from './styled';

/** Props for {@link ModalFooterButtonGroup} */
export interface ModalFooterButtonGroupProps extends CommonProps {
  children: ReactNode;
}

/** Group of buttons at the bottom of the modal dialog */
export function ModalFooterButtonGroup(props: ModalFooterButtonGroupProps) {
  const { children, className, testId, ariaDescribedBy, ...rest } = props;
  assertEmptyObject(rest);

  const testIdAttribute = useTestIdAttribute();

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