package com.yidian.shenghuoquan.bgoods.ui.coupon.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.bcommon.utils.StringUtils
import com.yidian.shenghuoquan.bgoods.R
import com.yidian.shenghuoquan.bgoods.dto.SelectCategoryDto

/**
 * 类目搜索列表适配器
 */
class CategorySearchListAdapter : BaseQuickAdapter<SelectCategoryDto, BaseViewHolder>(R.layout.commodity_layout_category_search_list_item) {

  private var keyword: String = ""

  /**
   * 设置搜索关键字
   */
  fun setKeyword(str: String) {
    keyword = str
  }

  override fun convert(holder: BaseViewHolder, item: SelectCategoryDto) {
    holder.getView<TextView>(R.id.tv_first_category_name).text = item.firstCategoryName
    val matcherSearchText = if (keyword.isNotBlank()) {
      StringUtils.matcherSearchText(Color.parseColor("#1852F1"), item.secondCategoryName, keyword)
    } else {
      item.secondCategoryName
    }
    holder.getView<TextView>(R.id.tv_second_category_name).text = matcherSearchText
  }

}
