package com.abbidot.tracker.dialog

import android.content.Context
import android.view.View
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.base.BaseDialog
import com.abbidot.tracker.databinding.DialogSelectPetLabelLayoutBinding
import com.abbidot.tracker.util.ViewUtil
import com.google.android.flexbox.FlexboxLayoutManager

/**
 *Created  by .yzq on 2022/1/7/007.
 * @link
 * @description:选择多个地图导航列表弹窗
 */
class SelectPetLabelDialog(
    context: Context,
    adapter: BaseRecyclerAdapter<*>,
) : BaseDialog<DialogSelectPetLabelLayoutBinding>(
    DialogSelectPetLabelLayoutBinding::inflate, context
) {

    private val mAdapter = adapter
    private var mOkListener: OnDialogOkListener? = null

    override fun initView() {
        mViewBinding.apply {
            rvDialogPetLabels.let {
                val flexboxLayoutManager = FlexboxLayoutManager(mContext).apply {
//                    justifyContent = JustifyContent.SPACE_AROUND
//                    alignItems=AlignItems.FLEX_START
                }
                ViewUtil.instance.setRecyclerViewFlexboxLayout(
                    mContext,
                    rvDialogPetLabels,
                    mAdapter,
                    right = AppUtils.dpToPx(6),
                    bottom = AppUtils.dpToPx(8)
                )
            }

            setOnClickListenerViews(btnDialogPetLabelsCancel, btnDialogPetLabelsSave)
        }
    }

    fun setOkListener(okListener: OnDialogOkListener) {
        mOkListener = okListener
    }

    override fun onClick(v: View) {
        mViewBinding.apply {
            when (v) {
                btnDialogPetLabelsCancel -> dismiss()
                btnDialogPetLabelsSave -> {
                    mOkListener?.onOkClick(this@SelectPetLabelDialog)
                }
            }
        }
    }
}