{"size": 1926, "ext": "js", "max_stars_repo_path": "helpers/inquirer.js", "max_stars_repo_name": "Edwinroman30/WeatherApp", "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T19:35:24.000Z", "max_issues_repo_path": "helpers/inquirer.js", "max_issues_repo_name": "Edwinroman30/WeatherApp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "helpers/inquirer.js", "max_forks_repo_name": "Edwinroman30/WeatherApp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.8556701031, "max_line_length": 64, "alphanum_fraction": 0.466251298}
const inquirer = require('inquirer');
/* require('colors'); */

const questions = {
    type: 'list',
    name: 'options',
    message: '¿Qué desea hacer?',
    choices: [
        {
            value: 1,
            name: `${'(1)'} Busca una ciudad.`
        },
        {
            value: 2,
            name: `${'(2)'} Historial de busqueda.`
        },
        {
            value: 0,
            name: `${'(0)'} Cerrar la app.\n`
        }
    ],
    loop: false
};


const menuInquirer = async () =>{

    console.log(`============================================`);
    console.log(`                 WEATHER APP                `);
    console.log(`============================================`);

    const {options} = await inquirer.prompt(questions);

    return options;
}

const pausaInquirer = async () =>{

    const resp = await inquirer.prompt({
        type: 'input',
        name: 'Enter',
        message: `Precione ${'ENTER'} para continuar.`
    });

    return resp;
}

const questioning = async (message) =>{

    const questionStructure = {
        type: 'input',
        name: 'answare',
        message,
        validate(input){

            if(input.length === 0){
                return 'Error: Debe de digital un valor...';
            }
            else{
                return true
            }
        }

    }

    return await inquirer.prompt(questionStructure);
}

const listingItems = async ( arrPlaces = [] ) =>{

    const choices = arrPlaces.map( (place) => {
        return { value: place.id, name: place.placeName } 
    });
    
    choices.push( {value: 0, name: 'Cancel.'} );

    const options = {
        type: 'list',
        name: 'id',
        message: 'Choose the right places:',
        choices: choices,
        loop: false
    }

    return  await inquirer.prompt(options);

}




module.exports = {
    menuInquirer,
    pausaInquirer,
    questioning,
    listingItems
};