package com.xuqm.base.web

import android.content.Context
import android.webkit.JavascriptInterface
import com.xuqm.base.common.AppManager
import com.xuqm.base.common.ToolsHelper
import com.xuqm.base.extensions.log

class XAndroidInterface constructor(val mContext: Context, val viewModel: XWebViewModel) {
    @JavascriptInterface
    fun showToast(callBackId: String, toast: String) {
        ToolsHelper.showMessage(toast)
        viewModel.callBackSuccess(callBackId)
    }

    @JavascriptInterface
    fun setTitle(callBackId: String, title: String) {
        viewModel.setTitle(title)
        viewModel.callBackSuccess(callBackId)
    }

    @JavascriptInterface
    fun scan(callBackId: String) {
        viewModel.scan(callBackId)
    }

    @JavascriptInterface
    fun closed() {
        AppManager.getInstance().finish()
    }

    @JavascriptInterface
    fun setTopMenu(callBackId: String, date: String) {
        date.split(",").log()
        viewModel.setTopMenu(callBackId,date.split(","))
    }
    @JavascriptInterface
    fun getUserInfo(callBackId: String) {
        viewModel.getUserInfo(callBackId)
    }
}