import { forwardRef } from 'react';
import PropTypes from 'prop-types';
import useResponsiveValues from "../../../hooks/breakpoint/useResponsiveValues/index.js";
import CustomPropTypes from "../../../utils/prop-types/index.js";
import cx from "../../../utils/css/cx.js";
import getMarginClasses from "../../../utils/css/getMarginClasses.js";
import classes from './styles.module.scss';

/**
 * Renders a centered content well with responsive max width and padding. This
 * is a standard container for most basic content being rendered on a page.
 *
 * ```js
 *
 * import { Well } from '@politico/interactive-style';
 * ```
 */
const Well = forwardRef((props, ref) => {
  const {
    children,
    margin,
    relative,
    as: Tag
  } = props;
  const marginValue = useResponsiveValues(margin);
  const margins = getMarginClasses(marginValue, {
    defaultSide: 'y',
    sides: ['y', 't', 'b']
  });
  return <Tag ref={ref} className={cx.merge(classes)('root', margins, {
    relative
  })}>
      {children}
    </Tag>;
});
Well.displayName = 'Well';
Well.defaultProps = {
  children: undefined,
  margin: undefined,
  relative: false,
  as: 'div'
};
Well.propTypes = {
  /**
   * Control which kind of tag or component is used to render the Well
   * container. If you use a custom component it will be passed `className` and
   * `ref` props.
   */
  as: PropTypes.elementType,
  /**
   * The vertical margins of the well. Margins can be specified as one spacing
   * value that gets used on both top and bottom, an explicit `y` value, or
   * completely separate `tb` values. The values correspond to levels of our
   * spacing scale (e.g., `"4"` corresponds to `$spacing-4`). Note that wells
   * do not support custom horizontal margins.
   */
  margin: CustomPropTypes.responsive(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
    y: PropTypes.string
  }), PropTypes.shape({
    t: PropTypes.string,
    b: PropTypes.string
  })])),
  /**
   * Whether the well should specify `position: relative` to allow absolute
   * positioning within it.
   */
  relative: PropTypes.bool,
  /**
   * Any children that should be rendered within the Well container.
   */
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)])
};
export default Well;