import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { confirm } from '@inquirer/prompts';
import ansis from 'ansis';
import { expandHome } from '../core/paths.js';
import { SLASH_TEMPLATES } from '../core/slash-templates.js';
export async function gitInstallCommand(opts = {}) {
    const scope = opts.scope ?? 'user';
    const baseDir = scope === 'user'
        ? expandHome('~/.claude/commands/ccjk')
        : join(process.cwd(), '.claude/commands/ccjk');
    const target = opts.target ? expandHome(opts.target) : baseDir;
    const names = Object.keys(SLASH_TEMPLATES);
    console.log(ansis.dim(`\n→ 安装到: ${target}`));
    console.log(ansis.dim(`→ 命令: ${names.map(n => `/ccjk:${n}`).join(', ')}\n`));
    if (!opts.yes) {
        const ok = await confirm({
            message: '确认安装？',
            default: true,
        });
        if (!ok) {
            console.log(ansis.gray('已取消。'));
            return;
        }
    }
    await mkdir(target, { recursive: true });
    for (const name of names) {
        const path = join(target, `${name}.md`);
        if (existsSync(path) && !opts.yes) {
            const overwrite = await confirm({
                message: `${name}.md 已存在，覆盖？`,
                default: false,
            });
            if (!overwrite) {
                console.log(ansis.gray(`  跳过 ${name}`));
                continue;
            }
        }
        await writeFile(path, SLASH_TEMPLATES[name], 'utf-8');
        console.log(ansis.green(`  ✔ ${name}.md`));
    }
    console.log(ansis.green('\n✔ 安装完成'));
    console.log(ansis.dim(`  在 Claude Code/Clavue 中输入 /ccjk:git-commit 试一下\n`));
}
//# sourceMappingURL=git-install.js.map