package com.yidian.shenghuoquan.border.app.adapter

import android.content.Context
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.yidian.shenghuoquan.border.R
import com.yidian.shenghuoquan.border.app.bean.OrderWebData

class OrderListAdapter(var context: Context, var orderList:List<OrderWebData>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    var view:View = LayoutInflater.from(context).inflate(R.layout.border_recycle_order_item, parent, false)
    var holder = MyViewHoder(view)
    return holder
  }

  override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
      mapDataToHoder(orderList[position], holder as MyViewHoder)
  }

  override fun getItemCount(): Int {
    return orderList.size
  }

  class MyViewHoder(itemView: View) : RecyclerView.ViewHolder(itemView) {

  }

  private fun mapDataToHoder(data: OrderWebData, holder: MyViewHoder) {
    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) {
      1 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
      }
      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
      }
      3 -> {
        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
      }
    }
    holder.itemView.findViewById<TextView>(R.id.tv_order_goods_count).text = data.goods_num.toString()
    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 = "已退款:"
    } else {
      holder.itemView.findViewById<TextView>(R.id.tv_pay_money_status).text = "已支付:"
    }

  }
}
