package com.cygnusa.hyperm.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.cygnusa.hyperm.R;
import com.cygnusa.hyperm.RedeemProductListActivity;
import com.cygnusa.hyperm.util.GlobalData;
import com.cygnusa.hyperm.util.StorePreference;
import com.cygnusa.hyperm.wrappers.Bulletin;
import com.cygnusa.hyperm.wrappers.RedeemCategory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;



public class RedeemPointListAdapter extends RecyclerView.Adapter<RedeemPointListAdapter.ViewHolder> {

    private RedeemCategory items;
    private Context context;
    private Bulletin TOPIC;
  //  String[] title={"Amazon Gift Card","Flipkart Gift Card","Bookmyshow Gift Card","ibaco Gift Card","Myntra Gift Card","Jabong Gift Card","Domino's Gift Card","T Gift Card","Life Style Gift Card","ICICI Gift Card","Visa Gift Card","Paytm Gift Card","e Gift Card","GRT Gift Card","fastrack Gift Card"};
   // String[] price={"500","200","300","500","500","300","1000","400","500","300","1000","400","500","300","1000"};
 //   int[] image={R.drawable.amazon,R.drawable.flipkart,R.drawable.book,R.drawable.ibaco,R.drawable.myntra,R.drawable.jabong,R.drawable.domino,R.drawable.amazon,R.drawable.flipkart,R.drawable.ibaco,R.drawable.myntra,R.drawable.jabong,R.drawable.domino,R.drawable.amazon,R.drawable.fastrack};
StorePreference storePreference;

    public RedeemPointListAdapter(Context context,RedeemCategory item) {

        this.items = item;
        this.context = context;
        storePreference = new StorePreference(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.redeem_list_item, parent, false);
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               storePreference.setString(GlobalData.WOOHOOCATID,items.getRoot_category().getCategory_id());
                context.startActivity(new Intent(context, RedeemProductListActivity.class));

            }
        });


        return new ViewHolder(v);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
       // Bulletin item = items.get(position);

     //   holder.view.setTag(item);
       holder.title.setText(items.getRoot_category().getCategory_name());
        holder.subTitle.setText("Shop Products");
       //holder.Amount.setText("Rs "+);
        holder.Amount.setSelected(true);
        holder.subTitle.setSelected(true);

        Glide.with(context).load(items.getRoot_category().category_image)
                .thumbnail(Glide.with(context).load(R.drawable.gif_loader))
                .apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.ALL)
                        .placeholder(R.drawable.placeholder).error(R.drawable.placeholder)).into(holder.redeemImage);

    }


    @Override
    public int getItemCount() {

        return 1;
    }

    public void add(RedeemCategory item, int position) {

    }

    public void add(RedeemCategory item) {


    }

    public void remove(int position) {

    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView redeemImage;
        TextView title, subTitle, Amount;
        View view;

        private ViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            redeemImage = itemView.findViewById(R.id.redeem_img);
            title = itemView.findViewById(R.id.redeem_title);
            subTitle = itemView.findViewById(R.id.redeem_subtitle);
            Amount = itemView.findViewById(R.id.redeem_amount);

        }

    }
    public String dateFormate(String dte) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date newDate = null;
        try {
            newDate = format.parse(dte);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        format = new SimpleDateFormat("dd-MMM-yyyy");
        String date = format.format(newDate);


        return date;
    }
}
