package com.develop.auth.ui

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import com.develop.auth.R
import com.develop.auth.databinding.DialogDataPickerBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

class AgeSelectDialog(
    private val activity: AppCompatActivity,
    private val onConfirm: (index: Int, change: Boolean) -> Unit
): BottomSheetDialog(activity, R.style.BottomSheetDialog) {

    private val binding = DialogDataPickerBinding.inflate(activity.layoutInflater)
    private val initIndex = 0
    init {
        val listData = createAgeListData()
        setContentView(binding.root)
        binding.tvCancel.setOnClickListener {
            dismiss()
        }
        binding.tvConfirm.setOnClickListener {
            dismiss()
            val currentIndex = binding.wheelPicker.currentItemPosition
            onConfirm(currentIndex, true)
        }
        binding.wheelPicker.selectedItemTextColor = Color.BLACK
        binding.wheelPicker.itemTextColor = 0xff000000.toInt()
        binding.wheelPicker.setAtmospheric(true)
        binding.wheelPicker.isCurved = true
        binding.wheelPicker.data = listData
        if (initIndex >= 0 && initIndex <= listData.size - 1) {
            binding.wheelPicker.setSelectedItemPosition(initIndex, false)
        }
    }

    private fun createAgeListData(): List<String> {
        val list = mutableListOf<String>()
        for (index in 20..80) {
            list.add(index.toString())
        }
        return list
    }
}