package com.nivesh.production.partnerOnBoarding.ui.fragments

import android.app.Activity
import android.content.Context
import androidx.fragment.app.Fragment
import com.nivesh.production.partnerOnBoarding.ui.activities.BaseActivity

open class BaseFragment : Fragment() {

    private lateinit var mActivity: Activity
    override fun onAttach(context: Context) {
        super.onAttach(context)
        mActivity = context as BaseActivity
    }

    companion object {
        fun addFragment(
            activity: BaseActivity,
            containerViewId: Int,
            fragment: Fragment,
            tag: String,
            addToBackStack: Boolean
        ) {
            val fragmentTransaction = activity.supportFragmentManager.beginTransaction()
            fragmentTransaction.add(containerViewId, fragment, tag)
            if (addToBackStack) {
                fragmentTransaction.addToBackStack(tag)
            }
            fragmentTransaction.commit()
        }

        fun replaceFragment(
            activity: BaseActivity,
            containerViewId: Int,
            fragment: Fragment,
            tag: String,
            addToBackStack: Boolean
        ) {
            val fragmentTransaction = activity.supportFragmentManager.beginTransaction()
            fragmentTransaction.replace(containerViewId, fragment, tag)
            if (addToBackStack) {
                fragmentTransaction.addToBackStack(tag)
            }
            fragmentTransaction.commit()
        }
    }
}