package com.example.prettywallpapers.prettyadapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.prettywallpapers.activity.PrettyCategoryListActivity;
import com.example.prettywallpapers.list.PrettyCategory;

import java.util.List;
import com.example.prettywallpapers.R;
import com.example.prettywallpapers.myvalue.MyValues;

public class WallpaperAdapter extends RecyclerView.Adapter<WallPaperViewHolder> {

    private List<PrettyCategory> prettyCategory;
    private Context context;
    private RecyclerView pretty_category_image;
    private TextView see_all;

    public WallpaperAdapter(List<PrettyCategory> categorylist, Context mycontext){
        prettyCategory = categorylist;
        Log.d("------------size","-------------size"+prettyCategory);
        context = mycontext;
    }
    @SuppressLint("MissingInflatedId")
    @NonNull
    @Override
    public WallPaperViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View myview = LayoutInflater.from(context).inflate(R.layout.recyclerview_pretty,parent,false);
        return new WallPaperViewHolder(myview);
    }

    @SuppressLint("CheckResult")
    @Override
    public void onBindViewHolder(@NonNull WallPaperViewHolder holder, int position) {
        PrettyCategory prettycategory = prettyCategory.get(position);
       // Log.d("------------size","-------------size"+prettycategory);
        holder.getTextView().setText(prettycategory.getName());
        holder.getSee_all().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PrettyCategoryListActivity.class);
                intent.putExtra(MyValues.PREETY_NAME, prettycategory);
                //intent.putExtra(MyValues.TYPE,1);
                context.startActivity(intent);
            }
        });
        InfoAdapter infoAdapter = new InfoAdapter(prettycategory.getList().subList(0,4),context);
        RecyclerView recyclerViewImage = holder.getRecyclerView_image();
        recyclerViewImage.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
        recyclerViewImage.setAdapter(infoAdapter);
    }

    @Override
    public int getItemCount() {
        return prettyCategory.size();
    }
}
