import TableValue from './TableValue'
import { Text } from '@fluentui/react-components';
import { IObjectValue } from '../../interfaces/objects';

interface ITCBParameterProps {
    values: IObjectValue[];
    vtable: string;
    inactive?: boolean;
    name: string;
    map_id: string;
}

const TCBParameter = ({
    values,
    vtable,
    name,
    map_id
}: ITCBParameterProps) => {
    //Get value
    // const { data: tcbValue } = useSWR(
    //     value ? `/general/params/tcb?id=${value}&vtable=${vtable}` : null,
    //     (url) => fetcher(url, BASE_URL.ems).then(res => res[0]),
    //     {
    //         revalidateOnFocus: false,
    //         revalidateIfStale: false
    //     }
    // )

    const tables = [
        'boiler_meter_caption',
        'BoilersTemper',
        'FuelsParametrs',
        'PipesTypes',
        'vAddRepairEvent',
        'vApartmentTypes',
        'vBoilers',
        'vBoilersAppointment',
        'vBoilersBalance',
        'vBoilersCondition',
        'vBoilersFuels',
        'vBoilersHotWater',
        'vBoilersPerimeter',
        'vBoilersPeriods',
        'vBoilersScheme',
        'vBoilersState',
        'vBoilersTypes',
        'vBuildingManagement',
        'vBuildingOwner',
        'vCanalization',
        'vColdWaterTypes',
        'vConditionEquipment',
        'vCovering',
        'vDensityWater',
        'vDryer',
        'vElectroSupplyTypes',
        'vEquipmentsTypes',
        'vFoundation',
        'vFuelsFeed',
        'vGasSupplyTypes',
        'vHeatingTypes',
        'vHeatTransfer',
        'vHotWaterTypes',
        'vMaterialsWall',
        'vNormative',
        'vPeriodHW',
        'vPipeDiameters',
        'vPipeOutDiameters',
        'vPipesBearingType',
        'vPipesCovering',
        'vPipesEvent',
        'vPipesGround',
        'vPipesIsolation',
        'vPipesLayer',
        'vPipesMaterial',
        'vPumpType',
        'vRepairEvent',
        'vRoof',
        'vRPSType',
        'vServe',
        'vStreets',
        'vTechStatus',
        'vTrash',
        'vTrashStorage',
        'vVentilation',
        'vValvingType',
        'vWallingEquipment',
        'tTypes',
    ]

    const TCBValue = (vtable: string) => {
        if (tables.includes(vtable)) {
            return (
                <TableValue map_id={map_id} values={values} name={name} type='select' vtable={vtable} />
            )
        } else {
            return (
                <Text>
                    {JSON.stringify(name)}
                    {JSON.stringify(Array.isArray(values) && values.length > 0 && values[0].value)}
                </Text>
            )
        }
    }

    return (
        TCBValue(vtable)
    )
}

export default TCBParameter