package com.zswc.creativity.utils

import android.content.Context
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet.BottomListSheetBuilder
import com.zswc.creativity.inte.ChoiceData
import com.zswc.creativity.inte.ChoiceListData
import com.zswc.creativity.inte.ChoseData
import com.zswc.creativity.model.InsurancePlan
import com.zswc.creativity.model.SelectData
import java.util.ArrayList


/**
 *Created by shihuiyun
 *on 2020/10/13
 */
object PopuBottomUtils {

     fun showList(context: Context,
                  list: ArrayList<SelectData>, chose: ChoiceListData
    ) {
        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position].code,list[position].name)
                    dialog.dismiss()
                }

        for (item in list) {
            builder.addItem(item.name)
        }
        builder.build().show()
    }



    fun showListString(context: Context,
                 list: ArrayList<String>, chose: ChoiceData
    ) {
        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position])
                    dialog.dismiss()
                }

        for (item in list) {
            builder.addItem(item)
        }
        builder.build().show()
    }



    fun showListChose(context: Context,
                       list: List<InsurancePlan>, chose: ChoseData
    ) {

        var data = ArrayList<String>()
        for (item in list) {
            data.add(item.schemeName)
        }

        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position])
                    dialog.dismiss()
                }

        for (item in data) {
            builder.addItem(item)
        }
        builder.build().show()
    }



}
