package com.example.chemical.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.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import com.example.chemical.R
import com.rc.httpcore.bean.UseNoBean

//查询-未登录-提示
class PromptDialog(ct: Context, private val data: UseNoBean) : Dialog(ct) {
    private var mHandler: Handler = Handler(Looper.getMainLooper())

    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.prompt_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.chemicalName).text = "${data.chemicalName}"
        if (data.casNum != null) {
            findViewById<TextView>(R.id.casNum).text = "CAS: ${data.casNum}"
        } else {
            findViewById<TextView>(R.id.casNum).text = "CAS:"
        }
        if (data.chemicalCategory != null) {
            findViewById<TextView>(R.id.chemicalCategory).text = "类别: ${data.chemicalCategory}"
        } else {
            findViewById<TextView>(R.id.chemicalCategory).text = "类别: "
        }
        if (data.specUnit != null && data.packUnit != null) {
            findViewById<TextView>(R.id.sepl).text =
                "规格: ${data.specNum}${data.specUnit}/${data.packUnit}"
        } else {
            findViewById<TextView>(R.id.sepl).text =
                "规格: ${data.specNum}${data.specUnit}/${data.packUnit}"
        }

        if (data.expireTime != null) {
            when (data.expireStatus) {
                1 -> {
                    findViewById<TextView>(R.id.expireTime).text = "过期时间: ${data.expireTime}"
                    findViewById<TextView>(R.id.expire).text = "已过期"
                }
                2 -> {
                    findViewById<TextView>(R.id.expireTime).text = "过期时间: ${data.expireTime}"
                    findViewById<TextView>(R.id.expire).text = "即将过期"
                }
                else -> {
                    findViewById<TextView>(R.id.expireTime).text = "过期时间: ${data.expireTime}"
                }
            }
        } else {
            findViewById<TextView>(R.id.expireTime).text = "过期时间:"
        }

        if (data.tagCode != null) {
            findViewById<TextView>(R.id.tagCode).text = "编码: ${data.tagCode}"
        } else {
            findViewById<TextView>(R.id.tagCode).text = "编码: "
        }
        if (data.chemicalLevelName != null) {
            findViewById<TextView>(R.id.chemicalLevelName).text = "级别: ${data.chemicalLevelName}"
        } else {
            findViewById<TextView>(R.id.chemicalLevelName).text = "级别: "
        }

        if (data.surplus != null) {
            findViewById<TextView>(R.id.surplus).text = "库存量: ${data.surplus}${data.specUnit}"
        } else {
            findViewById<TextView>(R.id.surplus).text = "库存量: "
        }
        if (data.belongName != null) {
            findViewById<TextView>(R.id.belongName).text = "归属人: ${data.belongName}"
        } else {
            findViewById<TextView>(R.id.belongName).text = "归属人: "
        }



        findViewById<Button>(R.id.butClos).setOnClickListener { dismiss() }

        mHandler.postDelayed({
            dismiss()
        }, 1000 * 15) // 15秒后关闭对话框

    }

    override fun onStop() {
        super.onStop()
        mHandler.removeCallbacksAndMessages(null)
    }
}