package com.ttiglobal.inttilectgpchat.blog;

import android.annotation.SuppressLint;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.ttiglobal.inttilectgpchat.R;
import com.ttiglobal.inttilectgpchat.blog.Helper.LikeRecyclerAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class Like_Info extends AppCompatActivity {

    LikeRecyclerAdapter adapter;
    RelativeLayout error;
    RecyclerView comment_list;
    ArrayList<HashMap<String, String>> childHashMap = new ArrayList<>();

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


        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setContentInsetStartWithNavigation(0);
        toolbar.setTitle("");
        Objects.requireNonNull(getSupportActionBar()).setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        @SuppressLint("PrivateResource")
        Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        backArrow.setColorFilter(getResources().getColor(R.color.txt_color), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(backArrow);

        error = findViewById(R.id.error);
        comment_list = findViewById(R.id.comment_list);
        comment_list.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
        comment_list.setLayoutManager(linearLayoutManager);
        error.setVisibility(View.VISIBLE);


        populateComment();


    }

    private void populateComment() {
        DocumentReference ref = FirebaseFirestore.getInstance().collection("forum_datas").document();
        ref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    DocumentSnapshot document = task.getResult();
                    assert document != null;
                    if (document.exists()) {

                        childHashMap = (ArrayList<HashMap<String, String>>) document.get("like_id");
                        adapter = new LikeRecyclerAdapter(Like_Info.this, childHashMap);
                        comment_list.setAdapter(adapter);
                    }
                } else {
                    adapter = new LikeRecyclerAdapter(Like_Info.this, childHashMap);
                    comment_list.setAdapter(adapter);
                }

            }

        });
    }

}
