'use client';
import { Airport } from '@/api/airport.types';
import { Metar } from '@/api/metar.types';
import { FaArrowsSpin, FaLocationArrow } from 'react-icons/fa6';
import Link from 'next/link';
import { AiFillStar, AiOutlineStar } from 'react-icons/ai';
import {
BsFillCloudDrizzleFill,
BsFillCloudFogFill,
BsFillCloudHailFill,
BsFillCloudHazeFill,
BsFillCloudRainFill,
BsFillCloudRainHeavyFill,
BsFillCloudSleetFill,
BsFillCloudSnowFill,
BsQuestionLg
} from 'react-icons/bs';
import { useState } from 'react';
import { Card, Divider, Grid, Modal, Tooltip } from '@mantine/core';
import './metars.css';
import SkyConditions from './SkyConditions';
interface MetarModalProps {
airport: Airport;
isOpen: boolean;
onClose(): void;
}
export default function MetarModal({ airport, isOpen, onClose }: MetarModalProps) {
const [isFavorite, setIsFavorite] = useState(false);
function handleFavorite(value: boolean) {
setIsFavorite(value);
}
return (
{airport.icao} {airport.full_name}
{isFavorite ? (
handleFavorite(false)} />
) : (
handleFavorite(true)} />
)}
);
}
function MetarInfo({ metar }: { metar: Metar }) {
function metarBGColor(metar: Metar | undefined) {
if (metar?.flight_category == 'VFR') {
return 'green';
} else if (metar?.flight_category == 'MVFR') {
return 'blue';
} else if (metar?.flight_category == 'IFR') {
return 'red';
} else if (metar?.flight_category == 'LIFR') {
return 'purple';
} else {
return 'black';
}
}
function windColor(metar: Metar | undefined) {
if (metar) {
if (Number(metar.wind_speed_kt) <= 9) {
return 'green';
} else if (Number(metar.wind_speed_kt) <= 12) {
return 'orange';
} else {
return 'red';
}
} else {
return 'gray';
}
}
return (
{metar.raw_text}
{metar.flight_category ? metar.flight_category : 'UNKN'}
<>
{metar.wind_speed_kt == undefined || metar.wind_speed_kt == 0 ? (
CALM
) : (
{metar.wind_speed_kt} KT
{metar.wind_dir_degrees && Number(metar.wind_dir_degrees) > 0 ? (
<>
{metar.wind_dir_degrees}°
>
) : (
<>>
)}
{metar.wind_dir_degrees && metar.wind_dir_degrees == 'VRB' ? (
<>
VRB
>
) : (
<>>
)}
)}
>
{metar.wx_string &&
metar.wx_string.split(' ').map((wx) => (
))}
);
}
function MetarIcon({ wx }: { wx: string }) {
// let color = 'bg-gray-400';
let title = '';
let icon = undefined;
if (wx.includes('DZ')) {
title = 'Drizzle';
icon = ;
} else if (wx.includes('RA')) {
title = 'Rain';
icon = ;
} else if (wx.includes('SN')) {
title = 'Snow';
icon = ;
} else if (wx.includes('SG')) {
title = 'Snow Grains';
icon = ;
} else if (wx.includes('IC')) {
title = 'Ice Crystals';
icon = ;
} else if (wx.includes('PL')) {
title = 'Ice Pellets';
icon = ;
} else if (wx.includes('GR')) {
title = 'Hail';
icon = ;
} else if (wx.includes('GS')) {
title = 'Snow Pellets';
icon = ;
} else if (wx.includes('BR')) {
title = 'Mist';
icon = ;
} else if (wx.includes('FG')) {
title = 'Fog';
icon = ;
} else if (wx.includes('FU')) {
title = 'Smoke';
icon = ;
} else if (wx.includes('VA')) {
title = 'Volcanic Ash';
icon = ;
} else if (wx.includes('DU')) {
title = 'Dust';
icon = ;
} else if (wx.includes('SA')) {
title = 'Sand';
icon = ;
} else if (wx.includes('HZ')) {
title = 'Haze';
icon = ;
} else {
title = 'Unknown';
icon = ;
}
return (
{icon}
);
}