package com.gh.gamecenter.gamedetail.fuli.kaifu

import android.app.Dialog
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.gh.gamecenter.common.view.VerticalItemDecoration
import com.gh.gamecenter.databinding.DialogServersCalendarRemindTimeSettingBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

/**
 * 设置提醒时间弹窗
 */
class ServersCalendarRemindTimeSettingDialog : BottomSheetDialogFragment() {

    private lateinit var viewBinding: DialogServersCalendarRemindTimeSettingBinding

    private var selectCallback: ((ServersCalendarAdvancedTime) -> Unit)? = null

    fun setSelectCallback(callback: ((ServersCalendarAdvancedTime) -> Unit)?) {
        this.selectCallback = callback
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, com.gh.gamecenter.common.R.style.DialogWindowTransparent)
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return super.onCreateDialog(savedInstanceState).apply {
            window?.setWindowAnimations(com.gh.gamecenter.common.R.style.community_publication_animation)
            window?.setGravity(Gravity.BOTTOM)
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        viewBinding.cancel.setOnClickListener {
            dismissAllowingStateLoss()
        }

        viewBinding.rv.adapter = ServersCalendarRemindTimeSettingAdapter(requireContext()) {
            this.selectCallback?.invoke(it)
            dismissAllowingStateLoss()
        }
        viewBinding.rv.layoutManager = LinearLayoutManager(context)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return DialogServersCalendarRemindTimeSettingBinding.inflate(inflater, container, false).also {
            viewBinding = it
        }.root
    }
}