'use client';

import { useReducer, useEffect } from 'react';
import { Card } from '@/components/ui/card';
import { weatherDataReducer, initialWeatherDataState, WeatherDataState } from './components/weatherDataReducer';
import WeatherContent from './components/WeatherContent';

export default function WeatherPage() {
  const [state, dispatch] = useReducer(weatherDataReducer, initialWeatherDataState);

  useEffect(() => {
    // 加载存储的数据
    dispatch({ type: 'LOAD_FROM_STORAGE' });
  }, []);

  // 保存数据到localStorage
  useEffect(() => {
    dispatch({ type: 'SAVE_TO_STORAGE' });
  }, [state.weatherData, state.weatherAlerts, state.filters]);

  return (
    <div className="space-y-6">

      <WeatherContent state={state} dispatch={dispatch} />
    </div>
  );
}