package com.base.datarecovery.activity.splash

import android.app.Activity
import android.content.Intent
import android.util.Log
import com.base.datarecovery.activity.MainActivity
import com.base.datarecovery.activity.appmanager.AppManagerAnimationActivity
import com.base.datarecovery.activity.appprocess.AppProcessAnimationActivity
import com.base.datarecovery.activity.battery.BatteryInfoAnimationActivity
import com.base.datarecovery.activity.guide.GuideActivity
import com.base.datarecovery.activity.junkclean.ScanJunkActivity
import com.base.datarecovery.activity.photomanager.PhotoManagerAnimationActivity
import com.base.datarecovery.activity.recovery.FileScanResultActivity
import com.base.datarecovery.activity.whatsapp.WhatsAppCleanerAnimationActivity
import com.base.datarecovery.bean.ConstObject
import com.base.datarecovery.bean.ConstObject.ID_APP_MANAGER
import com.base.datarecovery.bean.ConstObject.ID_APP_PROCESS
import com.base.datarecovery.bean.ConstObject.ID_BATTERY_INFO
import com.base.datarecovery.bean.ConstObject.ID_JUNK_CLEAN_PUSH
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_DOCUMENTS
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_PHOTOS
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_VIDEOS
import com.base.datarecovery.bean.ConstObject.ID_SCREENSHOT_CLEAN
import com.base.datarecovery.bean.ConstObject.ID_SIMILAR_IMAGE
import com.base.datarecovery.bean.ConstObject.ID_WHATSAPP_CLEANER
import com.base.datarecovery.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_CLEANER -> {
                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()
    }
}