import PropTypes from 'prop-types'
import { Tag, Typography } from 'antd'
import { getModelByName } from '../../../database/ObjectModels'

const { Text } = Typography

const ObjectTypeDisplay = ({
  objectType,
  showIcon = true,
  showLabel = true,
  style,
  color = 'default'
}) => {
  if (!objectType) {
    return <Text type='secondary'>n/a</Text>
  }

  const model = getModelByName(objectType)

  if (!model || model.name === 'unknown') {
    return <Text type='secondary'>Unknown type</Text>
  }

  const Icon = model.icon

  return (
    <Tag
      color={color}
      style={{ margin: 0, ...style }}
      icon={showIcon && Icon ? <Icon /> : undefined}
      className='object-type-display-tag'
    >
      {showLabel && model.label && model.label}
    </Tag>
  )
}

ObjectTypeDisplay.propTypes = {
  objectType: PropTypes.string,
  showIcon: PropTypes.bool,
  showLabel: PropTypes.bool,
  showPrefix: PropTypes.bool,
  style: PropTypes.object,
  color: PropTypes.string
}

export default ObjectTypeDisplay
