package com.bc_chat.im.activity.envelopes.adapter;

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

import com.bc_chat.bc_base.entity.wallet.WithdrawRecordBean;
import com.bc_chat.im.R;
import com.zhaohaoting.framework.imagepicker.camera.util.LogUtil;
import com.zhaohaoting.framework.view.recyclerview.BasicRecyclerAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Author: hxm
 * Date: 2019/5/8
 * Desc:
 * Version: 1.0
 */
public class WithdrawalRecordAdapter extends BasicRecyclerAdapter<WithdrawRecordBean> {

    public WithdrawalRecordAdapter(Context context, List<WithdrawRecordBean> list) {
        super(context, list, R.layout.item_withdraw_record);
    }

    @Override
    public void convert(ViewHolder viewHolder, WithdrawRecordBean item, int position) {
        if (item != null) {
            try {
                TextView tvPlatform = viewHolder.getView(R.id.tvPlatform);
                TextView tvAmount = viewHolder.getView(R.id.tvAmount);
                TextView tvFailedReason = viewHolder.getView(R.id.tvFailedReason);
                TextView tvDate = viewHolder.getView(R.id.tvDate);
                TextView tvStatus = viewHolder.getView(R.id.tvStatus);

                tvPlatform.setText("平台：" + item.getPlatform_name());
                tvAmount.setText("金额：￥ " + item.getAmount());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                long lcc_time = Long.valueOf(item.getCreated_at());
                tvDate.setText(sdf.format(new Date(lcc_time * 1000L)));

                int state = Integer.parseInt(item.getState());
                if (state == 1) {
                    tvStatus.setText("待审核");
                    tvStatus.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    tvFailedReason.setVisibility(View.GONE);
                } else if (state == 2) {
                    tvStatus.setText("已下发");
                    tvStatus.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    tvFailedReason.setVisibility(View.GONE);
                } else if (state == 3) {
                    tvStatus.setText("已拒绝");
                    tvStatus.setTextColor(mContext.getResources().getColor(R.color.jrmf_red));
                    tvFailedReason.setVisibility(View.VISIBLE);
                    tvFailedReason.setText(item.getRefuse_reason());
                }

            } catch (Exception e) {
                LogUtil.d(e.getMessage());
            }
        }
    }
}
