"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VUE_AGENT_CONFIG = void 0;
/* Vue wizard for Amplitude */
const fast_glob_1 = __importDefault(require("fast-glob"));
const package_manager_detection_light_1 = require("../../lib/package-manager-detection-light");
const constants_1 = require("../../lib/constants");
const package_json_1 = require("../../utils/package-json");
const package_json_light_1 = require("../../utils/package-json-light");
const semver_1 = require("../../utils/semver");
const browser_sdk_prompt_1 = require("../_shared/browser-sdk-prompt");
const vue_powered_docs_site_1 = require("../_shared/vue-powered-docs-site");
const FILE_SCAN_IGNORES = [
    '**/node_modules/**',
    '**/dist/**',
    '**/build/**',
    '**/.git/**',
    '**/.nuxt/**',
    '**/.output/**',
];
/**
 * Fallback Vue detection: sniff for .vue source files or Vite config when
 * package.json is missing or doesn't list `vue` (e.g. unusual scaffolds,
 * partial checkouts). Returns false if the tree looks Nuxt-shaped.
 */
async function hasVueFileSignals(installDir) {
    const nuxtConfigs = await (0, fast_glob_1.default)(['nuxt.config.{ts,js,mjs,cjs}'], {
        cwd: installDir,
        deep: 2,
        ignore: FILE_SCAN_IGNORES,
    });
    if (nuxtConfigs.length > 0)
        return false;
    const vueFiles = await (0, fast_glob_1.default)(['**/*.vue'], {
        cwd: installDir,
        deep: 4,
        ignore: FILE_SCAN_IGNORES,
    });
    return vueFiles.length > 0;
}
const getVueVersionBucket = (0, semver_1.createVersionBucket)();
exports.VUE_AGENT_CONFIG = {
    metadata: {
        name: 'Vue',
        glyph: '🟢',
        glyphColor: '#42B883',
        integration: constants_1.Integration.vue,
        targetsBrowser: true,
        docsUrl: 'https://amplitude.com/docs/sdks/analytics/browser/browser-sdk-2',
        beta: true,
        getIntegrationSkillId: () => 'integration-vue-3',
    },
    detection: {
        packageName: 'vue',
        packageDisplayName: 'Vue',
        getVersion: (packageJson) => (0, package_json_1.getPackageVersion)('vue', packageJson),
        getVersionBucket: getVueVersionBucket,
        getInstalledVersion: async (options) => {
            const packageJson = await (0, package_json_light_1.tryGetPackageJson)(options);
            return packageJson ? (0, package_json_1.getPackageVersion)('vue', packageJson) : undefined;
        },
        detect: async (options) => {
            const packageJson = await (0, package_json_light_1.tryGetPackageJson)(options);
            if (packageJson) {
                // Nuxt projects have both 'vue' and 'nuxt' — don't claim them
                if ((0, package_json_1.hasPackageInstalled)('nuxt', packageJson))
                    return false;
                // VitePress, VuePress, Slidev, etc. ship `vue` but are not product SPAs
                if ((0, vue_powered_docs_site_1.isVuePoweredDocsSite)(packageJson))
                    return false;
                return (0, package_json_1.hasPackageInstalled)('vue', packageJson);
            }
            // Fallback: sniff for .vue source files ONLY when package.json is
            // missing. If the manifest exists, trust it — avoids walking large
            // node_modules trees on every non-Vue project.
            return hasVueFileSignals(options.installDir);
        },
        detectPackageManager: package_manager_detection_light_1.detectNodePackageManagersLight,
    },
    environment: {
        uploadToHosting: true,
        getEnvVars: (apiKey, _host) => ({
            VITE_AMPLITUDE_API_KEY: apiKey,
        }),
    },
    analytics: {
        getTags: () => ({}),
    },
    prompts: {
        projectTypeDetection: 'This is a JavaScript/TypeScript project. Look for package.json and lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb) to confirm.',
        getAdditionalContextLines: () => {
            const frameworkId = 'vue';
            return [
                `Framework docs ID: ${frameworkId} (use amplitude://docs/frameworks/${frameworkId} for documentation)`,
                browser_sdk_prompt_1.BROWSER_UNIFIED_SDK_PROMPT_LINE,
                `Initialize from the project's main entry point (typically src/main.ts or src/main.js) before app.mount() so the SDK loads alongside your Vue root.`,
            ];
        },
    },
    ui: {
        successMessage: 'Amplitude integration complete',
        estimatedDurationMinutes: 5,
        getOutroChanges: () => [
            'Analyzed your Vue project structure',
            'Created and configured Amplitude initializers',
            'Integrated Amplitude into your application',
        ],
        getOutroNextSteps: () => [
            'Start your development server to see Amplitude in action',
            'Visit your Amplitude dashboard to see incoming events',
        ],
    },
};
