package com.miya.fastcashier.utils

import android.content.Context
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import androidx.core.content.res.ResourcesCompat
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.bigkoo.pickerview.view.TimePickerView
import com.miya.fastcashier.R
import java.util.*

class DateSelectHelper(val context: Context, val callback: (Date) -> Unit) {

    var timePickerView: TimePickerView? = null
    fun showDatePicker() {
        if (timePickerView == null) {
            initTimePicker()
        }
        val date = Calendar.getInstance()
        date.set(
            date.get(Calendar.YEAR),
            date.get(Calendar.MONTH),
            date.get(Calendar.DAY_OF_MONTH),
            0,
            0
        )
        timePickerView!!.setDate(date)
        timePickerView!!.show()
    }

    private fun initTimePicker() {
        val calendar = Calendar.getInstance()
        val startDate = Calendar.getInstance()
        val endDate = Calendar.getInstance()

        startDate.set(
            calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH),
            0,
            0,
            0
        )
        endDate.set(
            calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH),
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE)
        )
        timePickerView = TimePickerBuilder(context, OnTimeSelectListener { date, v ->
            callback(date)
        })
            .setTitleText("请选择开始时间")
            .setType(booleanArrayOf(false, false, false, true, true, false))
            .setDate(startDate)
            .setContentTextSize(30)
            .setTitleSize(30)
            .setSubCalSize(30)
            .setRangDate(startDate, endDate)
            .build()
    }

    fun dismiss() {
        timePickerView?.dismiss()
    }


}