package fsir.tqqe

import android.app.Activity
import android.view.View
import android.view.View.OnClickListener
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.test.basd.supercleanermax.R

class Tdnh : BottomSheetBehavior.BottomSheetCallback, OnClickListener, Vtzf<Kikc> {

    private val mContext: Activity

    private val bottomSheetBehavior: BottomSheetBehavior<LinearLayout>

    private val blackOverlay: View

    private val listener: Moaw

    private val mAlbumName: TextView

    private val mRecycleView: RecyclerView

    override fun onSlide(bottomSheet: View, slideOffset: Float) {
    }

    override fun onItemClick(position: Int, entity: Kikc) {
        mAlbumName.text = entity.name
        bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
        listener.onSelectAlbum(entity)
    }

    override fun onStateChanged(bottomSheet: View, newState: Int) {
        when (newState) {
            BottomSheetBehavior.STATE_HIDDEN -> {
                blackOverlay.visibility = View.GONE
            }

            BottomSheetBehavior.STATE_COLLAPSED -> {
                blackOverlay.visibility = View.GONE
            }

            else -> {
                blackOverlay.visibility = View.VISIBLE
            }
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.uooynfa -> {
                if (bottomSheetBehavior.state != BottomSheetBehavior.STATE_EXPANDED) {
                    bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
                }
            }

            R.id.npkngym -> {
                bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
            }
        }
    }

    constructor(mContext: Activity, listener: Moaw) {
        this.mContext = mContext
        this.listener = listener
        mRecycleView = mContext.findViewById(R.id.fusjlxn)
        blackOverlay = mContext.findViewById(R.id.npkngym)
        val bottomSheet = mContext.findViewById<LinearLayout>(R.id.phyfrri)
        bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
        mAlbumName = mContext.findViewById(R.id.uooynfa)
        init()
    }

    private fun init() {
        bottomSheetBehavior.addBottomSheetCallback(this)
        blackOverlay.setOnClickListener(this)
        mAlbumName?.setOnClickListener(this)

        mRecycleView.layoutManager = LinearLayoutManager(mContext)
        val mList = Lpgx.getAlbums(mContext)
        val mAdapter = Slnz(mList, this)
        mRecycleView.adapter = mAdapter
        if (mList.isNotEmpty()) {
            onItemClick(0, mList[0])
        }
    }

    override fun onUpdateBtn(boolean: Boolean, entity: Kikc) {

    }
}

