import { mapBotKindToCategory } from "@nuxtjs/robots/util";
import { useStorage } from "@vueuse/core";
import { ref } from "vue";
const botDetectionStorage = import.meta.client ? useStorage("__nuxt_robots:botd", null, localStorage, {
  serializer: {
    read: (value) => {
      try {
        return JSON.parse(value);
      } catch {
        return null;
      }
    },
    write: (value) => JSON.stringify(value)
  }
}) : ref(null);
export async function runFingerprinting() {
  if (botDetectionStorage.value) {
    return [botDetectionStorage.value, null];
  }
  try {
    const { load } = await import("@fingerprintjs/botd").catch(() => ({
      load: () => Promise.resolve({ detect: () => ({ bot: false }) })
    }));
    const botdAgent = await load().catch(() => ({
      detect: () => ({ bot: false })
    }));
    const result = botdAgent.detect();
    const isBot = result.bot;
    const fingerprintResult = {
      isBot: result.bot,
      botName: result.bot ? result.botKind : void 0,
      botCategory: result.bot ? mapBotKindToCategory(result.botKind) : void 0,
      trusted: false
    };
    if (isBot) {
      botDetectionStorage.value = fingerprintResult;
    }
    return [isBot ? fingerprintResult : false, null];
  } catch (error) {
    return [false, error instanceof Error ? error : new Error(String(error))];
  }
}
