package com.adealink.weparty.im.session.comp.fragment.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.adealink.frame.util.onClick
import com.adealink.weparty.im.databinding.ViewSessionSkillTopBarBinding
import com.adealink.weparty.module.profile.data.UserPlaymateSkill

class SkillTopBarView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0,
) : ConstraintLayout(context, attrs, defStyleAttr) {

    private val binding =
        ViewSessionSkillTopBarBinding.inflate(LayoutInflater.from(context), this)

    private var data: UserPlaymateSkill? = null

    private var onOrderClick: ((data: UserPlaymateSkill) -> Unit)? = null

    fun setOnOrderClick(onOrderClick: ((data: UserPlaymateSkill) -> Unit)) {
        this.onOrderClick = onOrderClick
    }

    fun setPlaymateCategory(data: UserPlaymateSkill) {
        this.data = data
        binding.clPlaymate.onClick {
            onOrderClick?.invoke(data)
        }
        binding.ivPlaymateCategory.setImageUrl(data.icon)
        binding.tvPlaymateCategoryName.text = data.name
        binding.vPlaymatePrice.setPrice(data.price, data.unit)
    }
}