package com.gh.gamecenter.message.view.message

import android.app.Activity
import android.content.Context
import android.text.Html
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.facebook.drawee.generic.RoundingParams
import com.facebook.drawee.view.SimpleDraweeView
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.callback.OnListClickListener
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.exposure.ExposureSource
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.provider.IDirectProvider
import com.gh.gamecenter.core.utils.GsonUtils.toJson
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.feature.entity.MessageEntity
import com.gh.gamecenter.feature.exposure.ExposureEvent
import com.gh.gamecenter.feature.provider.ICommentUtilsProvider
import com.gh.gamecenter.feature.provider.IGameDetailProvider
import com.gh.gamecenter.feature.provider.ILinkDirectUtilsProvider
import com.gh.gamecenter.feature.provider.ISubjectProvider
import com.gh.gamecenter.login.user.UserManager
import com.gh.gamecenter.message.R
import com.gh.gamecenter.message.databinding.MessageLineItemBinding
import com.gh.gamecenter.message.entity.MessageGameEntity
import com.gh.gamecenter.message.entity.MessageItemData
import com.gh.gamecenter.message.entity.MessageKeFuEntity
import com.gh.gamecenter.message.entity.MessageKeFuEntity.ServiceEntity
import com.gh.gamecenter.message.entity.MessageLinkEntity
import com.google.android.flexbox.FlexboxLayout
import com.lightgame.utils.Utils
import com.therouter.TheRouter

class MessageListAdapter(
    context: Context,
    private val mGameId: String,
    private val mGameName: String,
    private val mGameType: String,
    private val mType: String,
    private val mListViewModel: MessageListViewModel,
    private val mEntrance: String
) : ListAdapter<MessageItemData>(context) {

    private val mImageSize = (mContext.resources.displayMetrics.widthPixels - 36F.dip2px()) / 3
    private val mDirectUtils = TheRouter.get(IDirectProvider::class.java)
    private val mLinkDirectUtils = TheRouter.get(ILinkDirectUtilsProvider::class.java)
    private val mGameDetailProvider = TheRouter.get(IGameDetailProvider::class.java)

    override fun getItemViewType(position: Int): Int {
        return when (mType) {
            SortedMessageListAdapter.TYPE_USER -> ITEM_NORMAL_MESSAGE
            else -> ITEM_SYSTEM_MESSAGE
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return if (viewType == ITEM_NORMAL_MESSAGE) {
            MessageItemViewHolder(
                parent.toBinding(),
                object : OnListClickListener {
                    override fun <T : Any?> onListClick(view: View?, position: Int, data: T) {
                        MessageItemViewHolder.messageItemClickSkip(
                            view,
                            data as MessageEntity,
                            "消息中心", "", "",
                            mGameId, mGameName, mGameType, mType
                        )
                    }
                },
                ""
            )
        } else {
            KeFuViewHolder(
                parent.toBinding(),
                object : OnListClickListener {
                    override fun <T : Any?> onListClick(view: View?, position: Int, data: T) {
                        if (view?.id == R.id.message_kaifu_item) {
                            val keFuEntity = data as MessageKeFuEntity
                            if (!keFuEntity.isRead) {
                                mListViewModel.postMessageRead(keFuEntity.id)
                                notifyDataSetChanged()
                            }
                        }
                    }
                })
        }
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        mEntityList.safelyGetInRelease(position)?.let {
            if (holder is MessageItemViewHolder && it.normalMessage != null) {
                val entity = it.normalMessage
                entity?.read = true
                holder.setMessageItem(it.normalMessage, mContext, mEntrance)
                listOf(holder.mBinding.root, holder.mBinding.messageOriginal).forEach { view ->
                    view.setOnLongClickListener {
                        DialogHelper.showDeleteDialog(
                            mContext,
                            "删除消息",
                            "消息删除将不可恢复，确定删除吗？",
                            "确定",
                            "取消",
                            { entity?.id?.let { id -> mListViewModel.deleteMessage(id) } },
                            {},
                            false
                        )
                        false
                    }
                }
            }
            if (holder is KeFuViewHolder) {
                holder.binding.run {
                    messageKaifuItem.background = com.gh.gamecenter.common.R.drawable.reuse_listview_item_style.toDrawable(mContext)
                    messageKefuSuggestion.setBackgroundColor(com.gh.gamecenter.common.R.color.ui_background.toColor(mContext))
                    messageKefuSuggestion.setTextColor(com.gh.gamecenter.common.R.color.title.toColor(mContext))
                    messageKefuName.setTextColor(com.gh.gamecenter.common.R.color.text_black.toColor(mContext))
                    messageKefuContent.setTextColor(com.gh.gamecenter.common.R.color.title.toColor(mContext))
                    messageKefuTime.setTextColor(com.gh.gamecenter.common.R.color.hint.toColor(mContext))
                    copyTv.setTextColor(com.gh.gamecenter.common.R.color.text_secondary.toColor(mContext))
                }
                if (it.privateMessage != null) {
                    initKeFuViewHolder(holder, it.privateMessage!!)
                } else if (it.gameMessage != null) {
                    initGameMessageViewHolder(holder, it.gameMessage!!)
                }
            }
        }
    }

    override fun getItemCount(): Int = mEntityList.size

    private fun initKeFuViewHolder(holder: KeFuViewHolder, entity: MessageKeFuEntity) {
        val shouldShouldUserId = entity.showUserId ?: false

        val images: List<String>? = entity.images
        if (!images.isNullOrEmpty()) {
            holder.binding.messageKefuImagesContainer.removeAllViews()
            holder.binding.messageKefuImagesContainer.visibility = View.VISIBLE
            for (i in images.indices) {
                val image = images[i]
                val draweeView = SimpleDraweeView(mContext)
                val padding = 2F.dip2px()
                draweeView.setPadding(padding, padding, padding, padding)
                val params: FlexboxLayout.LayoutParams = FlexboxLayout.LayoutParams(mImageSize, mImageSize)
                draweeView.layoutParams = params
                draweeView.setImageURI(image)
                draweeView.setOnClickListener {
                    TheRouter.build(RouteConsts.activity.imageViewerActivity)
                        .apply {
                            extras.putStringArrayList(EntranceConsts.KEY_URL_LIST, images as ArrayList<String>)
                        }
                        .withInt(EntranceConsts.KEY_CURRENT, i)
                        .withString(EntranceConsts.KEY_ENTRANCE, "(消息中心-系统)")
                        .navigation()
                }
                val hierarchy = draweeView.hierarchy
                val roundingParams = RoundingParams.fromCornersRadius(18F)
                hierarchy.roundingParams = roundingParams
                hierarchy.setPlaceholderImage(com.gh.gamecenter.common.R.drawable.occupy)
                holder.binding.messageKefuImagesContainer.addView(draweeView)
            }
            holder.binding.messageKefuImagesContainer.requestLayout()
        } else {
            holder.binding.messageKefuImagesContainer.visibility = View.GONE
        }

        holder.binding.copyIdContainer.goneIf(!shouldShouldUserId)
        if (shouldShouldUserId) {
            holder.binding.copyIdContainer.setOnClickListener {
                UserManager.getInstance().userId.copyTextAndToast("已复制")
            }
        }

        val directToWebViewClick = TextHelper.DirectToWebViewHighlightedTextClick(
            mContext, "消息中心-系统"
        )

        holder.binding.messageKefuContent.text = Html.fromHtml(entity.message)

        holder.binding.messageKefuContent.setOnSpannableClickListener { spannableText: String ->
            directToWebViewClick.onCallback(spannableText)
        }

        holder.setClickData(entity)
        if (!TextUtils.isEmpty(entity.suggestion)) {
            holder.binding.messageKefuSuggestion.visibility = View.VISIBLE
            holder.binding.messageKefuSuggestion.text = entity.suggestion
        } else {
            holder.binding.messageKefuSuggestion.visibility = View.GONE
        }

        val newLinks = entity.newLinks
        if (!newLinks.isNullOrEmpty()) {
            holder.binding.messageSkipList.visibility = View.VISIBLE
            holder.binding.messageSkipList.removeAllViews()
            for (linkEntity in newLinks) {
                if (TextUtils.isEmpty(linkEntity.text) && TextUtils.isEmpty(linkEntity.title)) continue
                val textView: TextView = getLinkChildView(
                    holder,
                    if (!TextUtils.isEmpty(linkEntity.title)) linkEntity.title!! else linkEntity.text ?: ""
                )
                textView.setOnClickListener {
                    if (!entity.isRead) {
                        mListViewModel.postMessageRead(entity.id)
                        notifyDataSetChanged()
                    }
                    linkNewSkip(linkEntity)
                    if ("求加速回复" == entity.type) {
                        com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick("", "", "", "", mGameId, mGameName, mType, "求加速版本")
                        SensorsBridge.trackMessageItemClick(
                            gameId = mGameId,
                            gameName = mGameName,
                            gameType = mGameType,
                            sessionMessageType = mType,
                            messageType = "求加速回复"
                        )
                    } else if ("求版本回复" == entity.type) {
                        com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick("", "", "", "",  mGameId, mGameName, mType, "投票")
                        SensorsBridge.trackMessageItemClick(
                            gameId = mGameId,
                            gameName = mGameName,
                            gameType = mGameType,
                            sessionMessageType = mType,
                            messageType = "投票"
                        )
                    }
                }
            }
        } else {
            val links: List<MessageLinkEntity>? = entity.links
            if (!links.isNullOrEmpty()) {
                holder.binding.messageSkipList.visibility = View.VISIBLE
                holder.binding.messageSkipList.removeAllViews()
                for (link in links) {
                    if (TextUtils.isEmpty(link.qq) &&
                        TextUtils.isEmpty(link.id) &&
                        TextUtils.isEmpty(link.url) &&
                        "7moor" != link.type &&
                        "个人主页" != link.type
                    ) continue
                    val textView = getLinkChildView(holder, link.document ?: "")
                    textView.setOnClickListener {
                        if (!entity.isRead) {
                            mListViewModel.postMessageRead(entity.id)
                            notifyDataSetChanged()
                        }
                        linkSkip(link)
                        if ("求加速回复" == entity.type) {
                            com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick(
                                "", "",
                                (if (link.id == null) "" else link.id)!!, "",
                                mGameId, mGameName, mType,
                                "求加速版本"
                            )
                            SensorsBridge.trackMessageItemClick(
                                gameId = mGameId,
                                gameName = mGameName,
                                gameType = mGameType,
                                sessionMessageType = mType,
                                messageType = "求加速版本"
                            )
                        } else if ("求版本回复" == entity.type) {
                            com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick(
                                "", "",
                                (if (link.id == null) "" else link.id)!!, "",
                                mGameId, mGameName, mType,
                                "投票"
                            )
                            SensorsBridge.trackMessageItemClick(
                                gameId = mGameId,
                                gameName = mGameName,
                                gameType = mGameType,
                                sessionMessageType = mType,
                                messageType = "投票"
                            )
                        }
                    }
                }
            } else {
                holder.binding.messageSkipList.visibility = View.GONE
            }
        }

        val serviceEntity: ServiceEntity? = entity.serviceEntity
        holder.binding.messageKefuName.setText(R.string.kefu_default_name)
        if (serviceEntity != null) {
            val name = serviceEntity.name
            if (!TextUtils.isEmpty(name)) {
                holder.binding.messageKefuName.text = name
            }
            ImageUtils.display(holder.binding.messageKefuIcon, serviceEntity.icon)
        } else {
            ImageUtils.display(holder.binding.messageKefuIcon, R.drawable.message_kefu_icon)
        }

        if (entity.serviceEntity != null && entity.serviceEntity!!.auth != null) {
            ImageUtils.display(holder.binding.messageUserBadge, entity.serviceEntity!!.auth!!.icon)
            holder.binding.messageUserBadge.visibility = View.VISIBLE
        } else {
            holder.binding.messageUserBadge.visibility = View.GONE
        }

        val commentUtilsProvider = TheRouter.get(ICommentUtilsProvider::class.java)
        commentUtilsProvider?.setCommentTime(holder.binding.messageKefuTime, entity.time)

        if (!TextUtils.isEmpty(entity.suggestion)) {
            val suggest = StringBuffer()
            suggest.append("反馈原文：")
            suggest.append(entity.suggestion)
            holder.binding.messageKefuSuggestion.visibility = View.VISIBLE
            holder.binding.messageKefuSuggestion.text = suggest
        } else {
            holder.binding.messageKefuSuggestion.visibility = View.GONE
        }

        holder.binding.messageKefuUnread.isVisible = !entity.isRead

        holder.binding.messageKefuIcon.setOnClickListener {
            if (serviceEntity != null && mDirectUtils != null) {
                mDirectUtils.directToHomeActivity(mContext, serviceEntity.id, mEntrance, "消息中心-系统")
            }
        }
        holder.binding.messageKefuName.setOnClickListener {
            if (serviceEntity != null && mDirectUtils != null) {
                mDirectUtils.directToHomeActivity(mContext, serviceEntity.id, mEntrance, "消息中心-系统")
            }
        }

        holder.binding.root.setOnLongClickListener {
            DialogHelper.showDeleteDialog(
                mContext,
                "删除消息",
                "消息删除将不可恢复，确定删除吗？",
                "确定",
                "取消",
                { mListViewModel.deleteMessage(entity.id) },
                {},
                false
            )
            false
        }
    }

    private fun initGameMessageViewHolder(holder: KeFuViewHolder, entity: MessageGameEntity) {
        holder.binding.run {
            messageKefuSuggestion.visibility = View.GONE
            messageUserBadge.visibility = View.GONE
            messageKefuUnread.visibility = View.GONE
            if (entity.user != null) {
                messageKefuName.text = entity.user?.name
                ImageUtils.display(messageKefuIcon, entity.user?.icon)
            } else {
                ImageUtils.display(messageKefuIcon, R.drawable.message_kefu_icon)
            }

            val directToWebViewClick = TextHelper.DirectToWebViewHighlightedTextClick(
                mContext, "消息中心-系统"
            )
            messageKefuContent.text = Html.fromHtml(entity.content?.link?.text)
            messageKefuContent.setOnSpannableClickListener { spannableText: String ->
                directToWebViewClick.onCallback(spannableText)
            }

            if (entity.content?.type == "game_server_opening" && entity.content?.lines?.isNotEmpty() == true) {
                messageLinesContainer.removeAllViews()
                messageLinesContainer.visibility = View.VISIBLE
                val lines = if (entity.content!!.lines.size > 3) {
                    entity.content!!.lines.subList(0, 3)
                } else {
                    entity.content!!.lines
                }
                lines.forEachIndexed { index, line ->
                    MessageLineItemBinding.inflate(
                        mLayoutInflater,
                        messageLinesContainer,
                        true
                    ).apply {
                        ImageUtils.display(icon, line[0])
                        date.text = line[1]
                        serverName.text = line[2]
                        root.layoutParams = (root.layoutParams as MarginLayoutParams).apply {
                            bottomMargin = if (index < lines.size - 1) 10F.dip2px() else 0
                        }
                    }
                }
            } else {
                messageLinesContainer.visibility = View.GONE
            }

            if (!entity.content?.images.isNullOrEmpty()) {
                holder.binding.messageKefuImagesContainer.removeAllViews()
                holder.binding.messageKefuImagesContainer.visibility = View.VISIBLE
                entity.content?.images?.forEachIndexed { i, image ->
                    val draweeView = SimpleDraweeView(mContext)
                    val padding = 2F.dip2px()
                    draweeView.setPadding(padding, padding, padding, padding)
                    val params: FlexboxLayout.LayoutParams = FlexboxLayout.LayoutParams(mImageSize, mImageSize)
                    draweeView.layoutParams = params
                    draweeView.setImageURI(image)
                    draweeView.setOnClickListener {
                        TheRouter.build(RouteConsts.activity.imageViewerActivity)
                            .apply {
                                extras.putStringArrayList(EntranceConsts.KEY_URL_LIST, entity.content?.images!! as ArrayList<String>)
                            }
                            .withInt(EntranceConsts.KEY_CURRENT, i)
                            .withString(EntranceConsts.KEY_ENTRANCE, "(消息中心-系统)")
                            .navigation()
                    }
                    val hierarchy = draweeView.hierarchy
                    val roundingParams = RoundingParams.fromCornersRadius(18F)
                    hierarchy.roundingParams = roundingParams
                    hierarchy.setPlaceholderImage(com.gh.gamecenter.common.R.drawable.occupy)
                    holder.binding.messageKefuImagesContainer.addView(draweeView)
                }
                holder.binding.messageKefuImagesContainer.requestLayout()
            } else {
                holder.binding.messageKefuImagesContainer.visibility = View.GONE
            }

            val commentUtilsProvider = TheRouter.get(ICommentUtilsProvider::class.java)
            commentUtilsProvider?.setCommentTime(messageKefuTime, entity.time.create)

            if (!entity.links.isNullOrEmpty()) {
                messageSkipList.visibility = View.VISIBLE
                messageSkipList.removeAllViews()
                for (linkEntity in entity.links!!) {
                    if (TextUtils.isEmpty(linkEntity.text) && TextUtils.isEmpty(linkEntity.title)) continue
                    val textView = getLinkChildView(
                        holder,
                        if (!TextUtils.isEmpty(linkEntity.title)) linkEntity.title!! else linkEntity.text ?: ""
                    )
                    textView.setOnClickListener {
                        linkNewSkip(linkEntity)
                        if ("求加速回复" == entity.type) {
                            com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick(
                                "",
                                "",
                                "",
                                "",
                                mGameId, mGameName, mType,
                                "求加速版本"
                            )
                            SensorsBridge.trackMessageItemClick(
                                gameId = mGameId,
                                gameName = mGameName,
                                gameType = mGameType,
                                sessionMessageType = mType,
                                messageType = "求加速版本"
                            )
                        } else if ("求版本回复" == entity.type) {
                            com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick("", "", "", "",  mGameId, mGameName, mType, "投票")
                            SensorsBridge.trackMessageItemClick(
                                gameId = mGameId,
                                gameName = mGameName,
                                gameType = mGameType,
                                sessionMessageType = mType,
                                messageType = "投票"
                            )
                        } else if ("game_server_calendar" == linkEntity.type) {
                            com.gh.gamecenter.message.utils.NewLogUtils.logMessageInformClick(
                                "",
                                "",
                                "",
                                "",
                                mGameId, mGameName, mType,
                                "游戏开服日历"
                            )
                            SensorsBridge.trackMessageItemClick(
                                gameId = mGameId,
                                gameName = mGameName,
                                gameType = mGameType,
                                sessionMessageType = mType,
                                messageType = "游戏开服日历"
                            )
                        }
                    }
                }
            } else {
                messageSkipList.visibility = View.GONE
            }

            root.setOnLongClickListener {
                DialogHelper.showDeleteDialog(
                    mContext,
                    "删除消息",
                    "消息删除将不可恢复，确定删除吗？",
                    "确定",
                    "取消",
                    { mListViewModel.deleteMessage(entity.id) },
                    {},
                    false
                )
                false
            }
        }
    }

    private fun getLinkChildView(viewHolder: KeFuViewHolder, text: String): TextView {
        val textView = TextView(mContext)
        textView.setTextColor(com.gh.gamecenter.common.R.color.text_theme.toColor(mContext))
        textView.textSize = 12F
        textView.text = text
        val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        params.setMargins(0, 8F.dip2px(), 0, 0)
        viewHolder.binding.messageSkipList.addView(textView, params)
        return textView
    }

    private fun linkSkip(data: MessageLinkEntity) {
        val type = data.type
        if (TextUtils.isEmpty(type)) {
            Utils.toast(mContext, "数据请求失败")
            return
        }
        if (mDirectUtils == null || mLinkDirectUtils == null || mGameDetailProvider == null) return
        when (type) {
            "游戏" -> if (!TextUtils.isEmpty(data.id)) {
                val exposureEvent = ExposureEvent.createEvent(
                    null,
                    source = listOf(ExposureSource("消息中心"), ExposureSource("游戏详情"))
                )
                mGameDetailProvider.startGameDetailActivity(mContext, data.id ?: "", "消息中心", exposureEvent)
            }

            "QQ号" -> if (!TextUtils.isEmpty(data.qq)) {
                mDirectUtils.directToQqConversation(mContext, data.qq!!)
            }

            "web" -> if (!TextUtils.isEmpty(data.url)) {
                mDirectUtils.directToWebView(mContext, data.url!!, "(消息-公告)")
            }

            "QQ群" -> if (!TextUtils.isEmpty(data.key)) {
                mDirectUtils.directToQqGroup(mContext, data.key)
            }

            "新闻" -> if (!TextUtils.isEmpty(data.id)) {
                TheRouter.build(RouteConsts.activity.newsDetailActivity)
                    .withString(EntranceConsts.KEY_ENTRANCE, "(消息-公告)")
                    .withString(EntranceConsts.KEY_NEWSID, data.id)
                    .navigation()
            }

            "专题" -> {
                val subjectProvider = TheRouter.get(ISubjectProvider::class.java)
                if (!TextUtils.isEmpty(data.id) && subjectProvider != null) {
                    subjectProvider.startSubjectActivity(mContext, data.id, null, false, "(消息-客服)")
                }
            }

            "7moor" -> if (mContext is Activity) {
                // 去掉七陌支持，跳转到企点
                // ImManager.startChatActivity((Activity) mContext, null, null);
                mDirectUtils.directToWebView(mContext, Constants.TENCENT_QIDIAN_ADDRESS, mEntrance)
            }

            "问题" -> if (!TextUtils.isEmpty(data.id)) {
                TheRouter.build(RouteConsts.activity.questionDetailActivity)
                    .withString(EntranceConsts.KEY_QUESTIONS_ID, data.id)
                    .withString(EntranceConsts.KEY_ENTRANCE, mEntrance)
                    .withString(EntranceConsts.KEY_PATH, "(消息-客服)")
                    .navigation()
            }

            "回答" -> if (!TextUtils.isEmpty(data.id)) {
                mDirectUtils.directToAnswerDetail(mContext, data.id!!, mEntrance, "(消息-客服)")
            }

            "社区文章" -> if (!TextUtils.isEmpty(data.id) && data.community != null) {
                mDirectUtils.directToCommunityArticle(mContext, data.id, data.community!!.id, mEntrance, "(消息-客服)", "")
            }

            "社区专题" -> if (!TextUtils.isEmpty(data.id) && data.community != null) {
                mLinkDirectUtils.directToCommunityColumn(mContext, data.community, data.id!!, mEntrance, "(消息-客服)")
            }

            "视频" -> if (!TextUtils.isEmpty(data.id)) {
                mDirectUtils.directToVideoDetail(mContext, data.id!!, mEntrance, "系统_二级列表")
            }

            "安利墙评论" -> if (!TextUtils.isEmpty(data.id)) {
                mDirectUtils.directToAmway(mContext, data.id, mEntrance, "(消息-客服)")
            }

            "个人主页" -> mDirectUtils.directToHomeActivity(
                mContext,
                UserManager.getInstance().userId,
                mEntrance,
                "(消息-客服)"
            )

            "游戏详情评论" -> if (!TextUtils.isEmpty(data.id)) {
                mGameDetailProvider.startGameDetailActivity(
                    mContext,
                    data.id ?: "",
                    "",
                    true,
                    false,
                    false,
                    false,
                    null
                )
            }

            "订单中心",
            "订单详情",
            "光能记录", "光能记录获取",
            "光能记录使用",
            "抽奖中心",
            "我的奖品",
            "兑换商品",
            "中奖订单详情" -> {
                ToastUtils.toast("功能已下线，详情请咨询客服")
            }

            else -> {
                val entity = LinkEntity()
                entity.type = data.type
                if (!TextUtils.isEmpty(data.id)) {
                    entity.link = data.id
                }
                if (!TextUtils.isEmpty(data.url)) {
                    entity.link = data.url
                }
                if (!TextUtils.isEmpty(data.document)) {
                    entity.text = data.document
                }
                entity.community = data.community
                mLinkDirectUtils.directToLinkPage(mContext, entity, mEntrance, "(消息-客服)")
            }
        }
    }

    private fun linkNewSkip(data: LinkEntity) {
        val type = data.type
        if (TextUtils.isEmpty(type)) {
            Utils.toast(mContext, "数据请求失败")
            return
        }
        if (mDirectUtils == null || mLinkDirectUtils == null) return
        when (type) {
            "home" -> mDirectUtils.directToHomeActivity(
                mContext,
                UserManager.getInstance().userId,
                mEntrance,
                "(消息-客服)"
            )

            "7moor", "qidian" -> mDirectUtils.directToWebView(mContext, Constants.TENCENT_QIDIAN_ADDRESS, mEntrance)
            "order_center",
            "order_detail",

            "energy_record", "energy_record_get",
            "energy_record_cost",
            "raffle_center",
            "raffle_prize",
            "exchange_commodity",
            "win_order_detail" -> {
                ToastUtils.toast("功能已下线，详情请咨询客服")
            }

            "game_comment_detail" -> {
                val exposureSource = ExposureSource("消息中心", "")
                val exposureSourceList = ArrayList<ExposureSource>()
                exposureSourceList.add(exposureSource)
                TheRouter.build(RouteConsts.activity.ratingReplyActivity)
                    .withString(EntranceConsts.KEY_GAMEID, data.gameId)
                    .withString(EntranceConsts.KEY_COMMENTID, data.link)
                    .withString(EntranceConsts.KEY_EXPOSURE_SOURCE, toJson(exposureSourceList))
                    .withString(EntranceConsts.KEY_ENTRANCE, "消息中心-系统消息")
                    .navigation()
            }
            else -> {
                var exposureEvent: ExposureEvent? = null
                if (type == "游戏" || type == "game") {
                    exposureEvent = ExposureEvent.createEvent(
                        null,
                        source = listOf(ExposureSource("消息中心"), ExposureSource("游戏详情"))
                    )
                }
                mLinkDirectUtils.directToLinkPage(mContext, data, mEntrance, "消息中心", exposureEvent)
            }
        }
    }

    companion object {
        const val ITEM_NORMAL_MESSAGE = 0
        const val ITEM_SYSTEM_MESSAGE = 1
    }
}