package com.amz.genie.activities

import android.os.Bundle
import android.widget.ImageButton
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import com.amz.genie.R
import com.bumptech.glide.Glide
import com.google.android.material.imageview.ShapeableImageView
import java.io.File

class AttachmentPreviewActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_attachment_preview)

        val localPath = intent.getStringExtra("local_path").orEmpty()
        val title = intent.getStringExtra("title").orEmpty()

        val ib = findViewById<ImageButton>(R.id.ib_back_attachment_preview)
        val iv = findViewById<ShapeableImageView>(R.id.iv_attachment_preview)
        val tv = findViewById<TextView>(R.id.tv_title_attachment_preview)

        tv.text = title.ifBlank { "Lampiran" }

        onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
                handleBackPress(0)
            }
        })

        ib.setOnClickListener { handleBackPress(0) }

        // ✅ load dari file lokal
        Glide.with(this)
            .load(File(localPath))
            .into(iv)
    }
}