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

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

import com.base.utils.ui.datetime.selector.util.TextUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ruiwenliu.wrapper.util.BaseGlideHolder;
import com.ruiwenliu.wrapper.util.TransformationUtil2;
import com.ruiwenliu.wrapper.util.glide.GlideOptions;
import com.rv.component.utils.DisplayUtil;
import com.rv.home.R;
import com.rv.home.rv.module.ui.main.home.bean.HomeHotGoodListBean;

/**
 * Created :Auser
 * Date: 2019/5/17.
 * Desc:热门车型适配
 */

public class HotCarTypeAdapter extends BaseQuickAdapter<HomeHotGoodListBean.DataBean, BaseGlideHolder> {

    private String hotType;

    public HotCarTypeAdapter() {
        super(R.layout.rv_item_hot_car_type);
    }

    @Override
    protected void convert(BaseGlideHolder helper, HomeHotGoodListBean.DataBean bean) {
//        helper.loadRoundImage(mContext,bean.getIcon(), (ImageView) helper.getView(R.id.iv_goods),6);

        ImageView image = helper.getView(R.id.iv_goods);
        GlideOptions options = GlideOptions.placeholderOf(com.ruiwenliu.wrapper.R.drawable.glide_icon_placeholder).
                error(com.ruiwenliu.wrapper.R.drawable.glide_icon_error);
        TransformationUtil2 utils = new TransformationUtil2(image);
        Glide.with(mContext)
                .asBitmap()
                .load(bean.getIcon())
                .apply(options)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(DisplayUtil.dip2px(mContext,7))).override(image.getWidth(), image.getHeight()))
                .into(utils);

        helper.setText(R.id.tv_name, bean.getName());
        helper.setText(R.id.tv_content, bean.getName1());
        if (!TextUtil.isEmpty(bean.getPrice())) {
            helper.setText(R.id.tv_price, String.format("¥%1$s%2$s", bean.getPrice(), getUnit()));
        } else {
            helper.setText(R.id.tv_price, "");
        }

        if ("2".equals(hotType) || "4".equals(hotType)) {
            helper.setGone(R.id.tv_content, false);
            helper.setGone(R.id.tv_price, true);
        } else if("3".equals(hotType)) {
            helper.setGone(R.id.tv_content, false);
            helper.setGone(R.id.tv_price, false);
        } else{
            helper.setGone(R.id.tv_content, true);
            helper.setGone(R.id.tv_price, false);
        }
    }

    public void setType(String hotType) {
        this.hotType = hotType;
    }

    private String getUnit() {
        if (!TextUtils.isEmpty(hotType)) {
            switch (hotType) {
                case "4":
                    return mContext.getString(R.string.rv_one_car);
                case "2":
                    return mContext.getString(R.string.rv_one_person);
                case "3":
                    return mContext.getString(R.string.rv_day);
                default:
                    return mContext.getString(R.string.rv_one_car);
            }
        }
        return mContext.getString(R.string.rv_one_car);
    }


    //    @Override
//    public int getItemCount() {
//        return 4;
//    }
    @Override
    public int getItemCount() {
        return 4;
    }
}
