package com.adealink.weparty.profile.edit.dialog

import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.toast.util.showToast
import com.adealink.weparty.commonui.widget.BottomDialogFragment
import com.adealink.weparty.profile.R
import com.adealink.weparty.profile.databinding.DialogEditNicknameBinding

class EditNickNameDialog : BottomDialogFragment(R.layout.dialog_edit_nickname) {

    private val binding by viewBinding(DialogEditNicknameBinding::bind)
    private var callback: IEditNameCallback? = null

    fun setCallback(callback: IEditNameCallback?) {
        this.callback = callback
    }

    override fun initViews() {
        super.initViews()
        binding.btnSave.onClick {
            save()
        }
    }

    private fun save() {
        val nickName = binding.etInput.text?.toString()?.trim()
        if (nickName.isNullOrEmpty()) {
            showToast(R.string.profile_edit_nickname_empty)
            return
        }
        callback?.onEditName(nickName)
        dismiss()
    }


    interface IEditNameCallback {
        fun onEditName(name: String)
    }
}