package com.ygtx.emcs.activity.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ygtx.emcs.R;
import com.ygtx.emcs.activity.model.StockLineModel;
import com.ygtx.emcs.util.StringUtils;

import java.util.ArrayList;

public class BoxItemListViewAdapter extends BaseAdapter {
    private ArrayList<StockLineModel> mList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public BoxItemListViewAdapter(ArrayList<StockLineModel> list, Context context) {
        this.mList=list;
        this.mContext=context;
        this.mLayoutInflater=LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int position, View view, ViewGroup parent) {
        MainHolder mainHolder = null;
        final StockLineModel stockLineModel = mList.get(position);
        if (view == null) {
            view=mLayoutInflater.inflate(R.layout.ygtx_stock_product_item,null);
            mainHolder = new MainHolder();
            mainHolder.tv_box_code = view.findViewById(R.id.tv_box_code);
            mainHolder.tv_product_code = view.findViewById(R.id.tv_product_code);
            mainHolder.qty = view.findViewById(R.id.tv_qty);
            mainHolder.tv_product_name = view.findViewById(R.id.tv_product_name);
            mainHolder.img_ok = view.findViewById(R.id.img_ok);
            mainHolder.img_ng = view.findViewById(R.id.img_ng);
            view.setTag(mainHolder);
        }else{
            mainHolder= (MainHolder) view.getTag();
        }
        mainHolder.tv_box_code.setVisibility(View.GONE);
        mainHolder.tv_product_code.setText(stockLineModel.getItemCode());
        mainHolder.qty.setText(stockLineModel.getItemQuantity());
        if(!StringUtils.isEmpty(stockLineModel.getItemName())){
            mainHolder.tv_product_name.setText(stockLineModel.getItemName());
            mainHolder.tv_product_name.setVisibility(View.VISIBLE);
        }else{
            mainHolder.tv_product_name.setVisibility(View.GONE);
        }
        if("ok".equals(stockLineModel.getSelStatus())){
            mainHolder.img_ng.setVisibility(View.GONE);
            mainHolder.img_ok.setVisibility(View.VISIBLE);
//            mainHolder.img_ok.setAlpha(0.5f);
        }
        if("ng".equals(stockLineModel.getSelStatus())){
            mainHolder.img_ng.setVisibility(View.VISIBLE);
            mainHolder.img_ok.setVisibility(View.GONE);
//            mainHolder.img_ng.setAlpha(0.5f);
        }
        return view;
    }

    static class MainHolder {
        public TextView tv_product_code;
        public TextView qty;
        public TextView tv_box_code;
        public TextView tv_product_name;
        public ImageView img_ok;
        public ImageView img_ng;
    }

}
