package com.test.basd.onecleanmaster.activity.splash

import android.app.Activity
import android.content.Intent
import com.blankj.utilcode.util.SPUtils
import com.test.basd.onecleanmaster.activity.AppManagerActivity
import com.test.basd.onecleanmaster.activity.BatteryInfoActivity
import com.test.basd.onecleanmaster.activity.LargeFileCleanActivity
import com.test.basd.onecleanmaster.activity.MainActivity
import com.test.basd.onecleanmaster.activity.NetWorkActivity
import com.test.basd.onecleanmaster.activity.RecentAppActivity
import com.test.basd.onecleanmaster.activity.RepeatedPhotoActivity
import com.test.basd.onecleanmaster.activity.ScanJunkActivity
import com.test.basd.onecleanmaster.activity.SpeakerCleanerActivity
//import com.test.basd.quickclean.activity.VirusActivity
import com.test.basd.onecleanmaster.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_APP_MANAGER
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_BATTERY_OPTIMIZATION
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_CHARGE
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_CLEAN_NOTIFICATION
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_CLEAN_SPEAKER
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_INSTALL_PACKAGE_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_LARGE_FILE_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_LOW_BATTERY_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_NETWORK_TRAFFIC
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_PHONE_ACCELERATE
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_UNINSTALL_PACKAGE_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_VIRUS_PUSH
import com.test.basd.onecleanmaster.display.CloseNotificationReceiver
import com.test.basd.onecleanmaster.helps.ConfigHelper
import com.test.basd.onecleanmaster.helps.LogEx
import com.test.basd.onecleanmaster.notificationclean.NotificationCleanActivity
import com.test.basd.onecleanmaster.notificationclean.NotificationGuestActivity

object SplashJumpUtils {

    private val TAG = "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
        }
        LogEx.logDebug(TAG, "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, RepeatedPhotoActivity::class.java))
            }

            ID_CLEAN_SPEAKER -> {
                context.startActivity(Intent(context, SpeakerCleanerActivity::class.java))
            }

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

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

            ID_INSTALL_PACKAGE_PUSH -> {
//                context.startActivity(Intent(context, VirusActivity::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 -> {
//                startActivity<SpeedActivity>()
            }

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

                }
            }
        }
        context.finish()
    }
}