package com.hesiii.i_hear.Game;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.content.Intent;
import android.os.Bundle;

import com.hesiii.i_hear.Adapters.CategoryAdapter;
import com.hesiii.i_hear.Interfaces.CategoryEvents;
import com.hesiii.i_hear.Models.Category;
import com.hesiii.i_hear.Models.Data;
import com.hesiii.i_hear.R;
import com.hesiii.i_hear.databinding.ActivityCategoryBinding;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CategoryActivity extends AppCompatActivity {

    private ActivityCategoryBinding binding;
    private List<Category> categoryList;
    private CategoryAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityCategoryBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        if (getSupportActionBar() != null) {

            getSupportActionBar().hide();

        }

        setDataToRecyclerView();

    }

    private void setDataToRecyclerView() {

        adapter = new CategoryAdapter(this, getCategoryList(), new CategoryEvents() {
            @Override
            public void onCategoryClick(int position) {

                //Toast.makeText(GameCategoryActivity.this, getCategoryList().get(position).getCategoryTitle(), Toast.LENGTH_SHORT).show();
                //startActivity(new Intent(getApplicationContext(), DiceActivity.class));

                String categoryName = getCategoryList().get(position).getCategoryName();

                if (categoryName.equals("people")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", peopleData());
                    startActivity(intent);

                } else if (categoryName.equals("vehicles")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", vehiclesData());
                    startActivity(intent);

                } else if (categoryName.equals("fruits")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", fruitsData());
                    startActivity(intent);

                } else if (categoryName.equals("animals")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", animalsData());
                    startActivity(intent);

                } else if (categoryName.equals("objects")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", objectsData());
                    startActivity(intent);

                } else if (categoryName.equals("shuffle")) {

                    Intent intent = new Intent(CategoryActivity.this, GameActivity.class);
                    intent.putExtra("data", shuffleData());
                    startActivity(intent);

                }

            }
        });

        binding.categoryRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        binding.categoryRecyclerView.setHasFixedSize(true);
        binding.categoryRecyclerView.setAdapter(adapter);

    }

    private List<Category> getCategoryList() {

        List<Category> categoryList = new ArrayList<>();

        categoryList.add(new Category(R.drawable.people, "People", "people"));
        categoryList.add(new Category(R.drawable.vehicles, "Vehicles", "vehicles"));
        categoryList.add(new Category(R.drawable.fruits, "Fruits", "fruits"));
        categoryList.add(new Category(R.drawable.animals, "Animals", "animals"));
        categoryList.add(new Category(R.drawable.objects, "Objects", "objects"));
        categoryList.add(new Category(R.drawable.shuffle, "Shuffle", "shuffle"));

        return categoryList;

    }

    private ArrayList<Data>peopleData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.nurse, "nurse"));
        dataList.add(new Data(R.drawable.doctor, "doctor"));
        dataList.add(new Data(R.drawable.farmer, "farmer"));
        dataList.add(new Data(R.drawable.teacher, "teacher"));
        dataList.add(new Data(R.drawable.waiter, "waiter"));

        Collections.shuffle(dataList);

        return dataList;

    }

    private ArrayList<Data>vehiclesData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.bicycle, "bicycle"));
        dataList.add(new Data(R.drawable.bus, "bus"));
        dataList.add(new Data(R.drawable.car, "car"));
        dataList.add(new Data(R.drawable.ship, "ship"));
        dataList.add(new Data(R.drawable.train, "train"));

        Collections.shuffle(dataList);

        return dataList;

    }

    private ArrayList<Data>fruitsData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.apple, "apple"));
        dataList.add(new Data(R.drawable.banana, "banana"));
        dataList.add(new Data(R.drawable.orange, "orange"));
        dataList.add(new Data(R.drawable.pineapple, "pineapple"));
        dataList.add(new Data(R.drawable.strawberry, "strawberry"));

        Collections.shuffle(dataList);

        return dataList;

    }

    private ArrayList<Data>animalsData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.bird, "bird"));
        dataList.add(new Data(R.drawable.cow, "cow"));
        dataList.add(new Data(R.drawable.dog, "dog"));
        dataList.add(new Data(R.drawable.fish, "fish"));
        dataList.add(new Data(R.drawable.horse, "horse"));

        Collections.shuffle(dataList);

        return dataList;

    }

    private ArrayList<Data>objectsData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.bag, "bag"));
        dataList.add(new Data(R.drawable.book, "book"));
        dataList.add(new Data(R.drawable.chair, "chair"));
        dataList.add(new Data(R.drawable.pencil, "pencil"));
        dataList.add(new Data(R.drawable.table, "table"));

        Collections.shuffle(dataList);

        return dataList;

    }

    private ArrayList<Data>shuffleData() {

        ArrayList<Data>dataList = new ArrayList<>();

        dataList.add(new Data(R.drawable.bird, "bird"));
        dataList.add(new Data(R.drawable.table, "table"));
        dataList.add(new Data(R.drawable.orange, "orange"));
        dataList.add(new Data(R.drawable.train, "train"));
        dataList.add(new Data(R.drawable.farmer, "farmer"));

        Collections.shuffle(dataList);

        return dataList;

    }

}