package com.sixin.module_p.ui.enter.gn

import android.content.Intent
import com.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.ActionBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
import com.lukouguoji.module_base.ktx.logd
import com.lukouguoji.module_base.ktx.loge
import com.lukouguoji.module_base.router.ARouterConstants
import com.sixin.module_p.R
import com.sixin.module_p.ui.enter.gn.document.PdaDocumentHandoverActivity
import com.sixin.module_p.ui.gnc.cunfang.list.PdaGncCunFangListActivity
import com.sixin.module_p.ui.gnc.fubang.add.PdaGncFuBangAddActivity
import com.sixin.module_p.ui.gnc.shouyun.un.list.GncUnShouYunActivity
import com.sixin.module_p.ui.gnj.accidentVisa.list.PdaAccidentVisaListActivity
import com.sixin.module_p.ui.gnj.xieji.list.PdaGnjXieJiListActivity
import com.sixin.module_p.ui.goods.transport.list.PdaGoodsTransportListActivity
import com.sixin.module_p.ui.goods.transportLog.list.PdaTransportLogActivity
import dev.DevUtils

class GnViewModel : BaseViewModel() {

    val actionList = listOf(
        ActionBean(
            "出港收运",
            com.lukouguoji.module_base.R.drawable.img_gnc_shouyun,
            Constant.AuthName.AppDomExpCheckin
        ),
        ActionBean("出港复磅", R.drawable.gnc_fubang, Constant.AuthName.AppDomExpWeighting),
        ActionBean(
            "出港存放",
            com.lukouguoji.module_base.R.drawable.img_gnc_cunfang,
            Constant.AuthName.AppDomExpDeposit
        ),
        ActionBean(
            "进港卸机",
            com.lukouguoji.module_base.R.drawable.img_gnc_xieji,
            Constant.AuthName.MonitorInPack
        ),
        ActionBean(
            "货物转运",
            com.lukouguoji.module_base.R.drawable.img_gnc_huowuzhuanyun,
            Constant.AuthName.ComprehensiveTransfer
        ),
        ActionBean(
            "转运记录",
            com.lukouguoji.module_base.R.mipmap.transport_log,
            Constant.AuthName.TransportLog
        ),
        ActionBean(
            "事故签证",
            R.mipmap.mit_accident_visa,
            Constant.AuthName.ComprehensiveAccidentVisa
        ),
        ActionBean(
            "单证交接",
            R.mipmap.gnc_document_handover,
            Constant.AuthName.DocumentHandover
        ),
        ActionBean(
            "进港移库",
            R.drawable.gnj_yi_ku_icon,                        // 图标复制自 module_gnj（module_p 看不到业务模块资源）
            Constant.AuthName.GnjYiKu,                        // 权限串与 Pad 端菜单一致（AppDomImpMove）
            ARouterConstants.ACTIVITY_URL_GNJ_MOVE_STASH_LIST // 与 Pad 首页菜单同一跳转页（app 模块，走路由）
        ),
    )
        .filter { SharedPreferenceUtil.getString(Constant.Share.authList).contains(it.key) }


    fun onItemClick(position: Int) {
        val bean = actionList.getOrNull(position) ?: return

        // 配了路由的直接跳（5.5 寸适配页走这条，与 GjViewModel 同模式）
        if (bean.route.isNotEmpty()) {
            ARouter.getInstance().build(bean.route).navigation()
            return
        }

        when (val title = actionList[position].title) {
            "出港收运" -> {
                GncUnShouYunActivity.start(DevUtils.getTopActivity())
            }

            "出港复磅" -> {
                PdaGncFuBangAddActivity.start(DevUtils.getTopActivity())
            }

            "出港存放" -> {
                PdaGncCunFangListActivity.start(DevUtils.getTopActivity())
            }

            "进港卸机" -> {
                PdaGnjXieJiListActivity.start(DevUtils.getTopActivity())
            }

            "货物转运" -> {
                PdaGoodsTransportListActivity.start(DevUtils.getTopActivity())
            }

            "转运记录" -> {
                PdaTransportLogActivity.start(DevUtils.getTopActivity())
            }

            "事故签证" -> {
                PdaAccidentVisaListActivity.start(DevUtils.getTopActivity())
            }
            "单证交接" -> {
                DevUtils.getTopActivity()?.let {
                    it.startActivity(Intent(it,PdaDocumentHandoverActivity::class.java))
                }
            }

            else -> {
                loge("点击事件 $title 未处理")
            }
        }
    }
}