import axios from 'axios';
import React, { useEffect, useState } from 'react';

import config from '../config';
import {getAbsEntityCount} from '../utils/axios-utils';

export default function AbsEntityCount() {

    const [absEntityCount, setAbsCount] = useState(null);

    const handleAbsEntityCount = async () => {
	let absEntityCount = null;
        try {
	    absEntityCount = await getAbsEntityCount(`${config.API}stops-count`);
        } catch (err) {
	    console.error('handleAbsEntityCount(): err.message: ' + err.message);
        }
	setAbsCount(absEntityCount);
    };

    useEffect(() => {
	handleAbsEntityCount();
    }, []);

    return (
	<>
	    <p>
		Abs Count: {absEntityCount ? absEntityCount : 'loading...'}&nbsp;
	    </p>
	</>
    );
};
