package com.base.datarecovery.activity

import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import androidx.activity.addCallback
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.base.datarecovery.R
import com.base.datarecovery.bean.ConstObject.fcmNotification
import com.base.datarecovery.bean.ConstObject.stayNotification
import com.base.datarecovery.databinding.ActivitySettingBinding
import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.service.StayNotificationService
import com.base.datarecovery.service.StayNotificationService.Companion.startStayNotification
import com.base.datarecovery.utils.BarUtils
import com.base.datarecovery.view.RateStarPop.showRateStarPopDialog

class SettingActivity : BaseActivity<ActivitySettingBinding>() {

    override val binding: ActivitySettingBinding by lazy {
        ActivitySettingBinding.inflate(layoutInflater)
    }

    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)

        binding.switchStayNotification.isChecked = stayNotification
        binding.switchFcmNotification.isChecked = fcmNotification
    }

    override fun initListener() {
        onBackPressedDispatcher.addCallback {
            finishToMain()
        }
        binding.flBack.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }

        binding.switchStayNotification.setOnCheckedChangeListener { buttonView, isChecked ->
            stayNotification = isChecked
            if (isChecked) {
                startStayNotification()
            } else {
                val serviceIntent = Intent(this, StayNotificationService::class.java)
                stopService(serviceIntent)
            }
        }
        binding.switchFcmNotification.setOnCheckedChangeListener { buttonView, isChecked ->
            fcmNotification = isChecked
            if (isChecked) {
//                subscribeToTopic(ConfigHelper.packageName)
            } else {
//                unsubscribeFromTopic(ConfigHelper.packageName)
            }
        }

        binding.llPrivacy.setOnClickListener {
            val intent = Intent(
                Intent.ACTION_VIEW,
                Uri.parse(ConfigHelper.privacyPolicy)
            )
            startActivity(intent)
        }

        binding.llScore.setOnClickListener {
            showRateStarPopDialog(mustShow = true)
        }

    }
}