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

/**
 * Renders a standard dek, which is a title regular 400 on desktop and sans
 * regular component 400 on mobile.
 *
 * ```js
 *
 * import { Dek } from '@politico/interactive-style';
 * ```
 */
const Dek = forwardRef((props, ref) => {
  const {
    as: Tag,
    outlet,
    align,
    children,
    margin
  } = props;
  const marginValue = useResponsiveValues(margin);
  const margins = getMarginClasses(marginValue, {
    defaultSide: 'y',
    sides: ['y', 't', 'b']
  });
  return <Tag ref={ref} className={cls('dek', `outlet-${outlet}`, `align-${align}`, margins)}>
      {children}
    </Tag>;
});
Dek.displayName = 'Dek';
Dek.defaultProps = {
  as: 'div',
  outlet: 'interactive',
  align: undefined,
  children: undefined,
  margin: undefined
};
Dek.propTypes = {
  /**
   * Specify what kind of element to render as the dek.
   */
  as: PropTypes.elementType,
  /**
   * Specify the outlet style to use for the dek text.
   */
  outlet: PropTypes.oneOf(['interactive', 'magazine']),
  /**
   * Specify the text alignment of the text.
   */
  align: PropTypes.oneOf(['left', 'right', 'center']),
  /**
   * The content of the dek.
   */
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
  /**
   * The vertical margins of the Dek. 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
   * `Dek` does 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
  })]))
};
export default Dek;