package com.swago.room.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.swago.baseswago.baseroom.IRoomActiveListener
import com.swago.baseswago.baseroom.IRoomInfo
import com.swago.baseswago.baseroom.SwagoRoomManager
import com.swago.baseswago.dialog.ReportDialog
import com.swago.baseswago.util.NoDoubleClickListener
import com.swago.baseswago.util.UserInfo
import com.swago.room.databinding.LayoutUserFooterViewBinding
import com.swago.room.databinding.LayoutUserHeaderViewBinding
import com.swago.room.inter.IFooter

/**
 *@date 2021/10/9 10:55
 *description:
 */
class UserFooterView : ConstraintLayout, IFooter,IRoomActiveListener {

    lateinit var binding: LayoutUserFooterViewBinding

    var openSendMsgDialog:(()->Unit)? = null
    var openMessageFun:(()->Unit)? = null
    var openGiftPanelFun:(()->Unit)? = null
    var openGameFun:(()->Unit)? = null

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    ) {
        initView()
    }

    private fun initView() {
        visibility = View.GONE
        SwagoRoomManager.addListener(this)
        binding = LayoutUserFooterViewBinding.inflate(LayoutInflater.from(context), this, true)
        binding.ivChat.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                openSendMsgDialog?.invoke()
            }
        })

        binding.ivMessage.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                openMessageFun?.invoke()
            }
        })

        binding.ivGift.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                openGiftPanelFun?.invoke()
            }
        })

        binding.ivGame.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                openGameFun?.invoke()
            }
        })
    }

    fun setGameIcon(b: Boolean) {
        binding.ivGame.visibility = if (b) View.VISIBLE else View.GONE
    }

    override fun getFooterView(): View {
        return this
    }


    override fun changeRoom(iRoomInfo: IRoomInfo) {
        visibility = View.GONE
    }

    override fun leaveRoom(iRoomInfo: IRoomInfo) {
    }

    override fun joinedRoom(iRoomInfo: IRoomInfo) {
        visibility = View.VISIBLE
    }

    override fun endRoom(iRoomInfo: IRoomInfo?) {
    }

    override fun closeRoomed() {
        SwagoRoomManager.removeListener(this)
    }
}