package com.base.superfilemanager.activity.splash

import android.app.Activity
import android.content.Intent
import com.blankj.utilcode.util.SPUtils
import com.base.superfilemanager.activity.GuestActivity
import com.base.superfilemanager.activity.AppManagerActivity
import com.base.superfilemanager.activity.BatteryInfoActivity
import com.base.superfilemanager.activity.LargeFileCleanActivity
import com.base.superfilemanager.activity.MainActivity
import com.base.superfilemanager.activity.NetWorkActivity
import com.base.superfilemanager.activity.RecentAppActivity
import com.base.superfilemanager.activity.RepeaterdPhotoActivity
import com.base.superfilemanager.activity.ScanJunkActivity
import com.base.superfilemanager.activity.SpeakerCleanerActivity
import com.base.superfilemanager.activity.photocompress.photo.StartCompressionPhotoActivity
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_APP_MANAGER
//import com.base.superfilemanager.bean.ConfigBean.Companion.ID_BATTERY_OPTIMIZATION
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_CHARGE
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_CLEAN_NOTIFICATION
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_CLEAN_SPEAKER
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_INSTALL_PACKAGE_PUSH
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_LARGE_FILE_PUSH
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_LOW_BATTERY_PUSH
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_NETWORK_TRAFFIC
//import com.base.superfilemanager.bean.ConfigBean.Companion.ID_PHONE_ACCELERATE
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.base.superfilemanager.bean.ConfigBean.Companion.ID_UNINSTALL_PACKAGE_PUSH
//import com.base.superfilemanager.bean.ConfigBean.Companion.ID_VIRUS_PUSH
import com.base.superfilemanager.helps.ConfigHelper
import com.base.superfilemanager.helps.EventHelper
import com.base.superfilemanager.notificationclean.NotificationCleanActivity
import com.base.superfilemanager.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_CLEAN_SPEAKER -> {
                context.startActivity(Intent(context, SpeakerCleanerActivity::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, GuestActivity::class.java))
                    } else {
                        context.startActivity(Intent(context, MainActivity::class.java))
                    }

                }
            }
        }
        context.finish()
    }
}