export async function getOverviewData() {
  //  console.log("hitting here");
  try {
    // Fetch data from our API route
   
    
    const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000'}/api/dashboard`, {
      cache: 'no-store' // Ensure fresh data on each request
    });
     
    if (!response.ok) {
      throw new Error('Failed to fetch dashboard data');
    }

    const data = await response.json();

    // Transform API data to match component expectations
    return {
      views: {
        value: data.activeSessions,
        growthRate: 0.43,
      },
      profit: {
        value: data.totalRevenue,
        growthRate: 4.35,
      },
      products: {
        value: Math.floor(data.totalUsers / 10), // Example calculation
        growthRate: 2.59,
      },
      users: {
        value: data.totalUsers,
        growthRate: -0.95,
      },
    };
  } catch (error) {
    console.error('Error fetching overview data:', error);
    // Fallback to mock data if API fails
    return {
      views: {
        value: 3456,
        growthRate: 0.43,
      },
      profit: {
        value: 4220,
        growthRate: 4.35,
      },
      products: {
        value: 3456,
        growthRate: 2.59,
      },
      users: {
        value: 3456,
        growthRate: -0.95,
      },
    };
  }
}

export async function getChatsData() {
  // Fake delay
  await new Promise((resolve) => setTimeout(resolve, 1000));

  return [
    {
      name: "Jacob Jones",
      profile: "/images/user/user-01.png",
      isActive: true,
      lastMessage: {
        content: "See you tomorrow at the meeting!",
        type: "text",
        timestamp: "2024-12-19T14:30:00Z",
        isRead: false,
      },
      unreadCount: 3,
    },
    {
      name: "Wilium Smith",
      profile: "/images/user/user-03.png",
      isActive: true,
      lastMessage: {
        content: "Thanks for the update",
        type: "text",
        timestamp: "2024-12-19T10:15:00Z",
        isRead: true,
      },
      unreadCount: 0,
    },
    {
      name: "Johurul Haque",
      profile: "/images/user/user-04.png",
      isActive: false,
      lastMessage: {
        content: "What's up?",
        type: "text",
        timestamp: "2024-12-19T10:15:00Z",
        isRead: true,
      },
      unreadCount: 0,
    },
    {
      name: "M. Chowdhury",
      profile: "/images/user/user-05.png",
      isActive: false,
      lastMessage: {
        content: "Where are you now?",
        type: "text",
        timestamp: "2024-12-19T10:15:00Z",
        isRead: true,
      },
      unreadCount: 2,
    },
    {
      name: "Akagami",
      profile: "/images/user/user-07.png",
      isActive: false,
      lastMessage: {
        content: "Hey, how are you?",
        type: "text",
        timestamp: "2024-12-19T10:15:00Z",
        isRead: true,
      },
      unreadCount: 0,
    },
  ];
}