import axios from 'axios';
// Base URL for your backend API
const API_BASE_URL = '/api'; // Use your actual backend URL
// --- Mock Data (Replace with actual API calls) ---
const MOCK_CENSUS_VARS = [
{ id: 'medianIncome', name: 'Median Household Income' },
{ id: 'avgAge', name: 'Average Age' },
{ id: 'populationDensity', name: 'Population Density' },
];
const MOCK_CRM_FIELDS = [
{ id: 'lifetimeValue', name: 'Customer Lifetime Value' },
{ id: 'lastPurchaseDate', name: 'Last Purchase Date' },
{ id: 'productCategory', name: 'Top Product Category' },
];
const MOCK_GOOGLE_AUDIENCES = [
{ id: 'aud1', name: 'High-Intent Tech Shoppers' },
{ id: 'aud2', name: 'Engaged Users - 30d' },
{ id: 'aud3', name: 'Cart Abandoners - 7d' },
];
const MOCK_COMBINED_DATA = [
// Add more diverse mock data
{ id: 1, customerId: 'crm-123', zipCode: '90210', state: 'CA', latitude: 34.0902, longitude: -118.4064, censusData: { medianIncome: 110500, avgAge: 45, populationDensity: 3510 }, crmData: { lifetimeValue: 1500, lastPurchaseDate: '2024-10-20', productCategory: 'Electronics' }, googleAudiences: ['High-Intent Tech Shoppers', 'Engaged Users - 30d'] },
{ id: 2, customerId: 'crm-456', zipCode: '10001', state: 'NY', latitude: 40.7505, longitude: -73.9972, censusData: { medianIncome: 85000, avgAge: 38, populationDensity: 25000 }, crmData: { lifetimeValue: 800, lastPurchaseDate: '2024-11-05', productCategory: 'Apparel' }, googleAudiences: ['Engaged Users - 30d'] },
{ id: 3, customerId: 'crm-789', zipCode: '60611', state: 'IL', latitude: 41.8918, longitude: -87.6232, censusData: { medianIncome: 95000, avgAge: 41, populationDensity: 18000 }, crmData: { lifetimeValue: 2200, lastPurchaseDate: '2024-09-15', productCategory: 'Home Goods' }, googleAudiences: ['High-Intent Tech Shoppers', 'Cart Abandoners - 7d'] },
{ id: 4, customerId: 'crm-101', zipCode: '94107', state: 'CA', latitude: 37.7749, longitude: -122.4194, censusData: { medianIncome: 130000, avgAge: 35, populationDensity: 17500 }, crmData: { lifetimeValue: 500, lastPurchaseDate: '2024-11-10', productCategory: 'Software' }, googleAudiences: ['Engaged Users - 30d'] },
];
// --- End Mock Data ---
// Simulate API delay
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
export const fetchCensusVariables = async () => {
console.log("API: Fetching Census Variables...");
await sleep(300); // Simulate network delay
// Replace with: return axios.get(`${API_BASE_URL}/census-variables`);
return { data: MOCK_CENSUS_VARS };
};
export const fetchCrmFields = async () => {
console.log("API: Fetching CRM Fields...");
await sleep(300);
// Replace with: return axios.get(`${API_BASE_URL}/crm-fields`);
return { data: MOCK_CRM_FIELDS };
};
export const fetchGoogleAudiences = async () => {
console.log("API: Fetching Google Audiences...");
await sleep(300);
// Replace with: return axios.get(`${API_BASE_URL}/google-audiences`);
return { data: MOCK_GOOGLE_AUDIENCES };
};
export const fetchAnalyticsData = async (filters) => {
console.log("API: Fetching Analytics Data with filters:", filters);
await sleep(1000); // Simulate network delay & processing
// Replace with: return axios.post(`${API_BASE_URL}/analytics-data`, filters);
// Basic mock filtering (implement more robust filtering based on 'filters' object)
let filteredData = MOCK_COMBINED_DATA;
if (filters?.states?.length) {
filteredData = filteredData.filter(item => filters.states.includes(item.state));
}
if (filters?.googleAudiences?.length) {
filteredData = filteredData.filter(item =>
filters.googleAudiences.some(audId =>
MOCK_GOOGLE_AUDIENCES.find(mockAud => mockAud.id === audId && item.googleAudiences.includes(mockAud.name))
)
);
}
// Add more filtering logic based on censusData, crmData etc. from the 'filters' object
console.log(`API: Returning ${filteredData.length} records.`);
return { data: filteredData };
};