package com.example.myapplication.components.funs

import ButtonNice
import TextNice
import android.graphics.Bitmap
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
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.foundation.lazy.LazyColumn
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
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.graphics.asImageBitmap
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.myapplication.R
import myColor1
import myColor3
import myColor4

@Composable
fun createProductCard(name: String, price: Double, img: Bitmap, onClickAction: () -> Unit, onClickAction2: () -> Unit){
    Column () {
        Row {
            Image(
                bitmap = img.asImageBitmap(),
                contentDescription = null,
                modifier = Modifier.size(150.dp)
            )

            Column (modifier = Modifier.padding(start = 15.dp, end = 15.dp)){
                Text(name, fontSize = 24.sp, color = Color.Black)
                Text(price.toString() + " ₽", fontSize = 16.sp, color = Color.Black)
                ButtonNice("Инфо: " , Color.White, onClickAction)
            }
        }
        ButtonNice("Добавить в корзину" , myColor1, onClickAction2)
    }
}
@Composable
fun ProductCardInCart(name: String, price: Double, img: Bitmap, onClickAction: () -> Unit) {
    Column(modifier = Modifier.padding(top = 20.dp, start = 10.dp, end = 10.dp)) {
        Row {
            Image(
                bitmap = img.asImageBitmap(),
                contentDescription = null,
                modifier = Modifier.size(150.dp)
            )
            Column(modifier = Modifier.padding(start = 15.dp, end = 15.dp)) {
                Text(text = name, fontSize = 24.sp, color = Color.Black)
                Text(text = price.toString() + " ₽", fontSize = 16.sp, color = Color.Black)

                Button(
                    onClick = onClickAction,
                    colors = ButtonDefaults.buttonColors(
                        containerColor = Color.Transparent,
                        contentColor = myColor3
                    ),
                    contentPadding = PaddingValues(0.dp),
                    modifier = Modifier.size(50.dp).padding(top = 10.dp)

                ) {
                    Image(
                        painter = painterResource(id = R.drawable.delete),
                        contentDescription = null,
                        modifier = Modifier.size(50.dp)
                    )
                }
            }
        }
    }

    @Composable
    fun createProductPage(
        name: String,
        info: String,
        price: Int,
        @DrawableRes imgId: Int,
        onClickAction: () -> Unit
    ) {
        LazyColumn(modifier = Modifier.fillMaxSize().padding(10.dp)) {

            item {
                Box(
                    modifier = Modifier.padding(bottom = 10.dp).fillMaxWidth(),
                    contentAlignment = Alignment.Center
                ) {
                    TextNice(name)
                }
            }

            item {
                Image(
                    painter = painterResource(id = imgId),
                    contentDescription = null,
                    modifier = Modifier
                        .size(400.dp)
                        .aspectRatio(1f)
                )
            }

            item { TextNice("Характеристики: ") }
            item { Text(info) }
            item { ButtonNice("Добавить в корзину", myColor4, onClickAction) }
        }
    }
}