package com.zxhy.solarmasterace.filedetails

import android.annotation.SuppressLint
import android.os.Bundle
import android.text.format.Formatter
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import coil.load
import com.zxhy.solarmasterace.R
import com.zxhy.solarmasterace.databinding.ActivityFileDetailBinding
import java.io.File

class FileDetailActivity : AppCompatActivity() {
    private lateinit var binding: ActivityFileDetailBinding

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityFileDetailBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val path = intent.extras?.getString("Path") ?: ""
        val file = File(path)
        if (file.exists()) {
            binding.iv.load(path)
            binding.tvName.text = "Name:" + file.name
            binding.tvSize.text = "Size:" + Formatter.formatFileSize(this, file.length())
            binding.tvPosition.text = "Position:" + file.absoluteFile
        }
        binding.clArrow.setOnClickListener {
            finish()
        }
        binding.tvDelete.setOnClickListener {
            if (file.exists()) {
                file.delete()
            }
            finish()
        }
    }
}