import { GetContentListParams } from "@/api/CommonContent";
import { MiniScript } from "../../../common/utils/minisc/MiniScript";
import { navCommonDetail, navCommonList, navigateToAutoContent } from "../common/CommonContent";
import { back, backReturnData, navTo, redirectTo } from "@/components/utils/PageAction";


export function isDynamicScript(script: string): boolean {
  return script.length >= 10 && (script.startsWith('if(') 
    || script.startsWith('return') 
    || script.includes('{') 
    || script.includes('}') 
    || script.includes('(') 
    || script.includes(')') 
    || script.includes('&&') 
    || script.includes('||') 
    || script.includes('!') 
    || script.includes('==') 
    || script.includes('!=') 
    || script.includes('===') 
    || script.includes('!==') 
    || script.includes('>')

  );
}
export function getDynamicScript(): MiniScript {
  const dynamicScript = new MiniScript();
  dynamicScript.registerGlobal('uni', uni);
  dynamicScript.registerGlobal('consts', {
    TYPE_VIDEO: GetContentListParams.TYPE_VIDEO,
    TYPE_ARTICLE: GetContentListParams.TYPE_ARTICLE,
    TYPE_AUDIO: GetContentListParams.TYPE_AUDIO,
    TYPE_IMAGE: GetContentListParams.TYPE_IMAGE,
    TYPE_ARCHIVE: GetContentListParams.TYPE_ARCHIVE,
  });
  dynamicScript.registerFunction('navigateToAutoContent', navigateToAutoContent);
  dynamicScript.registerFunction('navCommonDetail', navCommonDetail);
  dynamicScript.registerFunction('navCommonList', navCommonList);
  dynamicScript.registerFunction('navTo', navTo);
  dynamicScript.registerFunction('back', back);
  dynamicScript.registerFunction('backReturnData', backReturnData);
  dynamicScript.registerFunction('redirectTo', redirectTo);
  return dynamicScript;
}