package com.audio.record.screen.test.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.audio.record.screen.test.R
import com.audio.record.screen.test.adapter.ToolAdapter
import com.audio.record.screen.test.base.BaseFragment
import com.audio.record.screen.test.databinding.FragmentMainBinding
import com.audio.record.screen.test.databinding.FragmentStartBinding

class StartFragment : BaseFragment<FragmentStartBinding>() {

    private var param1: String? = null
    private var param2: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
//            param1 = it.getString(ARG_PARAM1)
//            param2 = it.getString(ARG_PARAM2)
        }
    }


    override fun initBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentStartBinding =
        FragmentStartBinding.inflate(inflater, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val  navController = findNavController()

        binding.toolRecycler.run {
            val stringList = resources.getStringArray(R.array.tool_text).toList()
            adapter = ToolAdapter(requireContext()){
                when(it){
                    0->{
                        navController.navigate(R.id.action_to_fragmentCut)
                    }
                    1-> {
                        navController.navigate(R.id.action_to_fragmentCropping)
                    }
                    2->{
                        navController.navigate(R.id.action_to_fragmentVolume)
                    }
                    3->{
                        navController.navigate(R.id.action_to_fragmentSpeed)
                    }
                }

            }.apply { updateData(stringList) }
            layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)
        }
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            StartFragment().apply {
                arguments = Bundle().apply {
//                    putString(ARG_PARAM1, param1)
//                    putString(ARG_PARAM2, param2)
                }
            }
    }
}