package com.gh.gamecenter.feature.selector

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.updateStatusBarColor

import com.gh.gamecenter.common.R
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.core.utils.DisplayUtils

import kotlin.apply
import kotlin.jvm.java

/**
 * 选择本地视频/图片
 */
class LocalMediaActivity : BaseActivity() {

    override fun getLayoutId(): Int = R.layout.activity_video_tablayout_viewpager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateStatusBarColor(R.color.ui_surface_fixed_dark, R.color.ui_surface_fixed_dark)

        if (savedInstanceState == null) {
            val localMediaFragment = LocalMediaFragment().apply { arguments = intent.extras }
            supportFragmentManager.beginTransaction()
                .replace(R.id.container, localMediaFragment, LocalMediaFragment::class.java.name)
                .commitAllowingStateLoss()
        }

        DisplayUtils.transparentStatusAndNavigation(this)
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = false

    companion object {
        fun getIntent(
            context: Context,
            chooseType: ChooseType,
            maxChooseCount: Int = 1,
            entrance: String,
            imageType: Int = 0
        ): Intent {
            return Intent(context, LocalMediaActivity::class.java).apply {
                putExtra(EntranceConsts.KEY_TYPE, chooseType.value)
                putExtra(EntranceConsts.KEY_CHOOSE_MAX_COUNT, maxChooseCount)
                putExtra(
                    EntranceConsts.KEY_QUICK_CHOOSE,
                    if (chooseType == ChooseType.VIDEO) false else maxChooseCount == 1
                )
                putExtra(EntranceConsts.KEY_ENTRANCE, entrance)
                putExtra(EntranceConsts.KEY_IMAGE_TYPE, imageType)
            }
        }
    }
}

enum class ChooseType(val value: String) {
    VIDEO("video"),
    IMAGE("image")
}