import React from 'react'
import cx from 'classnames'
import MTIcon from './mt-icon'

const MTToolbox = (props) => {
  const {
    title = 'Activity',
    isOpen,
    twoCol = false,
    hasFooter = false,
    icon = 'settings',
    iconBackgroundColor = '#022E61',
    preTitle = '',
    onClose,
    ...otherProps
  } = props

  const classes = cx({
    toolbox: true,
    animated: true,
    'dont-print': true,
    hidden: !isOpen,
    fadeOutRight: !isOpen,
    fadeInRight: isOpen,
    'with-footer': hasFooter,
    'two-col': twoCol,
  })

  const iconBackgroundStyle = {
    backgroundColor: iconBackgroundColor,
  }

  return (
    <div
      { ...otherProps }
      className={ classes }
    >
      <div className="toolbox-header">
        <div className="toolbox-header__title">
          <div className="toolbox-header__title-icon" style={ iconBackgroundStyle }>
            <MTIcon type={ icon } align={ false } />
          </div>
          <div className="toolbox-header__title-text">
            <h4 className="h4">{ preTitle }</h4>
            <h3 className="h3">{ title }</h3>
          </div>
        </div>
        <div className="toolbox-header__controls">
          { props.controls }
        </div>
        <div className="toolbox-header__close">
          <MTIcon type="close" onClick={ onClose } />
        </div>
      </div>
      <div className="toolbox__content">{ props.children }</div>
    </div>
  )
}

MTToolbox.defaultProps = {
  title: 'Activity',
  isOpen: false,
  onClose: () => {},
  twoCol: false,
  hasFooter: false,
  icon: 'settings',
  iconBackgroundColor: '#022E61',
  preTitle: '',
}

export default MTToolbox
