package com.aiosman.ravenow.ui.index.tabs.add

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.LocalNavController
import com.aiosman.ravenow.ui.post.NewPostViewModel
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.composables.rememberDebouncedNavigation
import com.aiosman.ravenow.ui.composables.rememberDebouncedState
import com.aiosman.ravenow.ui.composables.rememberDebouncer

@Composable
fun AddPage(){
    val navController = LocalNavController.current
    val debouncer = rememberDebouncedNavigation()
    Column(modifier = Modifier
        .fillMaxSize()
        .background(Color.Black)) {
        AddBtn(icon = R.drawable.rider_pro_icon_rider_share, text = "Rave NowShare") {
                NewPostViewModel.asNewPost()
            debouncer {
                navController.navigate("NewPost")
            }
        }
//        AddBtn(icon = R.drawable.rider_pro_location_create, text = "Location Create")
    }
}

@Composable
fun AddBtn(@DrawableRes icon: Int, text: String,onClick: (() -> Unit)? = {}){
    val (isDebouncing, startDebounce, resetDebounce) = rememberDebouncedState()
    Row (modifier = Modifier
        .fillMaxWidth().padding(24.dp).clickable {
            if (!isDebouncing) {
                startDebounce()
                onClick?.invoke()
            }
        },
        verticalAlignment = Alignment.CenterVertically){
        Image(
            modifier = Modifier.size(40.dp),
            painter = painterResource(id = icon), contentDescription = null)
        Text(modifier = Modifier.padding(start = 24.dp),text = text, color = Color.White,fontSize = 22.sp, style = TextStyle(fontWeight = FontWeight.Bold))
    }
}
