package com.rv.home.rv.module.ui.main.home.order.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.ruiwenliu.wrapper.util.BaseGlideHolder;
import com.ruiwenliu.wrapper.util.TimeManager;
import com.rv.component.utils.DateUtils;
import com.rv.home.R;
import com.rv.home.R2;
import com.rv.home.rv.module.ui.main.home.order.bean.OrderListBean;
import com.rv.home.rv.module.ui.main.home.order.bean.ToTravelBean;

import java.util.List;

/**
 * Created :Auser
 * Date: 2019/5/31.
 * Desc:已出行
 */

public class HaveToTravelAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity,BaseGlideHolder> {
    public static final int TYPE_FOR_PAYMENT=1;
    public static final int TYPE_TO_TRAVEL=2;
    public static final int TYPE_TO_MEMBER = 3;

    public HaveToTravelAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_FOR_PAYMENT, R.layout.rv_item_order_for_payment);
        addItemType(TYPE_TO_TRAVEL, R.layout.rv_item_order_to_travel);
        addItemType(TYPE_TO_MEMBER, R.layout.rv_item_order_to_member);
    }

    @Override
    protected void convert(BaseGlideHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()){
            case TYPE_FOR_PAYMENT:
                OrderListBean.DataBeanX.DataBean dataBean= (OrderListBean.DataBeanX.DataBean) item;
                if (dataBean ==null){
                    return;
                }
                helper.setText(R.id.tv_order_time,String.format("%1$s%2$s",mContext.getString(R.string.rv_order_time),dataBean.getCrtTime()));
                if (dataBean.getOrderRentVehicleDetail() !=null && dataBean.getOrderRentVehicleDetail().getStart_city_name()!=null) {
                    helper.setText(R.id.tv_city, dataBean.getOrderRentVehicleDetail().getStart_city_name());
                }
                helper.setText(R.id.tv_order_state,mContext.getString(R.string.rv_order_have_travel));
                helper.loadRoundImage(mContext,dataBean.getIcon(), (ImageView) helper.getView(R.id.iv_goods),10);
                helper.setText(R.id.tv_car_type,dataBean.getName());
                if (dataBean.getOrderRentVehicleDetail() !=null) {
                    helper.setText(R.id.tv_get_time, DateUtils.timestampToString1(dataBean.getOrderRentVehicleDetail().getStart_time()));
                    helper.setText(R.id.tv_get_address, dataBean.getOrderRentVehicleDetail().getStart_addr());
                    helper.setText(R.id.tv_out_time, DateUtils.timestampToString1(dataBean.getOrderRentVehicleDetail().getEnd_time()));
                    helper.setText(R.id.tv_out_address, dataBean.getOrderRentVehicleDetail().getEnd_addr());
                }
                helper.setText(R.id.tv_price,String.format("¥%1$s",dataBean.getRealAmount()));
                helper.setText(R.id.tv_process,mContext.getString(R.string.rv_to_out_car));
                helper.addOnClickListener(R.id.tv_process);
                break;
            case TYPE_TO_TRAVEL:
                OrderListBean.DataBeanX.DataBean dataBean2 = (OrderListBean.DataBeanX.DataBean) item;
                if (dataBean2 == null) {
                    return;
                }
                if (dataBean2.getOrderTourDetail() ==null ){
                    return;
                }
                helper.setText(R.id.tv_order_time, String.format("%1$s%2$s", mContext.getString(R.string.rv_order_time), dataBean2.getCrtTime()));
                helper.setText(R.id.tv_city, dataBean2.getOrderTourDetail().getStartCityName());
                helper.setText(R.id.tv_order_state,mContext.getString(R.string.rv_order_have_travel));
                helper.loadRoundImage(mContext,dataBean2.getPicture(), (ImageView) helper.getView(R.id.iv_goods),50);
                helper.setText(R.id.tv_car_type,dataBean2.getName());
                helper.setText(R.id.tv_out_time, mContext.getString(R.string.rv_to_time) +DateUtils.timestampToString1( dataBean2.getOrderTourDetail().getStartTime()));
                helper.setText(R.id.tv_count_person, String.format("%1$s%2$s", mContext.getString(R.string.rv_to_person), dataBean2.getOrderTourDetail().getTotalNumber(), mContext.getString(R.string.rv_person)));
                helper.setText(R.id.tv_price, String.format("¥%1$s", dataBean2.getRealAmount()));
                helper.setVisible(R.id.tv_camp_process,false);
//                helper.setText(R.id.tv_camp_process, mContext.getString(R.string.rv_to_pay_for));
//                helper.addOnClickListener(R.id.tv_camp_process);
//                helper.setGone(R.id.tv_camp_process, TextUtils.isEmpty(mContext.getString(R.string.rv_to_pay_for))?false:true);
                break;
        }
    }

    public void addNewData(OrderListBean bean){
        mData.clear();
        addData(bean.getData().getData());
        notifyDataSetChanged();

    }
}
