package ir.almahdi.sandogh_bsa_aza.vam_ha_ozv;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

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

import java.util.List;

import ir.almahdi.sandogh_bsa_aza.Global_var;
import ir.almahdi.sandogh_bsa_aza.R;
import ir.almahdi.sandogh_bsa_aza.vam_ha_ozv.model.md_vam_karbar;

public class vam_adapter extends RecyclerView.Adapter<vam_adapter.MyViewHolder> {

    private Context myContext;
    private List<md_vam_karbar> myVamList;

    vam_adapter(Context context, List<md_vam_karbar> myVamList) {
        this.myContext = context;
        this.myVamList = myVamList;    }



    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.crd_vam_karbar, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        md_vam_karbar Entiremd_vam_karbar = myVamList.get(position);
        holder.setvamInfo(Entiremd_vam_karbar);
    }

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

    // ViewHoldr Class

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tarikh_dar_vam,id_vam,
           mab_vam,tedad_aghsat,mande_vam,tedad_gest_par,mab_gh_vam;

        MyViewHolder(View itemView) {
            super(itemView);

            id_vam = itemView.findViewById(R.id.idvam);
            tedad_aghsat = itemView.findViewById(R.id.tedad_aghsat);
            mab_vam = itemView.findViewById(R.id.mablagh_vam);
            mande_vam = itemView.findViewById(R.id.txtmande_vam);
           // tedad_gest_par = itemView.findViewById(R.id.txt_tedad_gest_par);
            tarikh_dar_vam = itemView.findViewById(R.id.txt_tarikh_vam);
            mab_gh_vam=itemView.findViewById(R.id.txt_mab_gest);
        }

        public void setvamInfo(md_vam_karbar vam_karbar) {
            id_vam.setText(vam_karbar.getId_par_vam_nbt());
            tedad_aghsat.setText(vam_karbar.getBazpard_vam_mah());
            mab_vam.setText(Global_var.splitDigits(Integer.parseInt(vam_karbar.getMablagh_vam_par())));
            // فعلا کوئری اقساط پرداختی ومانده وام را ننوشتیم
            mande_vam.setText(Global_var.splitDigits(Integer.parseInt(vam_karbar.getMande_vam())));
            mab_gh_vam.setText(Global_var.splitDigits(Integer.parseInt(vam_karbar.getMablagh_gh_vam_nob())));
            tarikh_dar_vam.setText(vam_karbar.getTarikh_par_vam());



        }
    }
}

