package com.yidian.shenghuoquan.buserorder.app.adapter

import android.graphics.Typeface
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.app.bean.OrderWebData
import com.yidian.shenghuoquan.buserorder.utils.Utils
import com.yidian.shenghuoquan.buserorder.view.RoundImageView

class OrderListAdapter : BaseQuickAdapter<OrderWebData, BaseViewHolder>(R.layout.border_recycle_order_item){
  override fun convert(holder: BaseViewHolder, item: OrderWebData) {
    mapDataToHoder(item, holder)
  }

  private fun mapDataToHoder(data: OrderWebData, holder: BaseViewHolder) {
    holder.itemView.findViewById<TextView>(R.id.tv_market_name).text = data.marketing_name
    holder.itemView.findViewById<TextView>(R.id.tv_pay_status).text = data.online_status
    when(data.order_item_list.size) {
      0 -> {
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image1).visibility = View.GONE
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image2).visibility = View.GONE
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image3).visibility = View.GONE
      }
      1 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image2).visibility = View.GONE
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image3).visibility = View.GONE
        /*if (Utils.isWebUrl(data.order_item_list[0].desc_pic_url)) {
          Glide.with(context).load(data.order_item_list[0].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image1))
        }*/
      }
      2 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_goog2_name).text = data.order_item_list[1].goods_name
        holder.itemView.findViewById<LinearLayout>(R.id.ll_order_image3).visibility = View.GONE
        /*if (Utils.isWebUrl(data.order_item_list[0].desc_pic_url) && Utils.isWebUrl(data.order_item_list[1].desc_pic_url)) {
          Glide.with(context).load(data.order_item_list[0].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image1))
          Glide.with(context).load(data.order_item_list[1].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image2))
        }*/
      }
      else -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_goog2_name).text = data.order_item_list[1].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_good3_name).text = data.order_item_list[2].goods_name
        /*if (Utils.isWebUrl(data.order_item_list[0].desc_pic_url) && Utils.isWebUrl(data.order_item_list[1].desc_pic_url) && Utils.isWebUrl(data.order_item_list[2].desc_pic_url)) {
          Glide.with(context).load(data.order_item_list[0].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image1))
          Glide.with(context).load(data.order_item_list[1].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image2))
          Glide.with(context).load(data.order_item_list[2].desc_pic_url).into(holder.itemView.findViewById(R.id.round_image3))
        }*/
      }
    }
    holder.itemView.findViewById<TextView>(R.id.tv_order_goods_count).text = "共${data.goods_num}件"
    holder.itemView.findViewById<TextView>(R.id.tv_pay_time).text = data.pay_time
    var money:TextView = holder.itemView.findViewById<TextView>(R.id.tv_pay_money_count)
    money.setTypeface(Typeface.DEFAULT_BOLD)
    money.text = "${data.payment}"
    holder.itemView.findViewById<RelativeLayout>(R.id.rl_show_order_detail).setOnClickListener {
      //跳转订单详情页面
    }
    if (data.online_status.equals("4")) {
      holder.itemView.findViewById<TextView>(R.id.tv_pay_money_status).text = "已退款:"
      holder.itemView.findViewById<TextView>(R.id.tv_pay_status).text = "已退款"
    } else {
      holder.itemView.findViewById<TextView>(R.id.tv_pay_money_status).text = "已支付:"
      holder.itemView.findViewById<TextView>(R.id.tv_pay_status).text = "已支付"
    }
  }
}
