package com.yidian.shenghuoquan.buserorder.viewmodel

import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.BindingAdapter
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.utils.DensityUtil

/**
 * author: yinjiacheng
 * date: 2021/8/24 15:34
 * description: 自提点搜索
 */
class PickupPointSearchViewModel : BaseViewModel() {

  companion object {
    /**
     * 设置右外边距
     * @param margin 外边距 单位dp
     */
    @JvmStatic
    @BindingAdapter("layout_marginEnd")
    fun setMarginEnd(view: View, margin: Int) {
      val lp = view.layoutParams as ConstraintLayout.LayoutParams
      lp.marginEnd = DensityUtil.dp2px(margin.toFloat())
      view.layoutParams = lp
    }
  }

  private val _clearSearch = MutableLiveData<Unit>()
  val clearSearch: LiveData<Unit> = _clearSearch

  private val _cancelSearch = MutableLiveData<Unit>()
  val cancelSearch: LiveData<Unit> = _cancelSearch

  /**
   * 清空搜索
   * 清空搜索框输入 不收起软键盘 请求附近自提点数据
   */
  fun clearSearch() {
    _clearSearch.value = Unit
  }

  /**
   * 取消搜索
   * 清空搜索框输入 收起软键盘 请求附近自提点数据
   */
  fun cancelSearch() {
    _cancelSearch.value = Unit
  }
}
