"use strict";
/**
 * 🎯 Chrome Extension Interactive Confirmation
 * Google-style "Did you mean?" with inquirer
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChromeExtensionConfirmer = void 0;
const inquirer_1 = __importDefault(require("inquirer"));
const colors_1 = require("../fix-once/colors");
const chrome_extension_detector_1 = require("./chrome-extension-detector");
class ChromeExtensionConfirmer {
    /**
     * Ask user to confirm Chrome Extension detection
     */
    static async confirmDetection(text, confidence) {
        // Check if we're in an interactive terminal
        if (!process.stdin.isTTY) {
            // In non-TTY, use confidence level for auto-decision
            return confidence === 'medium'; // Assume yes for medium confidence
        }
        const messages = {
            medium: `🎯 Detected possible Chrome Extension from: "${colors_1.chalk.yellow(text)}"`,
            low: `💭 Found extension-related terms in: "${colors_1.chalk.gray(text)}"`
        };
        const questions = {
            medium: 'Did you mean to create a Chrome Extension?',
            low: 'Is this a Chrome Extension project?'
        };
        console.log();
        console.log(messages[confidence]);
        const { confirmed } = await inquirer_1.default.prompt([
            {
                type: 'confirm',
                name: 'confirmed',
                message: questions[confidence],
                default: confidence === 'medium'
            }
        ]);
        return confirmed;
    }
    /**
     * Show suggestions for common variations
     */
    static async selectFromSuggestions(input) {
        const suggestions = this.generateSuggestions(input);
        if (suggestions.length === 0) {
            return null;
        }
        // Check if we're in an interactive terminal
        if (!process.stdin.isTTY) {
            // In non-TTY, return first suggestion or null
            return suggestions[0]?.value || null;
        }
        console.log();
        console.log(colors_1.chalk.cyan('🔍 Did you mean one of these?'));
        const { selection } = await inquirer_1.default.prompt([
            {
                type: 'list',
                name: 'selection',
                message: 'Select project type:',
                choices: [
                    ...suggestions.map(s => ({
                        name: s.display,
                        value: s.value
                    })),
                    new inquirer_1.default.Separator(),
                    {
                        name: 'None of these (continue as-is)',
                        value: null
                    }
                ]
            }
        ]);
        return selection;
    }
    /**
     * Generate smart suggestions based on input
     */
    static generateSuggestions(input) {
        const normalized = input.toLowerCase();
        const suggestions = [];
        // Check for Chrome Extension indicators
        const ceDetection = chrome_extension_detector_1.ChromeExtensionDetector.detect(normalized);
        if (ceDetection.confidence !== 'none') {
            suggestions.push({
                display: '🧩 Chrome Extension - Browser extension for Chrome/Edge',
                value: 'chrome-extension'
            });
        }
        // Check for related types
        if (normalized.includes('browser') || normalized.includes('web')) {
            if (!suggestions.find(s => s.value === 'chrome-extension')) {
                suggestions.push({
                    display: '🌐 Web Application - Traditional web app',
                    value: 'web-app'
                });
            }
        }
        if (normalized.includes('ext') || normalized.includes('plugin')) {
            suggestions.push({
                display: '🔌 Browser Plugin/Extension',
                value: 'browser-extension'
            });
        }
        if (normalized.includes('popup') || normalized.includes('toolbar')) {
            suggestions.push({
                display: '📱 Chrome Extension with Popup UI',
                value: 'chrome-extension-popup'
            });
        }
        if (normalized.includes('script') || normalized.includes('inject')) {
            suggestions.push({
                display: '💉 Content Script Extension',
                value: 'chrome-extension-content'
            });
        }
        return suggestions;
    }
    /**
     * Interactive project type selector with fuzzy search
     */
    static async selectProjectType(currentInput) {
        const projectTypes = [
            { name: '🧩 Chrome Extension', value: 'chrome-extension' },
            { name: '🌐 Web Application', value: 'web-app' },
            { name: '📱 Mobile App', value: 'mobile' },
            { name: '⚙️ CLI Tool', value: 'cli' },
            { name: '📚 Library/Package', value: 'library' },
            { name: '🔧 API/Backend', value: 'api' },
            { name: '🎮 Game', value: 'game' },
            { name: '🤖 Bot/Automation', value: 'bot' },
            { name: '📊 Data Science', value: 'data-science' },
            { name: '🎨 Other/Custom', value: 'other' }
        ];
        // If we have input, check for matches
        if (currentInput) {
            const detection = chrome_extension_detector_1.ChromeExtensionDetector.detect(currentInput);
            if (detection.confidence === 'high') {
                console.log(colors_1.chalk.green('✅ Chrome Extension detected automatically!'));
                return 'chrome-extension';
            }
            if (detection.confidence === 'medium' || detection.confidence === 'low') {
                const confirmed = await this.confirmDetection(currentInput, detection.confidence);
                if (confirmed) {
                    return 'chrome-extension';
                }
            }
        }
        // Check if we're in an interactive terminal
        if (!process.stdin.isTTY) {
            // In non-TTY, return best guess or default
            return currentInput ? this.guessDefault(currentInput) : 'web-app';
        }
        const { projectType } = await inquirer_1.default.prompt([
            {
                type: 'list',
                name: 'projectType',
                message: 'What type of project is this?',
                choices: projectTypes,
                default: currentInput ? this.guessDefault(currentInput) : 'web-app'
            }
        ]);
        return projectType;
    }
    /**
     * Guess the most likely default based on input
     */
    static guessDefault(input) {
        const normalized = input.toLowerCase();
        if (chrome_extension_detector_1.ChromeExtensionDetector.detect(normalized).confidence !== 'none') {
            return 'chrome-extension';
        }
        if (normalized.includes('api') || normalized.includes('backend')) {
            return 'api';
        }
        if (normalized.includes('cli') || normalized.includes('command')) {
            return 'cli';
        }
        if (normalized.includes('library') || normalized.includes('package')) {
            return 'library';
        }
        return 'web-app';
    }
}
exports.ChromeExtensionConfirmer = ChromeExtensionConfirmer;
/**
 * Example usage:
 *
 * Input: "chr ext for managing tabs"
 * → Shows: "🎯 Detected possible Chrome Extension"
 * → Asks: "Did you mean to create a Chrome Extension?" [Y/n]
 *
 * Input: "c e"
 * → Shows suggestions list with Chrome Extension highlighted
 *
 * Input: "extension"
 * → Shows: "💭 Found extension-related terms"
 * → Asks: "Is this a Chrome Extension project?" [y/N]
 */ 
//# sourceMappingURL=chrome-extension-confirmer.js.map