package com.utopiaindustries.qualitychecker.ui.adapter;

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

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

import com.utopiaindustries.qualitychecker.R;
import com.utopiaindustries.qualitychecker.models.InspectionItemDimension;

import java.util.List;

public class ItemDimensionAdapter extends
        RecyclerView.Adapter<ItemDimensionAdapter.ItemDiemsionViewHolder> {

    private final List<InspectionItemDimension> dimensions;

    public ItemDimensionAdapter( List<InspectionItemDimension> dimensions ){
        this.dimensions = dimensions;
    }
    @NonNull
    @Override
    public ItemDiemsionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dimension , parent, false);
        return new ItemDiemsionViewHolder( view );
    }

    @Override
    public void onBindViewHolder(@NonNull ItemDiemsionViewHolder holder, int position) {
        InspectionItemDimension dimension = dimensions.get( position );
        holder.bind( dimension );
    }

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

    public static class ItemDiemsionViewHolder extends RecyclerView.ViewHolder{

        private final EditText dimensionType,dimensionUnit,dimensionRequired,dimensionActual,dimensionDifference;

        public ItemDiemsionViewHolder(@NonNull View itemView) {
            super(itemView);
            dimensionType = itemView.findViewById( R.id.dimension_type );
            dimensionUnit = itemView.findViewById( R.id.dimension_unit );
            dimensionRequired = itemView.findViewById( R.id.dimension_required );
            dimensionActual = itemView.findViewById( R.id.dimension_actual );
            dimensionDifference = itemView.findViewById( R.id.dimension_difference );
        }
        public void bind( InspectionItemDimension dimension ){
            dimensionType.setText( dimension.getType() );
            dimensionUnit.setText( dimension.getUnit() );
            dimensionRequired.setText(  String.valueOf( dimension.getRequired() ));
            dimensionActual.setText( String.valueOf( dimension.getActual() ) );
            dimensionDifference.setText( String.valueOf( dimension.getDifference() ));
        }
    }
}
