package com.abbidot.tracker.ui.common

import android.content.Context
import android.view.View
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.tracker.R
import com.abbidot.tracker.adapter.TextViewAdapter
import com.abbidot.tracker.base.BaseDialog
import com.abbidot.tracker.bean.DataBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.dialog.CommonListDialog

/**
 *Created  by .yzq on 2024/7/15/015.
 * @link
 * @description:
 */
class UnitSelectDialog(context: Context) {

    private val mContext = context

    private var mUnitDialog: CommonListDialog? = null

    /**
     * 显示单位选择弹窗
     */
    fun showUnitDialog(listener: BaseDialog.OnDialogSelectListener?) {
        if (null == mUnitDialog) {
            val heightUnitList = mutableListOf<DataBean>()
            DataBean().run {
                name = mContext.getString(R.string.txt_imperial)
                state = ConstantInt.Type1
                heightUnitList.add(this)
            }
            DataBean().run {
                name = mContext.getString(R.string.txt_metric)
                state = ConstantInt.Type2
                heightUnitList.add(this)
            }
            val unitAdapter = TextViewAdapter(mContext, heightUnitList).apply {
                setOnItemClickListener(object : BaseRecyclerAdapter.OnItemClickListener {
                    override fun onItemClick(itemView: View?, pos: Int) {
                        mUnitDialog?.dismiss()
                        listener?.onSelectClick(mUnitDialog!!, heightUnitList[pos].state)
                    }
                })
            }
            mUnitDialog = CommonListDialog(mContext, unitAdapter, 3, 3)
        }
        mUnitDialog?.show()
    }
}