import { Spinner } from '@fluentui/react-components';
import type { CustomCellRendererProps } from 'ag-grid-react';
import axios from 'axios';
import useSWR from 'swr';

export default (params: CustomCellRendererProps) => {
    const { data: fuelTypes } = useSWR('/fuel/fuel-types', () => axios.get(`/fuel/fuel-types`, {
        baseURL: import.meta.env.VITE_API_NEST_URL
    }).then(res => res.data))

    if (fuelTypes) {
        return (
            <span>
                {fuelTypes.find((t: {
                    id: number
                    name: string
                }) => t.id === params.value).name}
            </span>
        );
    } else {
        return (
            <Spinner />
        )
    }
}