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` : null,
        (url) => fetcher(url, BASE_URL.nest),
        {
            revalidateOnFocus: false
        }
    )

    return (
        <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
            {Array.isArray(typeData) && (typeData.find(type => Number(type.id) === Number(object_data.type)) as IObjectType).name}
        </div>
    )
}

export default ObjectData