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

const styleByType = {
  warning: {
    icon: {
      type: 'hour-glass',
      className: 'mt-chip__warning-icon',
    },
    className: 'mt-chip__warning',
  },

  danger: {
    icon: {
      type: 'status-denied',
      className: 'mt-chip__danger-icon',
    },
    className: 'mt-chip__danger',
  },

  info: {
    icon: {
      type: 'info',
      className: 'mt-chip__info-icon',
    },
    className: 'mt-chip__info',
  },

  positive: {
    icon: {
      type: 'status-approved',
      className: 'mt-chip__positive-icon',
    },
    className: 'mt-chip__positive',
  },
}

const MTChip = ({
  children,
  color,
  style = {},
  className,
  type,
  ...otherProps
}) => {
  const typeStyling = styleByType[type]

  return (
    <div
      { ...otherProps }
      className={ cx('mt-chip', className, typeStyling?.className) }
      style={ {
        backgroundColor: color,
        ...style,
      } }
    >
      { typeStyling?.icon && (
        <MTIcon
          type={ typeStyling.icon.type }
          className={ typeStyling.icon.className }
        />
      ) }
      { children }
    </div>
  )
}

export default MTChip
