package com.smart.sdkdemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
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.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.smart.analytics.sdk.SmartAnalytics
import com.smart.sdkdemo.ui.theme.SDKDemoTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            SDKDemoTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    var isShow by remember {
        mutableStateOf(!SmartAnalytics.isPrivacyAgree())
    }

    Column {
        Text(
            text = "Hello $name!",
            modifier = modifier
        )
        if (isShow) {
            Button(onClick = {
                // 同意隐私政策后调用zt初始化方法
                initSmartAnalytics()
                isShow = false
            }) {
                Text(text = "同意隐私政策")
            }
        }
    }

}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    SDKDemoTheme {
        Greeting("Android")
    }
}