package com.base.filerecoveryrecyclebin.activity.splash

import android.app.Activity
import android.content.Intent
import android.util.Log
import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.appmanager.AppManagerAnimationActivity
import com.base.filerecoveryrecyclebin.activity.appprocess.AppProcessAnimationActivity
import com.base.filerecoveryrecyclebin.activity.battery.BatteryInfoAnimationActivity
import com.base.filerecoveryrecyclebin.activity.guide.GuideActivity
import com.base.filerecoveryrecyclebin.activity.junkclean.ScanJunkActivity
import com.base.filerecoveryrecyclebin.activity.photomanager.PhotoManagerAnimationActivity
import com.base.filerecoveryrecyclebin.activity.recovery.FileScanResultActivity
import com.base.filerecoveryrecyclebin.activity.whatsapp.WhatsAppCleanerAnimationActivity
import com.base.filerecoveryrecyclebin.bean.ConstObject
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_APP_MANAGER
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_APP_PROCESS
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_BATTERY_INFO
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_JUNK_CLEAN_PUSH
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_RECOVERY_DOCUMENTS
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_RECOVERY_PHOTOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_RECOVERY_VIDEOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_SCREENSHOT_CLEAN
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_SIMILAR_IMAGE
import com.base.filerecoveryrecyclebin.bean.ConstObject.ID_WHATSAPP
import com.base.filerecoveryrecyclebin.bean.ConstObject.isGuide

object StartUtils {

    private val TAG = "SplashJumpUtils"
    fun jumpNextPage(context: Activity) {

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

        Log.e(TAG, "actionId: $jumpType")

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

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

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

            ID_RECOVERY_PHOTOS -> {
                context.startActivity(Intent(context, FileScanResultActivity::class.java).putExtra("ScanType",ConstObject.SCAN_PHOTOS))
            }

            ID_RECOVERY_VIDEOS -> {
                context.startActivity(Intent(context, FileScanResultActivity::class.java).putExtra("ScanType",ConstObject.SCAN_VIDEOS))

            }

            ID_RECOVERY_DOCUMENTS -> {
                context.startActivity(Intent(context, FileScanResultActivity::class.java).putExtra("ScanType",ConstObject.SCAN_DOCUMENTS))
            }

            ID_WHATSAPP -> {
                context.startActivity(Intent(context, WhatsAppCleanerAnimationActivity::class.java))
            }
            ID_APP_PROCESS->{
                context.startActivity(Intent(context, AppProcessAnimationActivity::class.java))
            }
            ID_APP_MANAGER->{
                context.startActivity(Intent(context, AppManagerAnimationActivity::class.java))
            }
            ID_BATTERY_INFO -> {
                context.startActivity(Intent(context, BatteryInfoAnimationActivity::class.java))
            }


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

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

                }
            }
        }
        context.finish()
    }
}