package com.swago.baseswago.dialog

import android.os.Bundle
import androidx.fragment.app.viewModels
import com.swago.baseswago.R
import com.swago.baseswago.UserVm
import com.swago.baseswago.databinding.DialogReportBinding
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.NoDoubleClickListener

/**
 *@date 2021/12/12 13:47
 *description:举报弹窗
 */
class ReportDialog : BaseXDFragment<DialogReportBinding>() {

    private var account = ""

    companion object{
        fun newInstance(account: String):ReportDialog{
            val dialog = ReportDialog()
            val bundle = Bundle()
            bundle.putString("account",account)
            dialog.arguments = bundle
            return dialog
        }
    }

    private val userVm  by viewModels<UserVm>()

    override fun initOther() {
        arguments?.let {
            account = it.getString("account","")
        }
        binding.tvReportOne.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_one))
            }
        })

        binding.tvReportTwo.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_two))
            }
        })

        binding.tvReportThree.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_three))
            }
        })

        binding.tvReportFour.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_four))
            }
        })

        binding.tvReportFive.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_five))
            }
        })

        binding.tvReportSix.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                report(AppContext.getContext().resources.getString(R.string.report_six))
            }
        })
    }

    fun report(content:String){
        userVm.reportUser(account,content)
    }

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