# bash_confirm
# ------------
# Dialogo de confirmacion y/n con valor por defecto.
#
# USO (sourced):
#   source bash_confirm.sh
#   bash_confirm "Continuar?" && echo "Si" || echo "No"
#   bash_confirm "Eliminar?" "y"  # default yes

SCRIPT_DIR_BASH_CONFIRM="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR_BASH_CONFIRM/bash_colors.sh"
bash_colors

bash_confirm() {
    local prompt="${1:-¿Continuar?}"
    local default="${2:-n}"

    if [ "$default" = "y" ]; then
        prompt="$prompt [Y/n]"
    else
        prompt="$prompt [y/N]"
    fi

    echo -ne "${YELLOW}$prompt ${NC}"
    read -r response

    response=${response:-$default}
    case "$response" in
        [yY][eE][sS]|[yY]|[sS][iI])
            return 0
            ;;
        *)
            return 1
            ;;
    esac
}
