package com.bc_chat.mine

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bc_chat.bc_base.ImService.ImRongService
import com.bc_chat.bc_base.WebViewActivity
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.bc_base.contract.WebContract
import com.bc_chat.bc_base.presenter.WebPresenter
import com.bc_chat.bc_base.utils.Const
import com.bc_chat.mine.databinding.ActivityServiceCenterBinding
import com.zhaohaoting.framework.abs.BaseActivity
import com.zhaohaoting.framework.abs.contract.BaseContract
import com.zhaohaoting.framework.ui.utils.DialogUtils
import io.rong.imlib.model.Conversation

/**
 * author：Created by zhaohaoting on 2019/3/22
 * email：526309416@qq.com
 * desc：服务中心
 */
@Route(path = RouteConfig.SERVICE_CENTER_ACTIVITY)
class ServiceCenterActivity : BaseActivity<WebPresenter<WebContract.View>>(), View.OnClickListener, WebContract.View {

    private val binding by lazy {
        rootDataBinding as ActivityServiceCenterBinding
    }

    override fun initPresenter(): WebPresenter<WebContract.View>? = WebPresenter(this)

    override fun getLayoutResId(): Int = R.layout.activity_service_center

    override fun initialize() {
        binding.onClickEvent = this
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_customer -> {
                ARouter.getInstance().navigation(ImRongService::class.java).startConversation(this, Conversation.ConversationType.PRIVATE, Const.SYSTEM_NOTICE_ID, Const.SERVICE_NAME, null)
            }
            R.id.tv_customer_phone -> {
                judgePermission(Const.Permission.Key.CALL_PHONE, *Const.Permission.Value.CALL_PHONE)
            }
            R.id.tv_question -> {
                presenter.loadWebPage(Const.WebPageType.PRIVATE_PROTOCOL)
            }
        }
    }

    override fun loadWebPageSuccess(content: String) {
        WebViewActivity.startActivity(this, content, "问题答疑", 1)
    }

    override fun requestPermissionSuccess(requestCode: Int) {
        DialogUtils.callPhone(this, binding.tvCustomerPhone.text.toString())
    }
}