export default (configuration) => {
  return `
package ${configuration.packageName}.extensions

import ${configuration.name}.R
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.TypedValue
import android.text.InputFilter
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.AnimationUtils
import android.view.animation.ScaleAnimation
import android.view.animation.TranslateAnimation
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar

fun View.slideDown() {
    val animate = TranslateAnimation(
        0F,  // fromXDelta
        0F,  // toXDelta
        0F,  // fromYDelta
        this.height.toFloat()
    ) // toYDelta
    animate.duration = 500
    this.startAnimation(animate)
}

fun View.slideUp() {
    val animate = ScaleAnimation(
        1F,  // fromXDelta
        1F,  // toXDelta
        1F,  // fromYDelta
        0F
    ) // toYDelta
    animate.duration = 500
    this.startAnimation(animate)
}

fun View.fadeIn(duration: Int = 400) {
    clearAnimation()
    val alphaAnimation = AlphaAnimation(this.alpha, 1.0f)
    alphaAnimation.duration = duration.toLong()
    startAnimation(alphaAnimation)
}

fun View.fadeOut(duration: Int = 400) {
    clearAnimation()
    val alphaAnimation = AlphaAnimation(this.alpha, 0f)
    alphaAnimation.duration = duration.toLong()
    startAnimation(alphaAnimation)
}

fun View.changeTint(color: Int) {
    this.backgroundTintList =
        ContextCompat.getColorStateList(
            context, color
        )
}

fun View.show() {
    visibility = View.VISIBLE
}

fun View.hide() {
    visibility = View.GONE
}

fun View.invisible() {
    visibility = View.INVISIBLE
}

/*
fun RecyclerView.rvItemAnimation() {
    layoutAnimation = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_fall_down)
}
*/

fun ImageView.loadImageFromUrl(
    aImageUrl: String?,
    aPlaceHolderImage: Int = R.drawable.ic_loc_active
) {
    if (!aImageUrl.isNullOrEmpty()) {
        Glide.with(this.context)
            .load(Uri.parse(aImageUrl))
            .placeholder(aPlaceHolderImage)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .error(aPlaceHolderImage)
            .into(this)
    } else displayBlankImage(this.context, aPlaceHolderImage)
}


fun ImageView.displayBlankImage(aContext: Context, aPlaceHolderImage: Int) {
    Glide.with(aContext)
        .load(aPlaceHolderImage)
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(this)
}


@SuppressLint("NewApi")
fun Activity.snackBar(
    msg: String,
    length: Int = Snackbar.LENGTH_SHORT,
) =
    Snackbar.make(findViewById(android.R.id.content), msg, length)
        .setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_SLIDE)
        .show()

fun Fragment.snackBar(msg: String) = activity!!.snackBar(msg)

fun RecyclerView.setGridLayout(span: Int = 2) {
    layoutManager = GridLayoutManager(context, span)
}

fun RecyclerView.setVerticalLayout(aReverseLayout: Boolean = false) {
    layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, aReverseLayout)
}

fun RecyclerView.setHorizontalLayout(aReverseLayout: Boolean = false) {
    layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, aReverseLayout)
}

fun Activity.hideSoftKeyboard() {
    val imm = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
    var view = this.currentFocus
    if (view == null) {
        view = View(this)
    }
    imm.hideSoftInputFromWindow(view.windowToken, 0)
}

fun Fragment.shareText(text: String) {
    val sendIntent: Intent = Intent().apply {
        action = Intent.ACTION_SEND
        putExtra(Intent.EXTRA_TEXT, text)
        type = "text/plain"
    }
    startActivity(Intent.createChooser(sendIntent, null))
}

fun Fragment.hideKeyboard() {
    view?.let { activity?.hideSoftKeyboard() }
}

@ColorInt
fun Fragment.getColorFromAttr(
    @AttrRes attrColor: Int,
    typedValue: TypedValue = TypedValue(),
    resolveRefs: Boolean = true
): Int {
    requireContext().theme.resolveAttribute(attrColor, typedValue, resolveRefs)
    return typedValue.data
}

fun Fragment.toast(stringRes: String, duration: Int = Snackbar.LENGTH_SHORT) {
    view?.let {
        val snackBar = Snackbar.make(it, stringRes, duration)
            .setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_SLIDE)
        snackBar.show()
    }
}

fun View.setOnClickWithDebounce(action: (View) -> Unit) {
    setOnClickListener {
        isEnabled = false
        action.invoke(this)
        postDelayed({ isEnabled = true }, 2000)
    }
}

fun EditText.disableSpaces() {
    val filter =
        InputFilter { source, start, end, dest, dstart, dend ->
            for (i in start until end) {
                if (Character.isWhitespace(source[i])) {
                    return@InputFilter ""
                }
            }
            null
        }

    this.filters = arrayOf(filter)
}

  `;
};
