package com.zxhy.hfilemanagermaster

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.annotation.ColorRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.navigation.findNavController
import com.example.hfilemanagermaster.R
import com.example.hfilemanagermaster.databinding.ActivityOverviewBinding
import com.zxhy.hfilemanagermaster.permission.IntentLauncher
import com.zxhy.hfilemanagermaster.permission.PermissionLauncher

class OverviewActivity : AppCompatActivity() {
    private lateinit var binding: ActivityOverviewBinding
    lateinit var permissionLauncher: PermissionLauncher
    lateinit var intentLauncher: IntentLauncher

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        permissionLauncher = PermissionLauncher(this)
        intentLauncher = IntentLauncher(this)

        binding = ActivityOverviewBinding.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
        }

        window.statusBarColor = ContextCompat.getColor(this, R.color.color_B7FF03)
        binding.ivManager.isSelected = true


        binding.ivManager.setOnClickListener {
            binding.fragmentContainerView.findNavController().navigate(R.id.managerFragment)
            showManager()
        }

        binding.ivTools.setOnClickListener {
            binding.fragmentContainerView.findNavController().navigate(R.id.toolsFragment)
            showTools()
        }
    }

    fun setStatusBarColor(@ColorRes id: Int) {
        window.statusBarColor = ContextCompat.getColor(this, id)

        binding.ivTools.isSelected = true
        binding.ivManager.isSelected = false
    }

    fun showManager() {
        window.statusBarColor = ContextCompat.getColor(this, R.color.color_B7FF03)
        binding.ivManager.isSelected = true
        binding.ivTools.isSelected = false
    }

    fun showTools() {
        binding.ivTools.isSelected = true
        binding.ivManager.isSelected = false
        window.statusBarColor = ContextCompat.getColor(this, R.color.white)
    }
}