package com.b2lmobitech.fieldcloudhrms

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.b2lmobitech.fieldcloudhrms.databinding.FragmentMoreBinding

class MoreFragment : Fragment() {

    private lateinit var binding: FragmentMoreBinding
    private lateinit var adapter: MoreListAdapter

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentMoreBinding.inflate(inflater, container, false)

        setupMenuList()

        return binding.root
    }

    private fun setupMenuList() {

        val menuItems = listOf(
//            MoreMenuModel(R.drawable.ic_leave, "Leave Tracker"),
            MoreMenuModel(R.drawable.baseline_calendar_today_24, "Attendance"),
            MoreMenuModel(R.drawable.outline_assignment_add_24, "Time Sheet"),
            MoreMenuModel(R.drawable.outline_sick_24, "Leave Tracker"),
//            MoreMenuModel(R.drawable.ic_performance, "Performance"),
//            MoreMenuModel(R.drawable.ic_files, "Files"),
//            MoreMenuModel(R.drawable.ic_hr_letters, "HR Letters"),
            MoreMenuModel(R.drawable.baseline_travel_explore_24, "Travel"),
            MoreMenuModel(R.drawable.baseline_attach_money_24, "Payslip")
//            MoreMenuModel(R.drawable.ic_tasks, "Tasks")
        )

        adapter = MoreListAdapter(menuItems) { selectedItem ->
            when (selectedItem.title) {

//                "Leave Tracker" -> {
//                    startActivity(Intent(requireContext(), LeaveTrackerActivity::class.java))
//                }

                "Attendance" -> {
                    (activity as? HomeActivity)?.setTitleText("Attendance")
                    parentFragmentManager.beginTransaction()
                        .replace(R.id.fragmentContainer, AttendanceFragment())
                        .addToBackStack(null)
                        .commit()
                }

                "Time Sheet" -> {
                    (activity as? HomeActivity)?.setTitleText("Time Sheet")
                    parentFragmentManager.beginTransaction()
                        .replace(R.id.fragmentContainer, TimesheetFragment())
                        .addToBackStack(null)
                        .commit()
                }

                "Leave Tracker" -> {
                    (activity as? HomeActivity)?.setTitleText("Leave Tracker")
                    parentFragmentManager.beginTransaction()
                        .replace(R.id.fragmentContainer, LeaveTrackerFragment())
                        .addToBackStack(null)
                        .commit()
                }

                "Payslip" -> {
                    (activity as? HomeActivity)?.setTitleText("Payslip")
                    parentFragmentManager.beginTransaction()
                        .replace(R.id.fragmentContainer, PayslipFragment())
                        .addToBackStack(null)
                        .commit()
                }

//                "Performance" -> {
//                    startActivity(Intent(requireContext(), PerformanceActivity::class.java))
//                }
//
//                "Files" -> {
//                    startActivity(Intent(requireContext(), FilesActivity::class.java))
//                }
//
//                "HR Letters" -> {
//                    startActivity(Intent(requireContext(), HRLettersActivity::class.java))
//                }
//
                "Travel" -> {
                    (activity as? HomeActivity)?.setTitleText("Travel")
                    parentFragmentManager.beginTransaction()
                        .replace(R.id.fragmentContainer, TravelFragment())
                        .addToBackStack(null)
                        .commit()
                }
//
//                "Tasks" -> {
//                    startActivity(Intent(requireContext(), TasksActivity::class.java))
//                }
            }
        }

        binding.recyclerMore.apply {
            layoutManager = LinearLayoutManager(requireContext())
            adapter = this@MoreFragment.adapter
        }
    }
}
