package com.test.basd.smartjunkcleaner.activity.splash

import android.app.Activity
import android.content.Intent
import com.blankj.utilcode.util.SPUtils
import com.test.basd.smartjunkcleaner.activity.AppManagerActivity
import com.test.basd.smartjunkcleaner.activity.BatteryInfoActivity
import com.test.basd.smartjunkcleaner.activity.CleanGuestActivity
import com.test.basd.smartjunkcleaner.activity.LargeFileCleanActivity
import com.test.basd.smartjunkcleaner.activity.MainActivity
import com.test.basd.smartjunkcleaner.activity.NetWorkActivity
import com.test.basd.smartjunkcleaner.activity.RecentAppActivity
import com.test.basd.smartjunkcleaner.activity.RepeaterdPhotoActivity
import com.test.basd.smartjunkcleaner.activity.ScanJunkActivity
import com.test.basd.smartjunkcleaner.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_APP_MANAGER
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_CHARGE
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_CLEAN_NOTIFICATION
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_INSTALL_PACKAGE_PUSH
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_LARGE_FILE_PUSH
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_LOW_BATTERY_PUSH
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_NETWORK_TRAFFIC
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.test.basd.smartjunkcleaner.bean.ConfigBean.Companion.ID_UNINSTALL_PACKAGE_PUSH
import com.test.basd.smartjunkcleaner.helps.ConfigHelper
import com.test.basd.smartjunkcleaner.helps.EventHelper
import com.test.basd.smartjunkcleaner.notificationclean.NotificationCleanActivity
import com.test.basd.smartjunkcleaner.notificationclean.NotificationGuestActivity

object SplashJumpUtils {

    fun jumpNextPage(context: Activity) {

        var jumpType = context.intent.getIntExtra("type", 0)

        if (jumpType == 0) {
            val uri = context.intent.data
            val str = (uri?.getQueryParameter("type") ?: "0")
            jumpType = str.toIntOrNull() ?: 0
            if (jumpType != 0) {
                EventHelper.event("notification_jump", "jumpType=$jumpType")
            }
        }
        when (jumpType) {
//=================================主动广播=======================================
            ID_JUNK_CLEAN_PUSH -> {
                context.startActivity(Intent(context, ScanJunkActivity::class.java))
            }

//            ID_VIRUS_PUSH -> {
            //   context.startActivity(Intent(context, VirusActivity::class.java))
//            }

            ID_LARGE_FILE_PUSH -> {
                context.startActivity(Intent(context, LargeFileCleanActivity::class.java))
            }

            ID_PHOTO_COMPRESS -> {
                context.startActivity(Intent(context, StartCompressionPhotoActivity::class.java))
            }

            ID_APP_MANAGER -> {
                context.startActivity(Intent(context, AppManagerActivity::class.java))
            }

            ID_NETWORK_TRAFFIC -> {
                context.startActivity(Intent(context, NetWorkActivity::class.java))
            }

            ID_CLEAN_NOTIFICATION -> {
                if (SPUtils.getInstance().getBoolean("notification_guest", false)) {
                    context.startActivity(Intent(context, NotificationCleanActivity::class.java))
                } else {
                    context.startActivity(Intent(context, NotificationGuestActivity::class.java))
                }
            }

            ID_RECENT_USE_APP -> {
                context.startActivity(Intent(context, RecentAppActivity::class.java))
            }

            ID_SIMILAR_IMAGE -> {
                context.startActivity(Intent(context, RepeaterdPhotoActivity::class.java))
            }



//            ID_BATTERY_OPTIMIZATION -> {
//                context.startActivity(Intent(context, BatteryOptimizerActivity::class.java))
//            }

//================================被动广播=========================================

            ID_INSTALL_PACKAGE_PUSH -> {
                context.startActivity(Intent(context, ScanJunkActivity::class.java))
            }

            ID_UNINSTALL_PACKAGE_PUSH -> {
                context.startActivity(Intent(context, ScanJunkActivity::class.java))
            }

            ID_CHARGE -> {
                context.startActivity(Intent(context, BatteryInfoActivity::class.java))
            }

            ID_LOW_BATTERY_PUSH -> {
                context.startActivity(Intent(context, BatteryInfoActivity::class.java))
            }

//            ID_PHONE_ACCELERATE -> {
//                context.startActivity(Intent(context, SpeedActivity::class.java))
//            }

            else -> {
                val isHotLaunch = context.intent?.extras?.getBoolean("isHotLaunch", false) ?: false
                if (!isHotLaunch) {
                    if (!ConfigHelper.ifGuest) {
                        context.startActivity(Intent(context, CleanGuestActivity::class.java))
                    } else {
                        context.startActivity(Intent(context, MainActivity::class.java))
                    }

                }
            }
        }
        context.finish()
    }
}