package com.base.easyfilemanager.activity.splash

import android.app.Activity
import android.content.Intent
import com.base.easyfilemanager.activity.AppManagerActivity
import com.base.easyfilemanager.activity.CleanGuestActivity
import com.base.easyfilemanager.activity.DeviceScanActivity
import com.base.easyfilemanager.activity.LargeFileCleanActivity
import com.base.easyfilemanager.activity.NetWorkActivity
import com.base.easyfilemanager.activity.RecentAppActivity
import com.base.easyfilemanager.activity.RepeatPhotoActivity
import com.base.easyfilemanager.activity.ScanJunkActivity
import com.base.easyfilemanager.activity.ScreenShotActivity
import com.base.easyfilemanager.activity.home.NewMainActivity
import com.base.easyfilemanager.activity.photocompress.photo.StartCompressionPhotoActivity
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_APP_MANAGER
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_CLEAN_NOTIFICATION
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_LARGE_FILE_PUSH
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_NETWORK_TRAFFIC
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_SCREENSHOT_CLEAN
import com.base.easyfilemanager.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.base.easyfilemanager.helps.ConfigHelper
import com.base.easyfilemanager.helps.EventHelper
import com.base.easyfilemanager.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, RepeatPhotoActivity::class.java))
            }

            ID_SCREENSHOT_CLEAN -> {
                context.startActivity(Intent(context, ScreenShotActivity::class.java))
            }

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

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

                }
            }
        }
        context.finish()
    }
}