"use strict";
/**
 * Image Analysis Hook Installer
 *
 * Manages installation of prompt templates for image analysis (user-customizable).
 *
 * @module utils/image-analysis/hook-installer
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.installImageAnalysisPrompts = exports.getPromptsDir = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const ui_1 = require("../ui");
const config_manager_1 = require("../config-manager");
/**
 * Get prompts directory for image analysis
 */
function getPromptsDir() {
    return path.join((0, config_manager_1.getCcsHooksDir)(), '..', 'prompts', 'image-analysis');
}
exports.getPromptsDir = getPromptsDir;
/**
 * Install prompt templates to ~/.ccs/prompts/image-analysis/
 * Only installs if directory doesn't exist (doesn't overwrite user edits)
 *
 * @returns true if prompts installed or already exist
 */
function installImageAnalysisPrompts() {
    try {
        const promptsDir = getPromptsDir();
        // Skip if already exists (preserve user customizations)
        if (fs.existsSync(promptsDir)) {
            if (process.env.CCS_DEBUG) {
                console.error((0, ui_1.info)('Image analysis prompts already installed - preserving user customizations'));
            }
            return true;
        }
        // Create directory
        fs.mkdirSync(promptsDir, { recursive: true, mode: 0o755 });
        // Find bundled prompts
        const possibleBasePaths = [
            path.join(__dirname, '..', '..', '..', 'lib', 'prompts'),
            path.join(__dirname, '..', '..', 'lib', 'prompts'),
            path.join(__dirname, '..', 'lib', 'prompts'),
        ];
        let promptsBasePath = null;
        for (const p of possibleBasePaths) {
            if (fs.existsSync(p)) {
                promptsBasePath = p;
                break;
            }
        }
        if (!promptsBasePath) {
            if (process.env.CCS_DEBUG) {
                console.error((0, ui_1.warn)('Image analysis prompts source not found'));
            }
            return false;
        }
        // Copy prompt files
        const promptFiles = [
            'image-analysis-default.txt',
            'image-analysis-screenshot.txt',
            'image-analysis-document.txt',
        ];
        for (const file of promptFiles) {
            const sourcePath = path.join(promptsBasePath, file);
            const destPath = path.join(promptsDir, file.replace('image-analysis-', ''));
            if (fs.existsSync(sourcePath)) {
                fs.copyFileSync(sourcePath, destPath);
                fs.chmodSync(destPath, 0o644);
            }
            else if (process.env.CCS_DEBUG) {
                console.error((0, ui_1.warn)(`Prompt template not found: ${file}`));
            }
        }
        if (process.env.CCS_DEBUG) {
            console.error((0, ui_1.info)(`Installed image analysis prompts: ${promptsDir}`));
        }
        return true;
    }
    catch (error) {
        if (process.env.CCS_DEBUG) {
            console.error((0, ui_1.warn)(`Failed to install image analysis prompts: ${error.message}`));
        }
        return false;
    }
}
exports.installImageAnalysisPrompts = installImageAnalysisPrompts;
//# sourceMappingURL=hook-installer.js.map