package com.zxhy.hfilemanagermaster.manager

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.example.hfilemanagermaster.R
import com.example.hfilemanagermaster.databinding.FragmentManagerBinding
import com.zxhy.hfilemanagermaster.OverviewActivity
import com.zxhy.hfilemanagermaster.knife.getMountInfoList
import java.math.BigDecimal

/**
 * A simple [Fragment] subclass.
 * Use the [ManagerFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class ManagerFragment : Fragment() {
    private lateinit var binding: FragmentManagerBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_manager, container, false)
        binding = FragmentManagerBinding.bind(view.rootView)
        return view
    }

    @SuppressLint("SetTextI18n")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val disk = requireContext().getMountInfoList().first()
        binding.tvFree.text = disk.getTotalContent(requireContext())
        val percentF = BigDecimal(disk.used)
            .divide(BigDecimal(disk.total), 2, BigDecimal.ROUND_HALF_UP)

//        binding.indicatorView.setPercent(percentF.toFloat())
        binding.indicatorView.setPercent(0.3f)
        val percent = percentF.multiply(BigDecimal(100)).toInt()
        binding.tvUse.text = "$percent%"

        (requireActivity() as OverviewActivity).showManager()

        binding.cardView1.setOnClickListener { }
        binding.cardView2.setOnClickListener { }
        binding.cardView3.setOnClickListener { }

        binding.ivFile.setOnClickListener {
            findNavController().navigate(R.id.filesFragment)
        }
        binding.ivWord.setOnClickListener { }
        binding.ivExcel.setOnClickListener { }
        binding.ivPdf.setOnClickListener { }
        binding.ivPpt.setOnClickListener { }
        binding.cardView1.setOnClickListener {
            findNavController().navigate(R.id.dupPictureActivity)
        }
        binding.cardView2.setOnClickListener {
            findNavController().navigate(R.id.largeFileActivity)
        }
        binding.cardView3.setOnClickListener {
            findNavController().navigate(R.id.emptyFileActivity)
        }

    }

    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            ManagerFragment().apply {
                arguments = Bundle().apply {
                }
            }
    }
}