package com.swago.baseswago.dialog

import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.viewModels
import com.swago.baseswago.UserVm
import com.swago.baseswago.databinding.DialogReportBlockBinding
import com.swago.baseswago.util.IMUtil
import com.swago.baseswago.util.NoDoubleClickListener

/**
 *@date 2022/2/7 16:26
 *description:
 */
class ReportBlockDialogFragment : BaseXDFragment<DialogReportBlockBinding>() {

    private var account = ""
    private val userVm by viewModels<UserVm>()

    companion object {
        fun newInstance(account: String): ReportBlockDialogFragment {
            val args = Bundle()
            args.putString("account", account)
            val fragment = ReportBlockDialogFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun initOther() {
        arguments?.let {
            account = it.getString("account", "")
        }
        binding.tvReport.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                ReportDialog.newInstance(account).show(childFragmentManager, "ReportDialog")
            }
        })

        binding.tvBlack.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                val list = ArrayList<String>()
                list.add(account)
                IMUtil.addToBlackList(list){
                    userVm.addBlack(account,0)
                }
            }
        })
    }

    override fun initLiveData() {
        userVm.hasBeenBlackLiveData.observe(this) {
            dismissAllowingStateLoss()
        }
    }

    init {
        setGravity(Gravity.BOTTOM)
        setDimAmount(0.5f)
    }

}