package com.atmob.keyboard_android.component.child.impl.ai

import android.content.Context
import android.util.AttributeSet
import com.atmob.keyboard_android.component.child.ai.ISuperSpeakAiChatComponent
import com.atmob.keyboard_android.component.child.impl.AiChatComponent
import com.atmob.keyboard_android.ext.setGone
import com.atmob.keyboard_android.ext.setVisible
import com.atmob.keyboard_android.util.KeyboardHolder

/**
 * 超会说（教你说）-Ai生成内容页-实现类
 */
class SuperSpeakAiChatComponent @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AiChatComponent<ISuperSpeakAiChatComponent>(context, attrs, defStyleAttr),
    ISuperSpeakAiChatComponent {
    override fun getComponentInterfaceClazz(): Class<ISuperSpeakAiChatComponent> {
        return ISuperSpeakAiChatComponent::class.java
    }

    override fun setupViewModel() {
        // 监听Ai生成列表的更新
        KeyboardHolder.getKeyboardService()?.run {
            getKeyboardViewModel().superSpeakChatListResult.observe(getLifecycleOwner()) {
                if (it.isEmpty()) {
                    vReGenerateBtn.setGone()
                } else {
                    vReGenerateBtn.setVisible()
                }
                loadAiList(it)
            }
        }
    }

    override fun onComponentShow() {
        super.onComponentShow()
        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
            ?.updateSuperSpeakAiChatPageShowing(true)
    }

    override fun onComponentHide() {
        super.onComponentHide()
        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
            ?.updateSuperSpeakAiChatPageShowing(false)
    }
}