package com.develop.common.dialog

import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import com.develop.common.R
import com.develop.common.databinding.DialogDataPickerBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

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

    private val binding = DialogDataPickerBinding.inflate(activity.layoutInflater)
    private val initIndex = 0
    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val listData = createAgeListData()
        setContentView(binding.root)
        binding.root.setOnClickListener {
            dismiss()
        }
        binding.ivConfirm.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
    }
}