package com.zxhl.main.page.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.box.AddressEntity
import com.zxhl.cms.net.model.box.DepotEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.main.R


class AddressAdapter : BaseRecyclerAdapter<AddressEntity, AddressAdapter.ViewHolder> {
    private var mContext: Context? = null
    private val listener: OnRecycleItemClickListener<AddressEntity>

    constructor(
        content: Context?,
        listener: OnRecycleItemClickListener<AddressEntity>
    ) : super() {
        this.listener = listener
        mContext = content
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.item_user_address_name?.text = bean.username + bean.mobile
        holder.item_user_address?.text = "${bean.country},${bean.province},${bean.city},${bean.address},${bean.address2}"
        if (bean.defaultAddress.equals("1")) {
            holder.item_img_address_moren?.visibility = View.VISIBLE
        } else {
            holder.item_img_address_moren?.visibility = View.GONE
        }
        holder.item_img_edit?.setOnClickListener {
            JumpUtils.EditAddressReslutJump(
                bean.id,
                bean.username,
                bean.mobile,
                bean.address,
                bean.address2,
                bean.country,
                bean.city,
                bean.province,
                bean.defaultAddress
            )

        }
        holder.item_img_del?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
        holder.item_rl?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_address, parent, false)
        )
    }

    class ViewHolder : RecyclerView.ViewHolder {
        var item_img_address_moren: ImageView?
        var item_user_address_name: TextView?
        var item_user_address: TextView?
        var item_img_edit: ImageView?
        var item_img_del: ImageView?
        var item_rl: LinearLayout?

        constructor(
            itemView: View
        ) : super(itemView) {
            item_img_address_moren = itemView.findViewById<ImageView>(R.id.id_img_address_moren)
            item_img_edit = itemView.findViewById<ImageView>(R.id.id_img_bianji)
            item_img_del = itemView.findViewById<ImageView>(R.id.id_img_del)
            item_user_address_name = itemView.findViewById<TextView>(R.id.id_tv_user_address_name)
            item_user_address = itemView.findViewById<TextView>(R.id.id_tv_user_address)
            item_rl = itemView.findViewById<LinearLayout>(R.id.id_rl_item)


        }
    }
}