package com.atmob.keyboard_android.component

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.popup.ModeSwitchPopupWindow

/**
 * 快速切换组件
 */
class QuickSwitchComponent @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : BaseUIComponent(context, attrs, defStyleAttr) {
    private lateinit var vModeSwitchLayout: View

    /**
     * 模式切换的弹窗
     */
    private val mModeSwitchPopupWindow = ModeSwitchPopupWindow(context)

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

    override fun findView(view: View) {
        vModeSwitchLayout = view.findViewById(R.id.mode_switch_layout)
    }

    override fun bindView(view: View) {
        vModeSwitchLayout.setOnClickListener {
            // 弹出模式切换弹窗
            if (mModeSwitchPopupWindow.isShowing()) {
                mModeSwitchPopupWindow.dismiss()
            } else {
                mModeSwitchPopupWindow.show(vModeSwitchLayout)
            }
        }
    }
}