package com.develop.main.init.ui.provider

import android.view.View
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.develop.food.base.widgets.HomeFilterSortSearchView
import com.develop.main.R
import com.develop.main.init.ui.adapter.RecipesMainAdapter

class FunctionProvider : BaseItemProvider<Any>() {
    var onFunctionCallback: OnFunctionCallback? = null
    override val itemViewType: Int
        get() = RecipesMainAdapter.FUNCTION_TAG
    override val layoutId: Int
        get() = R.layout.home_function_provider

    var filterSortSearchView: HomeFilterSortSearchView? = null
    override fun convert(helper: BaseViewHolder, item: Any) {
        filterSortSearchView = helper.getView(R.id.function_view)
        filterSortSearchView?.onFunctionCallback =
            object : HomeFilterSortSearchView.OnFunctionCallback {
                override fun onFilterClick(filterView: View) {
                    onFunctionCallback?.onFilterClick(filterView)
                }

                override fun onSortClick(sortView: View) {
                    onFunctionCallback?.onSortClick(sortView)
                }

                override fun onSearchClick() {
                    onFunctionCallback?.onSearchClick()
                }

                override fun onInputSearch(searchContent: String) {
                    onFunctionCallback?.onInputSearch(searchContent)
                }

                override fun onBackClick() {
                    onFunctionCallback?.onBackClick()
                }
            }
    }

    interface OnFunctionCallback {
        fun onFilterClick(filterView: View)
        fun onSortClick(sortView: View)
        fun onSearchClick()
        fun onInputSearch(searchContent: String)
        fun onBackClick()
    }
}