package com.swago.room.dialog

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.Gravity
import com.bumptech.glide.Glide
import com.swago.baseswago.baseroom.SwagoRoomManager
import com.swago.baseswago.dialog.BaseXDFragment
import com.swago.baseswago.model.live.AnchorClosedModel
import com.swago.baseswago.util.NoDoubleClickListener
import com.swago.baseswago.util.TimeUtil
import com.swago.room.R
import com.swago.room.databinding.DialogAnchorCloseBinding

/**
 *@date 2021/11/28 21:13
 *description:
 */
class AnchorCloseDialog : BaseXDFragment<DialogAnchorCloseBinding>(){

    private var anchorCloseModel:AnchorClosedModel? = null

    companion object{
        fun newInstance(anchorCloseModel:AnchorClosedModel):AnchorCloseDialog{
            val dialog = AnchorCloseDialog()
            val bundle = Bundle()
            bundle.putParcelable("model",anchorCloseModel)
            dialog.arguments = bundle
            return dialog
        }
    }


    @SuppressLint("MissingSuperCall")
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        setDimAmount(0f)
        setHeightMatchParent()
        setGravity(Gravity.BOTTOM)
    }


    override fun initOther() {
        arguments?.let {
            anchorCloseModel =  it.getParcelable("model")
            anchorCloseModel?.let {  anchorClosedModel ->
                Glide.with(this).load(anchorClosedModel.user_head_img_url)
                    .placeholder(R.mipmap.default_avatar)
                    .error(R.mipmap.default_avatar).into(binding.ivAvatar)
                binding.tvIncomeValue.text = anchorClosedModel.income_coins
                binding.tvWatcherValue.text = anchorClosedModel.total_member
                binding.tvTimeValue.text = TimeUtil.convertMinSecond((anchorClosedModel.broadcast_time))
                binding.tvTotalTimeValue.text = TimeUtil.convertMinSecond((anchorClosedModel.total_broadcast_time))
                binding.tvName.text = anchorClosedModel.user_name
                binding.tvId.text = "ID:${anchorClosedModel.user_account}"
            }
        }

        binding.tvClose.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                dismissAllowingStateLoss()
                activity?.finish()
            }
        })
    }

    override fun initLiveData() {

    }
}