'use client'; import { Metar } from '@/api/metar.types'; import { Box, Card, Divider } from '@mantine/core'; import { CartesianGrid, LabelList, Line, LineChart, XAxis, YAxis } from 'recharts'; export default function SkyConditions({ metar }: { metar: Metar }) { const data: any = [ { name: 'start' }, { name: 'end' } ]; if (metar.sky_condition && metar.sky_condition.length > 0 && metar.sky_condition[0].sky_cover != 'CLR') { let maxHeight = 0; metar.sky_condition.forEach((skyCondition, index) => { data[0][index] = skyCondition.cloud_base_ft_agl; data[1][index] = skyCondition.cloud_base_ft_agl; if (skyCondition.cloud_base_ft_agl > maxHeight) { maxHeight = skyCondition.cloud_base_ft_agl; } }); maxHeight = Math.ceil((maxHeight % 1000 == 0 ? maxHeight + 1 : maxHeight) / 1000) * 1000; let interval; if (maxHeight <= 5000) { interval = 1; } else if (maxHeight <= 10000) { interval = 2; } else if (maxHeight <= 15000) { interval = 3; } else if (maxHeight <= 20000) { interval = 5; } else { interval = 10; } return ( {metar.sky_condition.map((skyCondition, index) => ( renderCustomizedLabel(props, skyCondition.sky_cover)} /> ))} ); } else { return ( Clear Skies ); } } const renderCustomizedLabel = (props: any, skyCover: string) => { const { x, y, value, index } = props; if (index == 1) { return ( {skyCover} {value} ); } else { return <>; } };