import { debounce } from 'lodash';
import React, { useEffect } from 'react';
import { collectDataFetch ,isEasyvCache} from 'utils/utils';

export default function useEventTracking({ screenId, tenantId, name }) {
  /**
   * 查看信息埋点 - 立即上传
   * 类型、大屏名称、大屏ID、查看次数
   * type、screenName、screenId、screenViewNum
   */
  useEffect(
    // 立即上传，不做本地缓存延迟上报、查看发布链接特殊情况，查看用户大概率无状态
    debounce(() => {
      if (tenantId && !isEasyvCache()) {
        collectDataFetch<{
          type: 'detailScreen';
          screenName: string;
          screenId: number;
          screenViewNum: number;
          id: string;
          tenantId: number;
        }>({
          id: `${screenId}-detail`,
          type: 'detailScreen',
          screenName: name,
          screenId,
          tenantId,
          screenViewNum: 1
        });
      }
    }, 150),
    [tenantId, name, screenId]
  );

  return null;
}
