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

const { Text } = Typography

const ObjectDisplay = ({ object, objectType }) => {
  if (!object) {
    return <Text type='secondary'>n/a</Text>
  }
  const model = getModelByName(objectType)
  const Icon = model.icon
  return (
    <Tag color='default' style={{ margin: 0 }} icon={<Icon />}>
      {object?.name ? object.name : null}
    </Tag>
  )
}

ObjectDisplay.propTypes = {
  object: PropTypes.object,
  objectType: PropTypes.string,
  style: PropTypes.object
}

export default ObjectDisplay
