package com.zswc.creativity.utils

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.layout.QMUIFrameLayout
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.popup.QMUIPopup
import com.qmuiteam.qmui.widget.popup.QMUIPopups
import com.ysnows.base.widget.DelEditText
import com.zswc.creativity.R
import com.zswc.creativity.inte.ChoiceData

/**
 *Created by shihuiyun
 *on 2020/9/21
 */
object  PopuSureUtils {

    fun show(context:Context, view: View, choiceData: ChoiceData ){

        var mNormalPopup = QMUIPopups.fullScreenPopup(context)
        val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
        val frameLayout = QMUIFrameLayout(context)
        //自定义布局
        val layoutInflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var layout = layoutInflater.inflate(R.layout.popu_sure, null)

        val imgClose:ImageView=layout.findViewById(R.id.img_close)
        val etNum: DelEditText =layout.findViewById(R.id.et_num)
        val tvSure:TextView=layout.findViewById(R.id.tv_sure)

        imgClose.onClick {
            mNormalPopup.dismiss()
        }

        tvSure.onClick {
            var s = etNum.text.toString().trim()
            if (TextUtils.isEmpty(s)) {
                Toast.makeText(context, "请输入支付密码", Toast.LENGTH_SHORT).show()
                return@onClick
            }

            choiceData?.onRestuse(s)

            mNormalPopup.dismiss()
        }


        builder.release();

        val size= QMUIDisplayHelper.getScreenWidth(context)


        val lp: FrameLayout.LayoutParams = FrameLayout.LayoutParams(size,
                FrameLayout.LayoutParams.WRAP_CONTENT)
        frameLayout.addView(layout, lp)

        mNormalPopup.addView(frameLayout)
        mNormalPopup.onDismiss() {
        }

        mNormalPopup.dismissIfOutsideTouch(false)
        mNormalPopup.animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
        mNormalPopup.show(view)


    }




}
