package com.app.simplitend.chats;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.app.simplitend.R;
import com.app.simplitend.apputils.CaregiverDataCache;
import com.app.simplitend.apputils.RetrofitHelper;

public class ChatsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chats);

        CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
            if (careGiverData1 != null && careGiverData1.patientDetails != null){

                String sender_image;
                if (careGiverData1.profile_photo == null){
                    sender_image = String.valueOf(R.drawable.caregiver_img);
                }else{
                    sender_image = RetrofitHelper.IMAGE_BASE_URL + careGiverData1.profile_photo;
                }

                String receiver_image;
                if (careGiverData1.patientDetails.profile_photo == null){
                    receiver_image = String.valueOf(R.drawable.senior_img);
                }else{
                    receiver_image = RetrofitHelper.IMAGE_BASE_URL + careGiverData1.patientDetails.profile_photo;
                }

                getSupportFragmentManager().beginTransaction()
                        .add(R.id.chats_fcv, new ChatFragment(
                                careGiverData1.caregiver_xid + "",
                                careGiverData1.patientId + "",
                                careGiverData1.link_id,
                                careGiverData1.patientDetails.id + "",
                                careGiverData1.first_name,
                                careGiverData1.patientDetails.first_name,
                                sender_image,
                                receiver_image), "chat")
                        .commitAllowingStateLoss();
            }else{
                finish();
            }
        }), true);

    }
}