package com.ux.video.file.filerecovery.photo

import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.ux.video.file.filerecovery.R
import com.ux.video.file.filerecovery.base.BaseActivity
import com.ux.video.file.filerecovery.databinding.ActivityPhotoInfoBinding
import com.ux.video.file.filerecovery.databinding.ActivityPhotoSortingBinding
import com.ux.video.file.filerecovery.utils.Common
import com.ux.video.file.filerecovery.utils.ExtendFunctions.dpToPx
import com.ux.video.file.filerecovery.utils.ScanManager

class PhotoInfoActivity : BaseActivity<ActivityPhotoInfoBinding>() {

    companion object {
        val KEY_CLICK_ITEM = "click_item"
    }

    private var myData: ResultPhotosFiles? = null

    override fun inflateBinding(inflater: LayoutInflater): ActivityPhotoInfoBinding =
        ActivityPhotoInfoBinding.inflate(inflater)

    override fun initView() {
        super.initView()
        myData = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            intent.getParcelableExtra(KEY_CLICK_ITEM, ResultPhotosFiles::class.java)
        } else {
            @Suppress("DEPRECATION")
            intent.getParcelableExtra("MY_KEY")
        }

        binding.run {
            myData?.let {

                tvName.text = it.name
                tvPath.text = it.path
                tvDate.text = Common.getFormatDate(it.lastModified)
                tvResolution.text = it.resolution

                Glide.with(this@PhotoInfoActivity)
                    .load(it.targetFile)
                    .apply(
                        RequestOptions()
                            .transform(
                                CenterCrop(),
                                RoundedCorners(8.dpToPx(this@PhotoInfoActivity))
                            )
                    )
                    .listener(object : RequestListener<Drawable> {
                        override fun onLoadFailed(
                            e: GlideException?,
                            model: Any?,
                            target: com.bumptech.glide.request.target.Target<Drawable?>,
                            isFirstResource: Boolean
                        ): Boolean {
                            return false
                        }

                        override fun onResourceReady(
                            resource: Drawable,
                            model: Any,
                            target: Target<Drawable?>?,
                            dataSource: DataSource,
                            isFirstResource: Boolean
                        ): Boolean {

                            return false
                        }

                    })
                    .into(image)
            }
        }


    }
}