import api from './api';

export async function fetchFeatureCardCounts(section) {
  try {
    const { data } = await api.get('/api/site/feature-card-clicks', {
      params: { section },
      skipErrorToast: true,
    });
    return data?.counts && typeof data.counts === 'object' && !Array.isArray(data.counts)
      ? data.counts
      : {};
  } catch {
    return {};
  }
}

export async function incrementFeatureCardClick(section, itemId) {
  try {
    const { data } = await api.post(
      '/api/site/feature-card-clicks/increment',
      { section, item_id: itemId },
      { skipErrorToast: true },
    );
    return typeof data?.count === 'number' ? data.count : null;
  } catch {
    return null;
  }
}
