import { getClassNames } from '@websolutespa/bom-core';
import { ReactNode, useContext } from 'react';
import styled from 'styled-components';
import { getVariantKey } from '../../variants';
import { getCssResponsive } from '../utils';
import { ModalContext } from './modal.context';
import { IModalVariants, modalVariants } from './modal.variants';

const ModalFooterStyle = styled.div<ModalFooterProps>`
  ${props => getVariantKey('footer', props.variant, props.variants)}
  ${props => getCssResponsive(props)}
`;

export type ModalFooterProps = {
  className?: string;
  variant?: keyof typeof modalVariants | (string & {});
  variants?: IModalVariants;
  children?: ReactNode;
};

export const ModalFooter = ({ children, className, variant, variants, ...props }: ModalFooterProps) => {
  const classNames = getClassNames('modal__footer', className);
  const context = useContext(ModalContext);
  return (
    <ModalFooterStyle
      className={classNames}
      variant={variant || context.variant}
      variants={variants || context.variants}
      {...props}
    >
      {children}
    </ModalFooterStyle>
  );
};

ModalFooter.displayName = 'ModalFooter';
