package com.hanwha.morakmorak.ui.main.home.post

import android.os.Bundle
import com.hanwha.morakmorak.R
import com.hanwha.morakmorak.databinding.ActivityPostDialogBinding
import com.hanwha.morakmorak.ui.BindingActivity
import com.hanwha.morakmorak.util.NotNullMutableLiveData
import org.koin.androidx.viewmodel.ext.android.getViewModel

class PostDialogActivity : BindingActivity<ActivityPostDialogBinding, PostDialogViewModel>() {

    override fun getLayoutResId() = R.layout.activity_post_dialog

    override fun getMyViewModel(): PostDialogViewModel  = getViewModel()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setFinishOnTouchOutside(false)

        binding.also {
            it.lifecycleOwner = this
            it.vm = viewModel
        }

        // Dialog click listener
        viewModel.onDialogCloseClick = { finish() }
        viewModel.onDialogNegativeClick = {
            //                Snackbar.make(binding.snackbarCoordinatorLayout, "왜 취소해?", Snackbar.LENGTH_SHORT).show()
//            viewModel.dateTime.clear()
//            viewModel.location.clear()
//            viewModel.maxPerson.clear()
//            viewModel.cover.clear()
//            meetingDialog.dismiss()
            finish()
        }
        viewModel.onDialogPositiveClick = {
//            Snackbar.make(binding.snackbarCoordinatorLayout, "저장되었습니다.", Snackbar.LENGTH_SHORT).show()
//            meetingDialog.dismiss()
            finish()
        }
    }
}

private fun NotNullMutableLiveData<String>.clear() {
    value = ""
}
