package com.adealink.weparty.commonui.mediapicker.imageselect.takePhoto

import android.annotation.SuppressLint
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.weparty.commonui.BaseActivity
import com.adealink.weparty.databinding.ActivityCameraBinding
import com.adealink.weparty.util.QMUIStatusBarHelper

/**
 * Created By: duxuefu
 * Creation Date: 2025/3/28 15:21
 * Description: 目前仅支持录制视频，拍照还是使用系统Intent(MediaStore.ACTION_IMAGE_CAPTURE)
 *
 * 1.放弃使用 Intent(MediaStore.ACTION_VIDEO_CAPTURE) ：因设置最大录制时长的方法
 * intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10) 在一些机型上不奏效；
 */
class CameraActivity : BaseActivity() {

    private val binding by viewBinding(ActivityCameraBinding::inflate)

    private var limitedDuration: Int = CameraConst.DEF_VIDEO_LIMITED_DURATION // 录制时长限制，单位：秒

    override fun onBeforeCreate() {
        super.onBeforeCreate()
        limitedDuration =
            intent.getIntExtra(EXTRA_LIMITED_DURATION, CameraConst.DEF_VIDEO_LIMITED_DURATION)
    }

    override fun initViews() {
        super.initViews()
        QMUIStatusBarHelper.setStatusBarLightMode(this)
        setContentView(binding.root)
        inflateRecordVideoFragment()
    }

    @SuppressLint("CommitTransaction")
    private fun inflateRecordVideoFragment() {
//        var fragment =
//            supportFragmentManager.findFragmentByTag(RecordVideoFragment.TAG) as? RecordVideoFragment
//        if (fragment?.isDetached == true) {
//            return
//        }
//
//        fragment = (fragment ?: RecordVideoFragment.newInstance(limitedDuration = limitedDuration))
//        fragment.videoRecordListener = this
//        supportFragmentManager.beginTransaction()
//            .replace(R.id.f_container, fragment, RecordVideoFragment.TAG)
//            .commit()
    }

//    override fun onRecordSuccess(videoInfo: RecordVideoInfo) {
//        val resultIntent = Intent().apply {
//            putExtra(EXTRA_VIDEO, videoInfo)
//        }
//        setResult(RESULT_OK, resultIntent)
//        finish()
//    }

    companion object {
        // 传参
        const val EXTRA_LIMITED_DURATION = "limited_duration"
        const val EXTRA_VIDEO = "key_video_info"
    }
}