package com.ar.sketch.paint.drawing.act

import android.Manifest
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat

import com.ar.sketch.paint.drawing.databinding.ActivityUploadBinding
import com.ar.sketch.paint.drawing.tool.Http
import com.ar.sketch.paint.drawing.tool.Upload
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch


class UploadActivity : AppCompatActivity() {


    private lateinit var requestPermissionLauncher: ActivityResultLauncher<Array<String>>
    private val permissions = arrayOf(
        Manifest.permission.READ_PHONE_STATE,
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION
    )
    private lateinit var binding: ActivityUploadBinding

    @SuppressLint("SuspiciousIndentation")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityUploadBinding.inflate(layoutInflater)
        setContentView(binding.root)

//        requestPermissionLauncher =
//            registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->
//                val phoneGranted: Boolean = result[Manifest.permission.READ_PHONE_STATE] == true
//                val locationGranted: Boolean =
//                    result[Manifest.permission.ACCESS_FINE_LOCATION] == true
//                val coarseLocation: Boolean =
//                    result[Manifest.permission.ACCESS_COARSE_LOCATION] == true
//
//                Log.e("Permission", "1=${phoneGranted}  2= ${locationGranted} 3=$coarseLocation")
//                if (phoneGranted && locationGranted && coarseLocation) {
//                    Upload.getData(this)
//                }
//
//            }
//
//
//        if (ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.READ_PHONE_STATE
//            ) != PackageManager.PERMISSION_GRANTED
//            || ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.ACCESS_FINE_LOCATION
//            ) != PackageManager.PERMISSION_GRANTED
//        ) {
//
////            requestPermissionLauncher.launch(permissions)
//        } else {
//            Upload.getData(this)
//        }
        binding.btn.setOnClickListener {
            Http.makeGetRequest(this)
        }

    }
}