package com.test.basd.supercleanermax.activity.splash

import android.app.Activity
import android.content.Intent
import com.test.basd.supercleanermax.activity.GuestActivity
import com.test.basd.supercleanermax.activity.AppManagerActivity
import com.test.basd.supercleanermax.activity.BatteryInfoActivity
import com.test.basd.supercleanermax.activity.LargeFileCleanActivity
import com.test.basd.supercleanermax.activity.MainActivity
import com.test.basd.supercleanermax.activity.NetWorkActivity
import com.test.basd.supercleanermax.activity.RecentAppActivity
import com.test.basd.supercleanermax.activity.RepeaterdPhotoActivity
import com.test.basd.supercleanermax.activity.ScanJunkActivity
import com.test.basd.supercleanermax.activity.SpeakerCleaningActivity
import com.test.basd.supercleanermax.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_APP_MANAGER
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_CHARGE
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_CLEAN_NOTIFICATION
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_CLEAN_SPEAKER
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_INSTALL_PACKAGE_PUSH
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_LARGE_FILE_PUSH
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_LOW_BATTERY_PUSH
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_NETWORK_TRAFFIC
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.test.basd.supercleanermax.bean.ConfigBean.Companion.ID_UNINSTALL_PACKAGE_PUSH
import com.test.basd.supercleanermax.helps.ConfigHelper
import com.test.basd.supercleanermax.helps.EventHelper
import com.test.basd.supercleanermax.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_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 -> {
                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, SpeakerCleaningActivity::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))
            }

            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()
    }
}