package com.zswc.creativity.utils

import android.content.Context
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.zswc.creativity.R
import com.zswc.creativity.inte.ChoiceData

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

    fun show(context:Context, text:String,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.item_tips, null)

        val tvContent:TextView=layout.findViewById(R.id.tv_content)
        val tvCancel:TextView=layout.findViewById(R.id.tv_cancel)
        val tvSure:TextView=layout.findViewById(R.id.tv_sure)
        tvContent.text=text

        tvCancel.onClick {
            mNormalPopup.dismiss()
        }

        tvSure.onClick {

            choiceData?.onRestuse("")

            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)


    }



    //接单的提示
    fun showRegistOrder(context:Context, phone:String,view: View,
                      password:String,payPassword:String,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.item_tips, null)

        val tvContent:TextView=layout.findViewById(R.id.tv_content)
        val tvPassword:TextView=layout.findViewById(R.id.tv_password)
        val tvPayPassword:TextView=layout.findViewById(R.id.tv_pay_password)
        val tvCancel:TextView=layout.findViewById(R.id.tv_cancel)
        val tvSure:TextView=layout.findViewById(R.id.tv_sure)

        tvContent.text="手机号：$phone"
        tvPassword.text= "登录密码：$password"
        tvPayPassword.text="二级密码：$payPassword"

        tvCancel.onClick {
            mNormalPopup.dismiss()
        }

        tvSure.onClick {

            choiceData?.onRestuse("")

            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)


    }

}
