export default (configuration) => {
    return `
        
    package ${configuration.packageName}.ui.fragments.alerts

import ${configuration.name}.R
import ${configuration.name}.databinding.FragmentAlertsBinding
import android.app.AlertDialog
import android.content.ContentValues.TAG
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import ${configuration.packageName}.data.local.AppPreferences
import ${configuration.packageName}.model.remote.AlertModel
import ${configuration.packageName}.adapter.AlertsAdapter
import ${configuration.packageName}.extensions.*
import ${configuration.name}.databinding.DialogAlertViewBinding
import ${configuration.packageName}.extensions.hide
import ${configuration.packageName}.extensions.loadImageFromUrl
import ${configuration.packageName}.extensions.setOnClickWithDebounce
import ${configuration.packageName}.extensions.setVerticalLayout
import ${configuration.packageName}.extensions.show
import ${configuration.packageName}.extensions.snackBar
import ${configuration.packageName}.extensions.viewBinding
import ${configuration.packageName}.network.Status
import ${configuration.packageName}.viewmodels.BaasViewModel
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel



class AlertsFragment : Fragment(R.layout.fragment_alerts) {

    private val viewModel: BaasViewModel by viewModel()
    private val binding by viewBinding(FragmentAlertsBinding::bind)
    private val newAlerts: ArrayList<AlertModel> = ArrayList()
    private val readAlerts: ArrayList<AlertModel> = ArrayList()
    private val newAlertsAdapter by lazy { AlertsAdapter(this::onAlertClick) }
    private val pref by inject<AppPreferences>()

    private fun onAlertClick(item: AlertModel) {
        Log.d(TAG, "onAlertClick: $item")
        showDialog(item.message, item.id)
    }

    private fun showDialog(message: String, id: Int) {
        val builder = AlertDialog.Builder(requireContext())
        val binding = DialogAlertViewBinding.inflate(layoutInflater)
        val dialog = builder.create()

        dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

        binding.tvAlertDialogMsg.text = message

        binding.buttonAlertDialogClose.setOnClickWithDebounce {
            dialog.dismiss()
            setAlertSeen(id)
        }
      
        dialog.setView(binding.root)
        dialog.setCancelable(true)
        dialog.show()
    }





    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)



        binding.rcvNewAlerts.apply {
            setVerticalLayout()
            adapter = newAlertsAdapter
        }


    }

    override fun onResume() {
        super.onResume()
        getAlerts()
    }

    private fun getAlerts() {
        viewModel.appAlertsList("id,desc", "1,20", "is_read,eq,0").observe(viewLifecycleOwner) {
            when (it.status) {
                Status.ERROR -> snackBar(it.message ?: getString(R.string.something_went_wrong))
                Status.LOADING -> {}
                Status.SUCCESS -> {
                    var alerts: List<AlertModel>? = it.data?.list?.map { map ->
                        val id = map["id"]?.toString()?.toDoubleOrNull()?.toInt() ?: 0
                        val create_at = map["create_at"] as? String ?: ""
                        val image = map["image"] as? String ?: ""
                        val is_read = map["is_read"]?.toString()?.toDoubleOrNull()?.toInt() ?: 1
                        val message = map["message"] as? String ?: ""
                        val update_at = map["update_at"] as? String ?: ""
                        val user_id = map["user_id"]?.toString()?.toDoubleOrNull()?.toInt() ?: 0
                        AlertModel(id, user_id, image, is_read, message, create_at, update_at )
                    }
                    setAlertLists(alerts)

                }
            }
        }
    }

    private fun setAlertSeen(id: Int = 0) {
        viewModel.appAlertsUpdate(1, id.toString()).observe(viewLifecycleOwner) {
            when (it.status) {
                Status.ERROR -> snackBar(it.message ?: getString(R.string.something_went_wrong))
                Status.LOADING -> {}
                Status.SUCCESS -> {

                    setAlertLists(newAlerts.filterNot { alert -> alert.id == id })
                }
                }
            }
        }

    private fun setAlertLists(message: List<AlertModel>?) {
        newAlerts.clear()
        newAlerts.addAll(message?.filter { it.is_read == 0 } ?: ArrayList())
        newAlertsAdapter.refresh(newAlerts)


        if (newAlerts.isEmpty()) {
            binding.tvTagNew.hide()
            binding.rcvNewAlerts.hide()
        } else {
            binding.tvTagNew.show()
            binding.rcvNewAlerts.show()
        }

        if (newAlerts.isEmpty() ) {
            binding.llNoAlerts.show()
        }
    }

}

`
}