package com.example.iplace.main.viewModel.dataView

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.example.iplace.R
import com.example.iplace.main.viewModel.MainViewModel
import com.example.iplace.ui.theme.brown_contrast

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FavouritesV(navController: NavHostController) {
    val viewModel = MainViewModel()
    var showDrawer by remember { mutableStateOf(false) }
    val headlinesOswald = FontFamily( //выбор шрифта
        Font(resId = R.font.headlines_oswald)
    )
    val basicNunitosans = FontFamily(
        Font(resId = R.font.basic_nunitosans)
    )
    Scaffold(
        topBar = {
            TopAppBar(
                title = {
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.SpaceBetween,
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        IconButton(onClick = { showDrawer = true }) {
                            Icon(Icons.Filled.Menu, contentDescription = "Меню")
                        }
                        // Заглушка для поиска
                        Text(text = "Поиск", modifier = Modifier.weight(1f))
                        IconButton(onClick = { navController.navigate("profile") }) {
                            Icon(Icons.Filled.Person, contentDescription = "Профиль")
                        }
                    }
                }
//                ,backgroundColor = Color.White,
//                elevation = 0.dp
            )
        }
//        ,
//        drawerContent = {
//            DrawerContent(showDrawer, navController)
//        },
//        drawerGesturesEnabled = showDrawer
    ) { innerPadding ->
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(innerPadding)
        ) {
            // Кнопка "Фильтр" с выпадающим списком (заглушка)
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(16.dp),
                verticalAlignment = Alignment.CenterVertically
            ) {
                Button(onClick = { /* Обработка нажатия на фильтр */ }) {
                    Text("Фильтр")
                }
                // Выпадающий список (заглушка)
                Spacer(modifier = Modifier.width(8.dp))
                // ...

            }
            Text(
                text = "Избранное",
                fontWeight = FontWeight.Bold,
                modifier = Modifier
                    .fillMaxWidth(),
                textAlign = TextAlign.Center
            )

            // 4 блока данных
            LazyColumn {
                items(listOf(1, 2, 3, 4)) { item ->
                    Box(
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(230.dp)
                            .padding(16.dp)
                            .background(Color.LightGray)
                    ) {
                        Column(
                            modifier = Modifier
                                .align(Alignment.BottomStart) // Выравниваем Column по левому нижнему углу
                        ) {
                            Text(text = "Название $item", modifier = Modifier)
                            Text(text = "Категория $item", modifier = Modifier)
                        }

                        Button(
                            onClick = { /* Обработка нажатия на фильтр */ },
                            modifier = Modifier
                                .align(Alignment.TopEnd) // Выравниваем Button по правому верхнему углу
                                .width(40.dp)
                                .height(40.dp),
                            colors = ButtonDefaults.buttonColors(brown_contrast)
                        ) {
                            Text(text = "☆")
                        }
                    }
                }
            }
        }
    }
}


