package com.img.rabbit.pages.screen.mine.setting

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
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.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.img.rabbit.R
import com.img.rabbit.config.Constants.agreementUrl
import com.img.rabbit.config.Constants.privacyUrl
import com.img.rabbit.pages.toolbar.TitleBar
import com.img.rabbit.utils.UrlLinkUtils.openAgreement

@Composable
fun AboutScreen(navController: NavHostController) {
    Scaffold{
        val context = LocalContext.current
        Column(
            modifier = Modifier.fillMaxSize()
        ) {
            TitleBar(navController = navController, paddingValues = it, title = "关于我们")

            Box(
                modifier = Modifier.fillMaxSize().padding(start = 17.dp, end = 17.dp)
            ){
                //TODO 设置内容
                Column(
                    modifier = Modifier
                        .fillMaxSize()
                        .padding(top = 100.dp)
                ){
                    Image(
                        painter = painterResource(id = R.mipmap.ic_launcher_logo),
                        contentDescription = "关于我们",
                        modifier = Modifier
                            .width(100.dp)
                            .aspectRatio(1f)
                            .align(Alignment.CenterHorizontally)
                    )



                    Text(
                        text = "截图兔",
                        fontSize = 18.sp,
                        fontWeight = FontWeight.Bold,
                        color = Color(0xFF1A1A1A),
                        modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 24.dp)
                    )


                    Column(
                        modifier = Modifier
                            .wrapContentSize()
                            .padding(top = 24.dp)
                            .background(
                                Color(0xFFFFFFFF),
                                RoundedCornerShape(18.dp)
                            )
                            .shadow(
                                elevation = 4.dp,
                                shape = RoundedCornerShape(8.dp),
                                ambientColor = Color(0x4DE5E5E5),
                                spotColor = Color(0x4DE5E5E5)
                            )
                    ){
                        Row(
                            modifier = Modifier
                                .fillMaxWidth()
                                .height(52.dp)
                                .clickable(
                                    indication = null,
                                    interactionSource = remember { MutableInteractionSource() }
                                ) {
                                    // 跳转用户协议页面
                                    openAgreement(context = context, title = "用户协议", url = agreementUrl)
                                },
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Box(
                                modifier = Modifier.weight(1f)
                            ){
                                Text(
                                    text = "用户协议",
                                    fontSize = 16.sp,
                                    fontWeight = FontWeight.Bold,
                                    color = Color(0xFF1A1A1A),
                                    modifier = Modifier
                                        .wrapContentSize()
                                        .padding(start = 8.dp)
                                )
                            }

                            Image(
                                painter = painterResource(id = R.mipmap.ic_arrow_right),
                                contentDescription = null,
                                contentScale = ContentScale.FillWidth,
                                modifier = Modifier
                                    .wrapContentSize()
                                    .padding(end = 12.dp)
                                    .align(Alignment.CenterVertically)
                            )
                        }
                        Box(
                            modifier = Modifier.fillMaxWidth().height(0.5.dp).padding(horizontal = 12.dp).background(
                                Color(0x4DBBBBBB)
                            )
                        )

                        Row(
                            modifier = Modifier
                                .fillMaxWidth()
                                .height(52.dp)
                                .clickable(
                                    indication = null,
                                    interactionSource = remember { MutableInteractionSource() }
                                ) {
                                    // 跳转隐私政策页面
                                    openAgreement(context = context, title = "隐私政策", url = privacyUrl)
                                },
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Box(
                                modifier = Modifier.weight(1f)
                            ){
                                Text(
                                    text = "隐私政策",
                                    fontSize = 16.sp,
                                    fontWeight = FontWeight.Bold,
                                    color = Color(0xFF1A1A1A),
                                    modifier = Modifier
                                        .wrapContentSize()
                                        .padding(start = 8.dp)
                                )
                            }

                            Image(
                                painter = painterResource(id = R.mipmap.ic_arrow_right),
                                contentDescription = null,
                                contentScale = ContentScale.FillWidth,
                                modifier = Modifier
                                    .wrapContentSize()
                                    .padding(end = 12.dp)
                                    .align(Alignment.CenterVertically)
                            )
                        }
                    }
                }
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
private fun PreviewAboutScreen(){
    AboutScreen(navController = rememberNavController())
}