package com.renrenliao.im.widget.dialog

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.gyf.immersionbar.ktx.statusBarHeight
import com.renrenliao.im.R
import com.renrenliao.im.utils.DeviceUtils
import com.renrenliao.im.utils.LogUtils
import com.renrenliao.im.widget.view.CustomToolBar
import kotlinx.android.synthetic.main.dialog_nickname.*


/**
 **@ClassName NickNameDialog
 **@Description
 **@Author gan
 **@Date 2022/5/30 15:15
 **/
class NickNameDialog(context: Context,nickName:String)
    : Dialog(context, R.style.userinfo_dialog) {

    init {
//        immersionBar(context as Activity)
//        {
//            this.statusBarColor(R.color.main_theme_color)
//        }

        setCanceledOnTouchOutside(true)
        setCancelable(true)
        val view = View.inflate(context, R.layout.dialog_nickname, null)

        val tool_bar = view.findViewById<CustomToolBar>(R.id.tool_bar)
        val cancle = tool_bar.findViewById<TextView>(R.id.tv_title_left)
        val confirm = tool_bar.findViewById<TextView>(R.id.tv_title_right)

        window?.setContentView(view)
        window?.setGravity(Gravity.BOTTOM)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            DeviceUtils.getScreenH(context)-context.statusBarHeight
        )
      //  LogUtils.error(DeviceUtils.getScreenH(context))
      //  LogUtils.error(context.statusBarHeight)
       //  ll_parent.setPadding(0,context.statusBarHeight,0,0)
       // DeviceUtils.setFullScreen(context as Activity?,R.color.main_theme_color,false)

        et_nickname.setText(nickName)

        cancle.setOnClickListener {
            dismiss()
         //   context.destroyImmersionBar(this)
        }
        confirm.setOnClickListener {
            val content = et_nickname.text.toString()
            if (content.isNotBlank()){
                mOnClickListener?.invoke(content)
                dismiss()
          //      context.destroyImmersionBar(this)
            }
        }
        mLinClear.setOnClickListener {
            et_nickname.setText("")
        }
    }

    var mOnClickListener: ((str:String) -> Unit)? = null
    fun setOnClickListener(l: (str:String) -> Unit) {
        mOnClickListener = l
    }
}