import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { getModifierClasses } from '../../../helpers';

const propTypes = {
  /**
   * The page content.
   */
  children: PropTypes.node,
  /**
   * The size of the space around the page.
   * You can also use responsive values like 'xs sm@md md@lg'
   */
  gutter: PropTypes.oneOfType([
    PropTypes.oneOf(['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
    PropTypes.string,
  ]),
  /**
   * The size of the horizontal space around the page.
   * You can also use responsive values like 'xs sm@md md@lg'
   */
  gutterHorizontal: PropTypes.oneOfType([
    PropTypes.oneOf(['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
    PropTypes.string,
  ]),
  /**
   * The size of the vertical space around the page.
   * You can also use responsive values like 'xs sm@md md@lg'
   */
  gutterVertical: PropTypes.oneOfType([
    PropTypes.oneOf(['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
    PropTypes.string,
  ]),
  /**
   * The content size.
   */
  size: PropTypes.oneOf(['full', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
  /**
   * The component used for the root node.
   * Either a string to use a DOM element or a component.
   */
  tag: PropTypes.elementType,
};

const defaultProps = {
  children: '',
  gutter: null,
  gutterHorizontal: null,
  gutterVertical: null,
  size: null,
  tag: 'div',
};

export const Container = ({
  children,
  gutter,
  gutterHorizontal,
  gutterVertical,
  size,
  tag: Tag,
  ...props
}) => {
  const classes = classnames(
    getModifierClasses({
      value: size,
      prefix: 'size',
      isResponsive: false,
      allowed: ['full', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
    }),
    getModifierClasses({
      value: gutter,
      prefix: 'gutter',
      isResponsive: true,
      allowed: ['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
    }),
    getModifierClasses({
      value: gutterVertical,
      prefix: 'gutter-vertical',
      isResponsive: true,
      allowed: ['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
    }),
    getModifierClasses({
      value: gutterHorizontal,
      prefix: 'gutter-horizontal',
      isResponsive: true,
      allowed: ['none', 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
    }),
  );

  return (
    <Tag className={`sui-l-container ${classes}`} {...props}>
      {children}
    </Tag>
  );
};

Container.propTypes = propTypes;
Container.defaultProps = defaultProps;
