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  IdentityDialogUtils {

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

        var mNormalPopup = QMUIPopups.fullScreenPopup(context)
        val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
        val frameLayout = QMUIFrameLayout(context)
//        frameLayout.background = QMUIResHelper.getAttrDrawable(context, R.attr.qmui_skin_support_popup_bg)
//        builder.background(R.attr.qmui_skin_support_popup_bg)
//          QMUISkinHelper.setSkinValue(frameLayout, builder)
//          frameLayout.radius = QMUIDisplayHelper.dp2px(context, 8)
//        val padding = QMUIDisplayHelper.dp2px(context, 0)
//        frameLayout.setPadding(padding, padding, padding, padding)

        //自定义布局
        val layoutInflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var layout = layoutInflater.inflate(R.layout.item_identity, null)
        val flOwner:FrameLayout=layout.findViewById(R.id.fl_owner)
        val flDriver:FrameLayout=layout.findViewById(R.id.fl_driver)

        val ivOwner: ImageView =layout.findViewById(R.id.iv_owner)
        val ivDriver:ImageView=layout.findViewById(R.id.iv_driver)

        val butSure: TextView = layout.findViewById(R.id.tv_sure)

        var chosetype=0

        flOwner.onClick {
            chosetype=2
            ivOwner.setImageResource(R.drawable.ic_identity_on)
            ivDriver.setImageResource(R.drawable.ic_identity_off)

        }
        flDriver.onClick {
            chosetype=1
            ivOwner.setImageResource(R.drawable.ic_identity_off)
            ivDriver.setImageResource(R.drawable.ic_identity_on)
        }


        butSure.onClick {

            if(chosetype==0){
                Toast.makeText(context,"请选择您的身份！",Toast.LENGTH_SHORT).show()

                return@onClick
            }

            choiceData?.onRestuse(chosetype.toString())

            mNormalPopup.dismiss()
        }


        builder.release();

       // val size= QMUIDisplayHelper.getScreenWidth(context)-QMUIDisplayHelper.dp2px(context, 54)

        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)


    }
}
