package com.ux.video.file.filerecovery.main

import android.content.Intent
import android.view.LayoutInflater
import com.ux.video.file.filerecovery.R
import com.ux.video.file.filerecovery.base.BaseActivity
import com.ux.video.file.filerecovery.databinding.ActivityScanSelectTypeBinding
import com.ux.video.file.filerecovery.result.ScanningActivity
import com.ux.video.file.filerecovery.utils.Common.KEY_SCAN_TYPE
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_audio
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_deleted_audio
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_deleted_documents
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_deleted_photo
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_deleted_video
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_documents
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_photo
import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_video
import kotlin.properties.Delegates

class ScanSelectTypeActivity : BaseActivity<ActivityScanSelectTypeBinding>() {

    companion object {
        val KEY_FILE_TYPE = "file_type"
        val VALUE_PHOTO = 0
        val VALUE_VIDEO = 1
        val VALUE_AUDIO = 2
        val VALUE_DOCUMENT = 3
    }

    private var allType by Delegates.notNull<Int>()
    private var deletedType by Delegates.notNull<Int>()
    override fun inflateBinding(inflater: LayoutInflater): ActivityScanSelectTypeBinding =
        ActivityScanSelectTypeBinding.inflate(inflater)


    override fun initView() {
        super.initView()
        val type = intent.getIntExtra(KEY_FILE_TYPE, VALUE_PHOTO)
        setSelectType(type)

    }

    override fun initData() {
        super.initData()
        binding.imageBack.setOnClickListener { finish() }
        binding.scanAllFile.setOnClickListener {

            startActivity(Intent(this@ScanSelectTypeActivity, ScanningActivity::class.java).apply {
                putExtra(KEY_SCAN_TYPE, allType)
            })

        }
        binding.scanDeletedFile.setOnClickListener {
            startActivity(Intent(this@ScanSelectTypeActivity, ScanningActivity::class.java).apply {
                putExtra(KEY_SCAN_TYPE, deletedType)
            })
        }
    }

    private fun setSelectType(fileType: Int) {
        when (fileType) {
            VALUE_PHOTO -> {
                allType = VALUE_SCAN_TYPE_photo
                deletedType = VALUE_SCAN_TYPE_deleted_photo
                binding.title.text = getString(R.string.photo_title)
            }

            VALUE_VIDEO -> {
                allType = VALUE_SCAN_TYPE_video
                deletedType = VALUE_SCAN_TYPE_deleted_video
                binding.title.text = getString(R.string.video_title)
            }

            VALUE_AUDIO -> {
                allType = VALUE_SCAN_TYPE_audio
                deletedType = VALUE_SCAN_TYPE_deleted_audio
                binding.title.text = getString(R.string.audio_title)
            }

            VALUE_DOCUMENT -> {
                allType = VALUE_SCAN_TYPE_documents
                deletedType = VALUE_SCAN_TYPE_deleted_documents
                binding.title.text = getString(R.string.document_title)
            }
        }

    }
}