package com.wdkl.ncs.android.lib.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import com.enation.javashop.utils.base.tool.ScreenTool
import com.wdkl.ncs.android.lib.R
import com.wdkl.ncs.android.lib.utils.reLayout

class MenuDialog {

    private val context : Context

    companion object {

        fun build(context: Context):MenuDialog{
            return MenuDialog(context)
        }

    }

    private constructor(context: Context) {
        this.context = context
    }

    fun config(voiceCall :(()->Unit)? = null, videoCall :(()->Unit)? = null) : Dialog {
        val contentView = LayoutInflater.from(context).inflate(R.layout.menu_dialog_lay, null)
        val dialog = Dialog(context, R.style.Dialog)
        dialog.setContentView(contentView)
        contentView.reLayout<ViewGroup.LayoutParams> {
            params ->
            params.width = ScreenTool.getScreenWidth(context).toInt()
            params.height = ScreenTool.getScreenHeight(context).toInt()
        }
        val voiceTv = contentView.findViewById<TextView>(R.id.menu_dialog_voice)
        val videoTv = contentView.findViewById<TextView>(R.id.menu_dialog_video)
        val cancelTv = contentView.findViewById<TextView>(R.id.menu_dialog_cancel)

        voiceTv.setOnClickListener {
            dialog.dismiss()
            voiceCall?.invoke()
        }
        videoTv.setOnClickListener {
            dialog.dismiss()
            videoCall?.invoke()
        }
        cancelTv.setOnClickListener {
            dialog.dismiss()
        }
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        return dialog
    }
}