import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { ComponentProps } from "@openchatai/copilot-widget";
import { ResponsiveLine } from "@nivo/line";
interface WeatherInfo {
latitude: number;
longitude: number;
generationtime_ms: number;
utc_offset_seconds: number;
timezone: string;
timezone_abbreviation: string;
elevation: number;
current_units: {
time: string;
interval: string;
temperature_2m: string;
wind_speed_10m: string;
};
current: {
time: string;
interval: number;
temperature_2m: number;
wind_speed_10m: number;
};
hourly_units: {
time: string;
temperature_2m: string;
relative_humidity_2m: string;
wind_speed_10m: string;
};
hourly: {
time: string[];
temperature_2m: number[];
relative_humidity_2m: number[];
wind_speed_10m: number[];
};
}
type Props = ComponentProps<WeatherInfo>;
export function GetWetherDataRenderer(props: Props) {
const {
data: { current, current_units, hourly },
} = props;
return (
<Card className="max-w-sm p-3">
<CardHeader className="flex flex-row items-center">
<div className="grid gap-0.5">
<CardTitle className="text-xl">Partly Cloudy</CardTitle>
<CardDescription>
{current.temperature_2m}
{current_units.temperature_2m} Wind {current.wind_speed_10m}{" "}
{current_units.wind_speed_10m}
</CardDescription>
</div>
</CardHeader>
<CardContent>
<div className="hourly-forecast">
<div
className="w-full"
style={{
height: "150px",
marginTop: "1rem",
}}
>
<ResponsiveLine
data={[
{
id: "temperature",
color: "hsl(0, 70%, 50%)",
data: hourly.time.map((time, index) => ({
x: time,
y: hourly.temperature_2m[index],
})),
},
{
id: "humidity",
color: "hsl(120, 70%, 50%)",
data: hourly.time.map((time, index) => ({
x: time,
y: hourly.relative_humidity_2m[index],
})),
},
{
id: "wind",
color: "hsl(240, 70%, 50%)",
data: hourly.time.map((time, index) => ({
x: time,
y: hourly.wind_speed_10m[index],
})),
},
]}
yScale={{
type: "linear",
min: "auto",
max: "auto",
stacked: true,
reverse: false,
}}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "transportation",
legendOffset: 36,
legendPosition: "middle",
truncateTickAt: 0,
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "count",
legendOffset: -40,
legendPosition: "middle",
truncateTickAt: 0,
}}
/>
</div>
</div>
</CardContent>
</Card>
);
}