"use strict";
/**
 * @fileoverview Template creation utilities for new problem setup.
 * Provides functions to copy template files and display setup instructions.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logTemplateCreationSuccess = logTemplateCreationSuccess;
exports.copyTemplate = copyTemplate;
exports.handleTemplateCreationError = handleTemplateCreationError;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const formatter_1 = require("../formatter");
/**
 * Displays success message and next steps after template creation.
 * Shows formatted instructions for getting started with the new problem.
 *
 * @param {string} directory - Name of the created problem directory
 *
 * @example
 * // From actions.ts createTemplateAction
 * logTemplateCreationSuccess('my-problem');
 * // Displays:
 * //   1. cd my-problem
 * //   2. Add your solutions, generators, and validator
 * //   3. Edit Config.json...
 * //   4. Run 'polyman generate all' to generate tests
 * //   5. Run 'polyman validate all' to validate tests
 * //   6. Run 'polyman verify' for full verification
 */
function logTemplateCreationSuccess(directory) {
    console.log();
    formatter_1.fmt.info(`  ${formatter_1.fmt.infoIcon()} ${formatter_1.fmt.bold('Next steps:')}`);
    console.log();
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('1.')} cd ${formatter_1.fmt.highlight(directory)}`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('2.')} Add your solutions, generators, and validator`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('3.')} Edit ${formatter_1.fmt.highlight('Config.json')} to configure your problem`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('4.')} Run ${formatter_1.fmt.highlight('polyman generate all')} to generate tests`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('5.')} Run ${formatter_1.fmt.highlight('polyman validate all')} to validate tests`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('6.')} Run ${formatter_1.fmt.highlight('polyman verify')} for full verification`);
    formatter_1.fmt.log(`    ${formatter_1.fmt.primary('Full Guide ->')} Visit ${formatter_1.fmt.highlight('https://hamzahassanain.github.io/polyman/')}`);
    console.log();
}
/**
 * Recursively copies template directory structure to destination.
 * Copies all files and subdirectories from template to problem directory.
 *
 * @param {string} srcDir - Source template directory path
 * @param {string} destDir - Destination problem directory path
 *
 * @example
 * // From actions.ts createTemplate
 * const templateDir = path.resolve(__dirname, '../template');
 * const problemDir = path.resolve(process.cwd(), 'my-problem');
 * copyTemplate(templateDir, problemDir);
 */
function copyTemplate(srcDir, destDir) {
    const entries = fs_1.default.readdirSync(srcDir, { withFileTypes: true });
    for (const entry of entries) {
        const srcPath = path_1.default.join(srcDir, entry.name);
        const destPath = path_1.default.join(destDir, entry.name);
        if (entry.isDirectory()) {
            fs_1.default.mkdirSync(destPath, { recursive: true });
            copyTemplate(srcPath, destPath);
        }
        else {
            fs_1.default.copyFileSync(srcPath, destPath);
        }
    }
}
/**
 * Handles template creation errors.
 * Logs error and exits process with code 1.
 *
 * @param {unknown} error - Error that occurred during template creation
 *
 * @example
 * try {
 *   copyTemplate(srcDir, destDir);
 * } catch (error) {
 *   handleTemplateCreationError(error);
 * }
 */
function handleTemplateCreationError(error) {
    const message = error instanceof Error ? error.message : String(error);
    formatter_1.fmt.error(`${formatter_1.fmt.cross()} ${message}`);
    process.exit(1);
}
//# sourceMappingURL=create-template.js.map