package com.example.iplace.main.viewModel.mainView

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.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.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

@Composable
fun UserSettings(navController: NavHostController) {
    val viewModel = MainViewModel()
    val headlinesOswald = FontFamily( //выбор шрифта
        Font(resId = R.font.headlines_oswald)
    )
    val basicNunitosans = FontFamily(
        Font(resId = R.font.basic_nunitosans)
    )

    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White)
    ) {
        Spacer(modifier = Modifier.height(20.dp))
        // Верхний блок (2/5 размера экрана)
        Box(
            modifier = Modifier
                .weight(2f)
                .background(Color.LightGray)
                .padding(16.dp),
            contentAlignment = Alignment.TopCenter
        ) {

            // Кнопки назад и настроек
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceBetween,
                verticalAlignment = Alignment.CenterVertically
            ) {
                IconButton(onClick = { navController.navigate("MenuV") }) {
                    Icon(Icons.Filled.ArrowBack, contentDescription = "Назад")
                }
            }
            Spacer(modifier = Modifier.height(60.dp))

            // Заголовок "Профиль"
            Text(
                text = "Настройки профиля",
                fontWeight = FontWeight.Bold,
                modifier = Modifier
                    .padding(top = 32.dp)
                    .fillMaxWidth(),
                textAlign = TextAlign.Center
            )

            // Блок с фотографией, именем и гендером
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(top = 64.dp),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                // Фотография (заглушка)
                Box(
                    modifier = Modifier
                        .size(120.dp)
                        .clip(CircleShape)
                        .background(Color.Gray)
                )

                // Имя и гендер
                Row(
                    modifier = Modifier
                        .padding(top = 16.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = "Имя пользователя")
                    Spacer(modifier = Modifier.width(8.dp))
                    // Символ гендера (заглушка)
                    Text(text = "♂")
                }
                Button(onClick = {  }) {
                    Text("Выбрать фото")
                }
            }
        }

        // Остальной контент (3/5 размера экрана)
        Box(
            modifier = Modifier
                .weight(3f)
                .fillMaxSize()
                .background(Color.White)
        ) {
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(top = 64.dp),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                OutlinedTextField(
                    value = "",
                    onValueChange = {},
                    label = { Text("Изменить имя") },
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(horizontal = 16.dp)
                        .clip(RoundedCornerShape(20.dp))
                )
                Spacer(modifier = Modifier.height(10.dp))

                OutlinedTextField(
                    value = "",
                    onValueChange = {},
                    label = { Text("Изменить адрес") },
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(horizontal = 16.dp)
                        .clip(RoundedCornerShape(20.dp))
                )
                Spacer(modifier = Modifier.height(10.dp))

                OutlinedTextField(
                    value = "",
                    onValueChange = {},
                    label = { Text("Изменить телефон") },
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(horizontal = 16.dp)
                        .clip(RoundedCornerShape(20.dp))
                )
                Spacer(modifier = Modifier.height(10.dp))

                OutlinedTextField(
                    value = "",
                    onValueChange = {},
                    label = { Text("Изменить информацию о себе") },
                    modifier = Modifier
                        .fillMaxWidth()
                        .height(45.dp)
                        .padding(horizontal = 16.dp)
                        .clip(RoundedCornerShape(20.dp))
                )
                Spacer(modifier = Modifier.height(15.dp))
                Button(
                    onClick = { navController.navigate("profile") },
                    modifier = Modifier.width(290.dp).height(50.dp),
                    colors = ButtonDefaults.buttonColors(brown_contrast)
                ) {
                    Text(
                        text = "Сохранить",
                        fontSize = 24.sp,
                        fontFamily = basicNunitosans
                    )
                }
                Spacer(modifier = Modifier.height(10.dp))
                Button(
                    onClick = { navController.navigate("passwordVerification") },
                    modifier = Modifier.width(290.dp).height(50.dp),
                    colors = ButtonDefaults.buttonColors(brown_contrast)
                ) {
                    Text(
                        text = "Изменить пароль",
                        fontSize = 24.sp,
                        fontFamily = basicNunitosans
                    )
                }

            }
        }
    }
}