package de.sebse.fuplanner2

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import de.sebse.fuplanner2.ui.courses.CoursesScreen
import de.sebse.fuplanner2.ui.details.CourseDetailsScreen
import de.sebse.fuplanner2.ui.details_announcements.CourseAnnouncementScreen
import de.sebse.fuplanner2.ui.details_announcements.CourseAnnouncementsScreen
import de.sebse.fuplanner2.ui.details_description.CourseDescriptionScreen

sealed class MenuItem {
    object Courses : NavLinks(R.string.menu_courses, R.drawable.ic_menu_courses, "courses")
    object Canteen : NavLinks(R.string.menu_canteen, R.drawable.ic_menu_canteen, "canteen")
    object Schedule : NavLinks(R.string.menu_schedule, R.drawable.ic_menu_event, "schedule")
    object Notifications :
        NavLinks(R.string.menu_notifications, R.drawable.ic_menu_notifications, "navigation")
}

val screens = listOf(
    MenuItem.Courses,
    MenuItem.Canteen,
    MenuItem.Schedule,
    MenuItem.Notifications
)

@Composable
fun MainActivityComposable() {
    DrawerLayout(
        appName = stringResource(R.string.app_name),
        menu = screens,
        startDestination = MenuItem.Courses.route
    ) { tools ->
        composable(route = MenuItem.Courses.route) {
            CoursesScreen(tools)
        }
        composable(
            arguments = listOf(
                navArgument("id") { type = NavType.LongType }
            ),
            route = "${MenuItem.Courses.route}/{id}"
        ) {
            val id = it.arguments!!.getLong("id")
            CourseDetailsScreen(tools, id)
        }
        composable(
            arguments = listOf(
                navArgument("id") { type = NavType.LongType }
            ),
            route = "${MenuItem.Courses.route}/{id}/description"
        ) {
            val id = it.arguments!!.getLong("id")
            CourseDescriptionScreen(tools, id)
        }
        composable(
            arguments = listOf(
                navArgument("id") { type = NavType.LongType }
            ),
            route = "${MenuItem.Courses.route}/{id}/announcements"
        ) {
            val id = it.arguments!!.getLong("id")
            CourseAnnouncementsScreen(tools, id)
        }
        composable(
            arguments = listOf(
                navArgument("id") { type = NavType.LongType },
                navArgument("announceId") { type = NavType.LongType }
            ),
            route = "${MenuItem.Courses.route}/{id}/announcements/{announceId}"
        ) {
            val id = it.arguments!!.getLong("id")
            val announceId = it.arguments!!.getLong("announceId")
            CourseAnnouncementScreen(tools, id, announceId)
        }
    }
}
