package com.pixelnx.localhelp.ui.vendor;

import android.content.Context;
import android.content.Intent;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.model.ModelShopListData;
import com.pixelnx.localhelp.model.ModelUserData;

import com.pixelnx.localhelp.ui.home.ActivityCategHome;

import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;

import com.pixelnx.localhelp.utils.widgets.CustomTextMedium;
import com.pixelnx.localhelp.utils.widgets.CustomTextSemiBold;
import com.squareup.picasso.Picasso;



import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class AdapterShop extends RecyclerView.Adapter<AdapterShop.HolderDialogOrder> {
    private List<ModelShopListData.Data> dataArrayList;
    private Context mContext;

    SharedPref sharedPref;
    ModelUserData modelUserData;


    public AdapterShop(Context mContext, List<ModelShopListData.Data> shopsList) {
        this.dataArrayList = shopsList;
        this.mContext = mContext;
        sharedPref = SharedPref.getInstance(mContext);
        modelUserData = sharedPref.getUser(Consts.Status.SP);
    }

    @NonNull
    @Override
    public HolderDialogOrder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_fragmentshop, viewGroup, false);

        return new HolderDialogOrder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final HolderDialogOrder holder, final int i) {

        holder.storeName.setText(" " + dataArrayList.get(i).getUserName());




        String add=dataArrayList.get(i).getAddress().trim();
        if(!add.isEmpty()){
            String strings=add.replace("|",",");
            String[] parts = strings.split(",");

            String address=""+parts[1] +","+parts[3]+" "+parts[2]+" ,"+parts[0];
            holder.storeAdd.setText(" " +address);
        }



        holder.storePhone.setText(" " + dataArrayList.get(i).getUserMobile());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ModelShopListData.Data data=dataArrayList.get(i);
                Intent intent=new Intent(mContext, ActivityCategHome.class);
                intent.putExtra("data",  data);
                intent.putExtra("chk_shp",  ""+data.getUserId());
                mContext.startActivity(intent);

            }
        });


        Picasso.get()
                .load(Consts.Status.BASE_IMAGE_URL+"users/" + dataArrayList.get(i).getUserImage())
                .placeholder(R.drawable.shoppingcaet)
                .into(holder.storeIv);

    }

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

    public static class HolderDialogOrder extends RecyclerView.ViewHolder {
        CustomTextMedium  storeAdd;
        CustomTextMedium  storePhone;

        CustomTextSemiBold storeName;
        CustomTextSemiBold storeDis;
        CircleImageView storeIv;


        public HolderDialogOrder(@NonNull View itemView) {
            super(itemView);
            storeName = itemView.findViewById(R.id.storeName);
            storeAdd = itemView.findViewById(R.id.storeAdd);
            storePhone= itemView.findViewById(R.id.storephone);
            storeIv= itemView.findViewById(R.id.storeIv);
            storeDis= itemView.findViewById(R.id.storedis);
        }
    }



}
