import { Flex } from '@mantine/core'
import { IObjectData, IObjectType } from '../../interfaces/objects'
import useSWR from 'swr'
import { fetcher } from '../../http/axiosInstance'
import { BASE_URL } from '../../constants'

const ObjectData = (object_data: IObjectData) => {
    const { data: typeData } = useSWR(
        object_data.type ? `/general/types/all` : null,
        (url) => fetcher(url, BASE_URL.ems),
        {
            revalidateOnFocus: false
        }
    )

    return (
        <Flex gap='sm' direction='column'>
            {Array.isArray(typeData) && (typeData.find(type => Number(type.id) === Number(object_data.type)) as IObjectType).name}


        </Flex>
    )
}

export default ObjectData