package com.zaojiao.app.feat.home.plan

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import kotlinx.coroutines.launch

@Composable
internal fun HomePlanRoute() {
    HomePlanPage()
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HomePlanPage() {
    val tabTitles = listOf("学习计划", "全部课程")
    val pageState = rememberPagerState()
    val coroutineScope = rememberCoroutineScope()

    Column(
        modifier = Modifier
            .statusBarsPadding()
            .fillMaxSize()
    ) {
        TabRow(selectedTabIndex = pageState.currentPage) {
            tabTitles.forEachIndexed { index, title ->
                Tab(selected = pageState.currentPage == index,
                    onClick = {
                        coroutineScope.launch {
                            pageState.scrollToPage(index)

                        }
                    }) {
                    Text(text = title)
                }
            }
        }

        HorizontalPager(
            state = pageState,
            pageCount = 2,
            userScrollEnabled = true,
        ) {
            when (it) {
                0 -> HomePlanIndexPage()
                1 -> HomePlanTotalPage()
                else -> TODO()
            }
        }
    }
}