import { logClick, logExposure, MDAuto } from "@grace/built-in";
import { IAutoMdData } from "@grace/built-in";
import {getUrlParam} from "@/utils/utils.ts";

const appId = CFG.appID;
const dcm = "202." + CFG.projectId + ".0.0";
const domain = "";

const channel = getUrlParam("channel");
const dom = `${channel}.0.0.0`;

const MDList: IAutoMdData[] = new Array(40).fill("").map((_, i) => {
  return {
    ele: `.md${i + 1}`,
    data: {
      dpm: `${appId}.110.${i + 1}.1`,
      dcm,
      dom,
      domain,
      appId,
    },
    once: false,
  };
});

MDList.push({
  ele: ".md10_0",
  data: {
    dpm: `${appId}.110.10.0`,
    dcm,
    dom,
    domain,
    appId,
  },
  once: true,
});


MDList.push({
  ele: ".md10_1",
  data: {
    dpm: `${appId}.110.10.1`,
    dcm,
    dom,
    domain,
    appId,
  },
  once: true,
});


MDAuto({
  show: MDList, // 曝光
  click: MDList, // 点击
});

export function handleLogExposure(id: number | string, id2: number | string = 1) {
  logExposure({
    dpm: `${appId}.110.${id}.${id2}`,
    dcm,
    domain,
    dom,
    appId,
  });
}

export function handleLogClick(id: number | string, id2: number | string = 1) {
  logClick({
    dpm: `${appId}.110.${id}.${id2}`,
    dcm,
    domain,
    dom,
    appId,
  });
}
