package com.ux.video.file.filerecovery.success

import android.content.Intent
import android.view.LayoutInflater
import androidx.core.view.isVisible
import com.ux.video.file.filerecovery.R
import com.ux.video.file.filerecovery.base.BaseActivity
import com.ux.video.file.filerecovery.databinding.ActivityRecoverOrDeletedSuccessBinding
import com.ux.video.file.filerecovery.main.MainActivity
import com.ux.video.file.filerecovery.recovery.RecoveryActivity
import com.ux.video.file.filerecovery.utils.Common
import com.ux.video.file.filerecovery.utils.FileType

class RecoverySuccessActivity : BaseActivity<ActivityRecoverOrDeletedSuccessBinding>() {

    companion object {
        val KEY_SUCCESS_TYPE = "success_type"
        val KEY_SUCCESS_COUNT = "success_count"
    }

    private lateinit var fileType: FileType

    //0  恢复成功  1 删除成功
    private var successType = 0
    override fun inflateBinding(inflater: LayoutInflater): ActivityRecoverOrDeletedSuccessBinding =
        ActivityRecoverOrDeletedSuccessBinding.inflate(inflater)

    override fun initData() {
        super.initData()
        val intExtra = intent.getIntExtra(Common.KEY_FILE_TYPE, FileType.PHOTO.value)

        fileType = FileType.from(intExtra)!!

        successType = intent.getIntExtra(KEY_SUCCESS_TYPE, 0)
        val counts = intent.getIntExtra(KEY_SUCCESS_COUNT, 0)

        binding.run {
            tvNumber.text = counts.toString()
            bottomBtnRecoverLayout.run {
                tvLeft.text = resources.getString(R.string.text_continue)
                tvRight.text = resources.getString(R.string.view)
            }
            when (fileType) {
                FileType.PHOTO  -> tvFileType.text =
                    resources.getString(R.string.describe_photos)

                FileType.VIDEO  -> tvFileType.text =
                    resources.getString(R.string.describe_videos)

                FileType.AUDIO  -> tvFileType.text =
                    resources.getString(R.string.describe_audios)

                FileType.DOCUMENT  -> tvFileType.text =
                    resources.getString(R.string.describe_documents)
            }
            when (successType) {
                0 -> {
                    imageCenter.setImageResource(R.drawable.image_recover_success)
                    tvNumber.setTextColor(
                        Common.getColorInt(
                            this@RecoverySuccessActivity,
                            R.color.main_text_blue
                        )
                    )
                    bottomBtnRecoverLayout.root.isVisible = true
                    tvContinue.isVisible = false
                    tvDescribe.text = resources.getString(R.string.recovered_success)

                    bottomBtnRecoverLayout.tvLeft.setOnClickListener { finish()}
                    bottomBtnRecoverLayout.tvRight.setOnClickListener {
                        finish()
                        Intent(this@RecoverySuccessActivity,RecoveryActivity::class.java).apply {
                            putExtra(Common.KEY_FILE_TYPE,fileType.value)
                        }.let {
                            startActivity(it)
                        }

                    }

                }

                1 -> {
                    imageCenter.setImageResource(R.drawable.image_deleted_success)
                    tvNumber.setTextColor(
                        Common.getColorInt(
                            this@RecoverySuccessActivity,
                            R.color.dialog_shape_delete
                        )
                    )
                    bottomBtnRecoverLayout.root.isVisible = false
                    tvContinue.isVisible = true
                    tvDescribe.text = resources.getString(R.string.deleted_success)
                    tvContinue.setOnClickListener { finish()}
                }
            }

            imageViewBack.setOnClickListener { finish() }
            imageBackHome.setOnClickListener {
                val intent = Intent(this@RecoverySuccessActivity, MainActivity::class.java)
                intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
                startActivity(intent)
                finish()

            }
        }


    }


}