package com.naz.sdkdemo.adaapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.naz.sdkdemo.R;
import com.naz.sdkdemo.bean.TrademarkInfo;
import com.naz.sdkdemo.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class FullApplyTrademarkSelectAdapter extends BaseQuickAdapter<TrademarkInfo, BaseViewHolder> {
   public FullApplyTrademarkSelectAdapter(@Nullable List<TrademarkInfo> data) {
      super(R.layout.item_full_apply_trademark_select, data);
   }

   @Override
   protected void convert(@NonNull BaseViewHolder holder, TrademarkInfo info) {
      changeUi(holder, info.select);
      if (null != info.exe_sale_order_b) {
         holder.setText(R.id.tv_order_id, "销售订单号："+info.exe_sale_order_b.no);
         holder.setText(R.id.tv_content, info.exe_sale_order_b.customer_name);
      }
      holder.setText(R.id.tv_total_num, "商标数量：" + (int) info.qty);
      holder.setText(R.id.tv_apply_num, "已领数量：" + info.out_stock_qty_total);
   }

   @Override
   protected void convertPayloads(@NonNull BaseViewHolder helper, TrademarkInfo item, @NonNull List<Object> payloads) {
      super.convertPayloads(helper, item, payloads);
      Object payload = payloads.get(0);
      if (TextUtils.equals(payload.toString(), "change")) {
         item.select = !item.select;
         changeUi(helper, item.select);
      }
   }

   private void changeUi(BaseViewHolder helper, Boolean select) {
      if (select) {
         helper.itemView.setBackgroundResource(R.drawable.bg_item_select_red);
         helper.setImageResource(R.id.iv_select, R.mipmap.icon_selected);
      } else {
         helper.itemView.setBackgroundResource(R.mipmap.bg_white_round_background);
         helper.setImageResource(R.id.iv_select, R.mipmap.icon_unselect);
      }
      int size = MyUtils.dp2px(mContext, 16);
      helper.itemView.setPadding(size, 0, size, size);
   }

   public List<TrademarkInfo> getSelectList() {
      List<TrademarkInfo> list = new ArrayList<>();
      for (TrademarkInfo info : getData()) {
         if (info.select) {
            list.add(info);
         }
      }
      return list;
   }
}
