package com.kaixed.kchat.view.activity

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.kaixed.kchat.R
import com.kaixed.kchat.databinding.ActivityApplyAddFriendBinding
import com.kaixed.kchat.viewmodel.ApplyFriendViewModel
import com.kaixed.kchat.viewmodel.SearchFriendsViewModel

class ApplyAddFriendActivity : AppCompatActivity() {
    private lateinit var binding: ActivityApplyAddFriendBinding

    private val applyAddFriendViewModel: ApplyFriendViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityApplyAddFriendBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val contactId = intent.getStringExtra("contactId")

        binding.tvSendApply.setOnClickListener {
            Log.d("haha", contactId.toString())

            if (contactId != null) {
                applyAddFriendViewModel.addFriends(contactId, binding.etMessage.text.toString())
                    ?.observe(this) { value ->
                        if (value != null) {
                            runOnUiThread {
                                if (value.code == "200") {
                                    Toast.makeText(this, value.msg, Toast.LENGTH_SHORT).show()
                                    finish()
                                }
                            }
                        }
                    }

            }

        }
    }
}