package com.yidian.yac.newscontent.action

import android.os.Handler
import com.yidian.common.XRouterPathConstants
import com.yidian.common.YacBaseApplication
import com.yidian.common.chameleon.ChameleonEvent
import com.yidian.common.chameleon.ChameleonEventService
import com.yidian.xpage.XPageManager

class ChameleonActionExecutor:ChameleonEventService {
     val handler by lazy{Handler(YacBaseApplication.context.mainLooper)}
    companion object{
        const val MODULE_GENERAL = "generalAction"
        const val MODULE_CARD = "card"
        const val ACTION_SHARE = "share"
        const val ACTION_COMMENT = "comment"
        const val ACTION_THUMB_UP = "thumb_up"
        const val ACTION_GOTO_AUTHOR = "goto_author"
        const val ACTION_VIDEO_DETAIL = "video_detail"
        const val ACTION_DOC = "doc"
    }

    private var lastClickTime = 0L

    override fun dispatchEvent(event: ChameleonEvent) {

        when{
            event.module == MODULE_GENERAL && event.action == ACTION_DOC ->{
                val currentClickTime = System.currentTimeMillis()
                if(currentClickTime - lastClickTime < 1000) return
                lastClickTime = currentClickTime
                handler.post {
                    val paramsMap = hashMapOf<String, Any>(
//                        Pair(NewsContentActivity.ContentType, NewsContentActivity.TextType),
//                        Pair( NewsContentActivity.DocId, event.params?.optString("docid")?:"" )
                    )
                    XPageManager.push(XRouterPathConstants.NEWS_CONTENT, paramsMap)
                }

            }
            event.module == MODULE_GENERAL && event.action == ACTION_VIDEO_DETAIL ->{
                val currentClickTime = System.currentTimeMillis()
                if(currentClickTime - lastClickTime < 1000) return
                lastClickTime = currentClickTime

                handler.post {
                    val paramsMap = hashMapOf<String, Any>(
//                        Pair(NewsContentActivity.ContentType, NewsContentActivity.VideoType),
//                        Pair( NewsContentActivity.DocId, event.params?.optString("docid")?:"" )
                    )
                    XPageManager.push(XRouterPathConstants.NEWS_CONTENT, paramsMap)
                }
            }
            event.module == MODULE_CARD && event.action == ACTION_GOTO_AUTHOR ->{
                val currentClickTime = System.currentTimeMillis()
                if(currentClickTime - lastClickTime < 1000) return
                lastClickTime = currentClickTime
                handler.post {
                    val paramsMap = hashMapOf<String, Any>(
                        Pair( "fromId", event.params?.optString("fromId")?:"" )
                    )
//                    XPageManager.push(XRouterPathConstants.AUTHOR_HOME_PAGE, paramsMap)
                }
            }

        }


    }


}