import { dashboardAPI } from './api.js';

// 使用新的API服务
export const fetchOverviewData = async () => {
  try {
    const response = await dashboardAPI.getOverview();
    return response.data || {};
  } catch (error) {
    console.error('Error fetching overview data:', error);
    return {};
  }
};

export const fetchRealtimeData = async () => {
  try {
    const response = await dashboardAPI.getRealtime();
    return response.data || {};
  } catch (error) {
    console.error('Error fetching realtime data:', error);
    return {};
  }
};

export const fetchFarmData = async () => {
  try {
    const response = await dashboardAPI.getFarmData();
    return response.data || [];
  } catch (error) {
    console.error('Error fetching farm data:', error);
    return [];
  }
};

export const fetchGovernmentData = async (type) => {
  try {
    const response = await dashboardAPI.getGovernmentData();
    return response.data || [];
  } catch (error) {
    console.error('Error fetching government data:', error);
    return [];
  }
};

export const fetchFinanceData = async (type) => {
  try {
    const response = await dashboardAPI.getFinanceData();
    return response.data || [];
  } catch (error) {
    console.error('Error fetching finance data:', error);
    return [];
  }
};

export const fetchMapData = async () => {
  try {
    const response = await dashboardAPI.getMapRegions();
    return response.regions || [];
  } catch (error) {
    console.error('Error fetching map data:', error);
    return [];
  }
};

export const fetchRegionDetail = async (regionId) => {
  try {
    const response = await dashboardAPI.getRegionDetail(regionId);
    return response || {};
  } catch (error) {
    console.error('Error fetching region detail:', error);
    return {};
  }
};