package com.aiosman.riderpro.ui.index.tabs.profile.composable

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.riderpro.R
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun UserContentPageIndicator(
    pagerState: PagerState
){
    val scope = rememberCoroutineScope()
    Row(
        modifier = Modifier
            .verticalScroll(rememberScrollState())
            .fillMaxWidth()
            .padding(horizontal = 16.dp),
    ) {
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier
                .clip(RoundedCornerShape(32.dp))
                .background(if (pagerState.currentPage == 0) Color(0xFFFFFFFF) else Color.Transparent)
                .padding(horizontal = 16.dp, vertical = 4.dp)
                .noRippleClickable {
                    // switch to gallery
                    scope.launch {
                        pagerState.scrollToPage(0)
                    }
                }
        ) {
            Text(
                text = stringResource(R.string.gallery),
                fontSize = 14.sp,
                fontWeight = FontWeight.W600,
                color = Color.Black,
                modifier = Modifier.padding(8.dp)
            )
        }
        Spacer(modifier = Modifier.width(4.dp))
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier
                .clip(RoundedCornerShape(32.dp))
                .background(if (pagerState.currentPage == 1) Color(0xFFFFFFFF) else Color.Transparent)
                .padding(horizontal = 16.dp, vertical = 4.dp)
                .noRippleClickable {
                    // switch to moments
                    scope.launch {
                        pagerState.scrollToPage(1)
                    }
                }
        ) {
            Text(
                text = stringResource(R.string.moment),
                fontSize = 14.sp,
                fontWeight = FontWeight.W600,
                color = Color.Black,
                modifier = Modifier.padding(8.dp)
            )
        }
    }
}