"""SLAM Toolbox integrated launch for SaltyBot"""

import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    slam_share = get_package_share_directory('slam_toolbox')
    nav2_slam_dir = get_package_share_directory('saltybot_nav2_slam')

    slam_params = LaunchConfiguration('slam_params_file')
    use_sim_time = LaunchConfiguration('use_sim_time')

    return LaunchDescription([
        DeclareLaunchArgument(
            'slam_params_file',
            default_value=os.path.join(nav2_slam_dir, 'config', 'slam_toolbox_params.yaml'),
        ),

        DeclareLaunchArgument('use_sim_time', default_value='false'),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(slam_share, 'launch', 'online_async_launch.py')
            ),
            launch_arguments={
                'params_file': slam_params,
                'use_sim_time': use_sim_time,
            }.items(),
        ),
    ])
