package com.swago.room.anchor

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.gyf.immersionbar.ImmersionBar
import com.swago.baseswago.PersonDataDFragment
import com.swago.baseswago.baseroom.IRoomInfo
import com.swago.room.base.BaseComFragment
import com.swago.room.databinding.FragmentBaseComBinding
import com.swago.room.inter.IFooter
import com.swago.room.inter.IHeader
import com.swago.room.vm.RoomVm
import com.swago.room.widget.AnchorFooterView
import com.swago.room.widget.AnchorHeaderView

/**
 *@date 2021/10/9 11:35
 *description:
 */
class AnchorRoomFragment : BaseComFragment<FragmentBaseComBinding>() {

    private var footerView : AnchorFooterView? = null

    override fun initOther() {
        super.initOther()
    }

    override fun initLiveData() {
        super.initLiveData()
        roomVm.roomUserDataLiveData.observe(this){
            iHeader.updateRoomUser(it)
        }

        footerView = iFooter as AnchorFooterView
        footerView?.openSendMsgDialog = {
            openSendMessageDialog()
        }

        footerView?.openMessageFun = {
            openMessageListDialog()
        }

        footerView?.openGameFun = {
            openGameDialog()
        }

        val headerView = iHeader as AnchorHeaderView
        headerView.showUserInfo = {
            PersonDataDFragment.newInstance(it, isAnchor = true, inRoom = true).show(childFragmentManager,"PersonDataDFragment")
        }

        msgVm.inComeChange = {
            headerView.updateIncome(it)
        }

        msgVm.updateHotValue = {
            headerView.updateHotValue(it)
        }
    }



    override fun changeRoom(iRoomInfo: IRoomInfo) {
    }

    override fun leaveRoom(iRoomInfo: IRoomInfo) {
    }

    override fun joinedRoom(iRoomInfo: IRoomInfo) {
        super.joinedRoom(iRoomInfo)
    }

    override fun endRoom(iRoomInfo: IRoomInfo?) {
    }

    override fun closeRoomed() {
        super.closeRoomed()
    }

    fun setFooterGameIcon(b: Boolean) {
        footerView?.setGameIcon(b)
    }

    override val iHeader: IHeader by lazy {
        AnchorHeaderView(requireContext())
    }
    override val iFooter: IFooter by lazy {
        AnchorFooterView(requireContext())
    }
}