package dev.ulfrx.recipe.ui.screens.planner

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.ulfrx.recipe.navigation.DockDestination
import dev.ulfrx.recipe.ui.components.empty.EmptyState
import dev.ulfrx.recipe.ui.components.overlay.BottomOverlayScaffold
import dev.ulfrx.recipe.ui.screens.shell.rememberShellChromeHeight
import dev.ulfrx.recipe.ui.theme.RecipeTheme
import org.jetbrains.compose.resources.stringResource
import recipe.composeapp.generated.resources.Res
import recipe.composeapp.generated.resources.empty_planner_subtitle
import recipe.composeapp.generated.resources.empty_planner_title
import recipe.composeapp.generated.resources.shell_tab_planner

@Composable
fun PlannerScreen(viewModel: PlannerViewModel) {
    val state by viewModel.state.collectAsStateWithLifecycle()

    BottomOverlayScaffold(
        open = state.isCalendarOpen,
        onDismiss = viewModel::closeCalendar,
        bottomInset = rememberShellChromeHeight(),
        overlay = {
            PlannerCalendarPill(
                selectedDate = state.selectedDate,
                expanded = state.isCalendarOpen,
                onExpandedChange = viewModel::setCalendarOpen,
                onSelectDate = viewModel::selectDate,
                onShiftSelection = viewModel::shiftSelection,
            )
        },
    ) {
        Column(
            modifier =
                Modifier
                    .fillMaxSize()
                    .windowInsetsPadding(WindowInsets.statusBars)
                    .padding(top = RecipeTheme.spacing.xl),
            verticalArrangement = Arrangement.Top,
        ) {
            BasicText(
                text = stringResource(Res.string.shell_tab_planner),
                style = RecipeTheme.typography.title.copy(color = RecipeTheme.colors.content),
                modifier = Modifier.padding(horizontal = RecipeTheme.spacing.lg),
            )
            Box(modifier = Modifier.fillMaxSize()) {
                EmptyState(
                    icon = DockDestination.Planner.icon,
                    title = stringResource(Res.string.empty_planner_title),
                    subtitle = stringResource(Res.string.empty_planner_subtitle),
                )
            }
        }
    }
}
