package com.zxbw.modulemain.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.zxbw.modulemain.R
import com.zxbw.modulemain.uitls.TimeUtils
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.utils.Utils


class CashEnterListAdapter : BaseRecyclerAdapter<Any, CashEnterListAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<Any>

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        if (position < 2) {
            holder.id_img_cash_enter?.setImageResource(R.drawable.icon_withdraw_task_yshixiao)
            holder.id_tv_data?.text = TimeUtils.getWeekOfDate(TimeUtils.getDate(position - 2))
        } else if (position > 2) {
            holder.id_img_cash_enter?.setImageResource(R.drawable.icon_withdraw_task_kstx2)
            holder.id_tv_data?.text = TimeUtils.getWeekOfDate(TimeUtils.getDate(position - 2))
        } else {
            holder.id_img_cash_enter?.setImageResource(R.drawable.icon_withdraw_task_kstx)
            holder.id_tv_data?.text = TimeUtils.getWeekOfDate(TimeUtils.getDate(0))
        }
        holder.id_rl_cash_task_view?.setOnClickListener {
            listener.onItemClick(it, position, null)
        }


    }

    override fun getItemCount(): Int {
        return 5
    }

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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_rl_cash_task_view: LinearLayout?
        var id_tv_data: TextView?
        var id_img_cash_enter: ImageView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_rl_cash_task_view = itemView.findViewById<LinearLayout>(R.id.id_ll_cash_enter_view)
            id_tv_data = itemView.findViewById<TextView>(R.id.id_tv_data)
            id_img_cash_enter = itemView.findViewById<ImageView>(R.id.id_img_cash_enter)
        }
    }

}