package com.atmob.keyboard_android.component.page.impl

import android.content.Context
import android.util.AttributeSet
import android.view.View
import com.atmob.keyboard_android.R
import com.atmob.keyboard_android.component.base.BaseUIComponent
import com.atmob.keyboard_android.component.base.animator.ComponentAnimator
import com.atmob.keyboard_android.component.base.animator.impl.TransitionAnimator
import com.atmob.keyboard_android.component.page.IVipPageComponent
import com.atmob.keyboard_android.constant.Constants
import com.atmob.keyboard_android.ext.click
import com.atmob.keyboard_android.util.KeyboardHolder
import com.atmob.keyboard_android.util.bridge.FlutterBridgeManager

/**
 * Vip页组件
 */
class VipPageComponent @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : BaseUIComponent<IVipPageComponent>(context, attrs, defStyleAttr), IVipPageComponent {
    private lateinit var vBackBtn: View
    private lateinit var vJoinVipBtn: View

    override fun onInflateViewId(): Int {
        return R.layout.component_vip_page
    }

    override fun findView(view: View) {
        vBackBtn = view.findViewById(R.id.back_btn)
        vJoinVipBtn = view.findViewById(R.id.join_vip_btn)
    }

    override fun bindView(view: View) {
        vBackBtn.click {
            hide()
        }
        vJoinVipBtn.click {
            // 跳转到VIP商店
            FlutterBridgeManager.jump2VipStore()
            hide()
        }

        setData()
    }

    private fun setData() {
    }

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

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

    override fun getComponentAnimator(): ComponentAnimator {
        return if (Constants.COMPONENT_ANIMATOR_ENABLE) {
            TransitionAnimator()
        } else {
            super.getComponentAnimator()
        }
    }

    override fun getComponentInterfaceClazz(): Class<IVipPageComponent> {
        return IVipPageComponent::class.java
    }
}