import React from 'react'
import PropTypes from 'prop-types'
import { omit } from 'ramda'

function MTColumn (props) {
  const {
    offset,
    width,
    align,
    children,
    className,
    ...rest
  } = props
  const otherProps = omit([ 'shouldWrap' ], rest)
  const flexStyle = width === 0
    ? {
      flex: '1 1 auto',
      WebkitFlex: '-webkit-flex 1 1 auto',
      MozFlex: '-moz-flex 1 1 auto',
    }
    : {
      flex: `0 0 ${width}%`,
      WebkitFlex: `-webkit-flex 0 0 ${width}%`,
      MozFlex: `-moz-flex 0 0 ${width}%`,
      maxWidth: `${width}%`,
    }
  const offsetStyle = offset === 0 ? { marginLeft: 0 } : { marginLeft: `${offset}%` }
  const columnStyle = Object.assign(flexStyle, offsetStyle)

  return (
    <div
      { ...otherProps }
      className={ `mt-column mt-column--${align} ${className}` }
      style={ columnStyle }
    >
      { children }
    </div>
  )
}

MTColumn.defaultProps = {
  align: 'auto',
  width: 0,
  offset: 0,
  className: '',
}

MTColumn.propTypes = {
  align: PropTypes.string,
  className: PropTypes.string,
  width: PropTypes.number,
  offset: PropTypes.number,
  children: PropTypes.node,
}

export default MTColumn
