package xn.hxp.weidith

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import xn.hxp.R
import xn.hxp.comm.Constants
import com.rc.httpcore.HttpConfig

//身份认证通过
class AuthenticationDialog(
    private val ct: Context,
    private var imgUrl: String?,
    private var subName: String,
    private var deptName: String,
    private var buildName: String,
    private var userName: String,
    private var iClickLit: IClickLit,
) : Dialog(ct) {
    private var tvView: TextView? = null

    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.authentication_dialog)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        findViewById<TextView>(R.id.subName).text = "$subName"
        findViewById<TextView>(R.id.deptName).text = "$deptName"
        findViewById<TextView>(R.id.buildName).text = "$buildName"
        findViewById<TextView>(R.id.userName).text = "$userName"
        var img = findViewById<ImageView>(R.id.imgView)
        tvView = findViewById<TextView>(R.id.tvView)
        iClickLit.onUpView(tvView!!)
        setCanceledOnTouchOutside(false) // 禁止点击对话框外部空白区域时关闭对话框
        // 使用 Glide 加载网络图片
//        if (imgUrl != null) {
//
//        }
        Glide.with(ct)
            .load("${HttpConfig.API_BASE_IMG_URL}$imgUrl")
            .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
            .error(R.mipmap.icon_zhan_wei)
            .into(img)
    }

    interface IClickLit {
        fun onUpView(tvView: TextView)//关闭后调用归还api
    }
}