package com.bc_chat.bc_base.view

import android.view.View
import com.bc_chat.bc_base.R
import com.bc_chat.bc_base.databinding.DialogGroupInfoBinding
import com.bc_chat.bc_base.utils.Const
import com.bc_chat.bc_base.utils.gone
import com.zhaohaoting.framework.abs.AbsBottomDialogFragment
import com.zhaohaoting.framework.abs.contract.BaseContract

/**
 * author：Created by zhaohaoting on 2019/2/22
 * email：526309416@qq.com
 * desc：群资料菜单
 */
class GroupMenuDialogFragment : AbsBottomDialogFragment<BaseContract.BasePresenter>(), View.OnClickListener {

    private var role: Int? = Const.GROUP_ROLE.ROLE_GROUP_ORDINARY
    override fun initialize() {
        val binding = rootDataBinding as DialogGroupInfoBinding
        binding.onClickEvent = this
        role = arguments?.getInt("role",Const.GROUP_ROLE.ROLE_GROUP_ORDINARY)
        if (Const.GROUP_ROLE.ROLE_GROUP_LORDE == role) {
            binding.tvExitGroup.gone()
        }
    }

    override fun initPresenter(): BaseContract.BasePresenter? = null

    override fun getLayoutResId(): Int = R.layout.dialog_group_info

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_clear_msg -> {
                groupMenuListener?.groupMenuClick(1)
            }
            R.id.tv_exit_group -> {
                groupMenuListener?.groupMenuClick(2)
            }
            R.id.tv_cancel -> {
                dismissAllowingStateLoss()
            }
        }
    }

    fun setOnGroupMenuListener(listener: (position: Int) -> Unit) {
        groupMenuListener = object : OnGroupMenuListener {
            override fun groupMenuClick(position: Int) {
                dismissAllowingStateLoss()
                listener(position)
            }
        }
    }

    private var groupMenuListener: OnGroupMenuListener? = null

    interface OnGroupMenuListener {
        fun groupMenuClick(position: Int)
    }

}