/* eslint-disable no-await-in-loop */
/* eslint-disable unicorn/filename-case */
/* eslint-disable perfectionist/sort-objects */
/* eslint-disable unicorn/better-regex */
/* eslint-disable unicorn/prefer-regexp-test */
/* eslint-disable perfectionist/sort-imports */
import inquirer from 'inquirer';
import log from '../util/log.js';
import Conf from "conf";
const config = new Conf({ projectName: "campfire" });
const appNameExists = (appName) => JSON.parse(config.get("APP_NAMES")).includes(appName);
const appNameValidator = async (input) => {
    if (input.match(/^[A-Za-z0-9-]+$/)) {
        return true;
    }
    return 'Application name must consist only of A-Z, a-z, 0-9, and dash(-)';
};
const appInfoPrompt = async () => {
    log.header('\nPlease answer the following questions to finish configuring Campfire in this repository:');
    let response;
    do {
        response = await inquirer.prompt([{
                name: 'APP_NAME',
                message: 'What is the name of your application?',
                type: 'input',
                validate: appNameValidator,
            }]);
        if (appNameExists(response.APP_NAME))
            log.info("Hm...that app name already exists. Please enter a unique name.");
    } while (appNameExists(response.APP_NAME));
    return response;
};
export default appInfoPrompt;
