package com.casic.electric.detector.view

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import com.casic.electric.detector.R
import com.casic.electric.detector.bean.LabelBean
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.pengxh.kt.lite.base.KotlinBaseActivity
import com.pengxh.kt.lite.extensions.getScreenHeight
import com.pengxh.kt.lite.extensions.getScreenWidth
import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.utils.Constant
import kotlinx.android.synthetic.main.activity_object_detail.*

class ObjectDetailActivity : KotlinBaseActivity() {

    private val kTag = "ObjectDetailActivity"
    private val context: Context = this@ObjectDetailActivity
    private val gson by lazy { Gson() }

    override fun initData(savedInstanceState: Bundle?) {
        window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window.decorView.setBackgroundColor(Color.TRANSPARENT)
        window.setGravity(Gravity.CENTER)
        val params = window.attributes
        params.width = ((getScreenWidth() * 0.9).toInt())
        params.height = ((getScreenHeight() * 0.7).toInt())
        window.attributes = params

        val objectJson = intent.getStringExtra(Constant.INTENT_PARAM)!!
        try {
            val labelBean =
                gson.fromJson<LabelBean>(objectJson, object : TypeToken<LabelBean>() {}.type)

            markerObjTypeView.text = labelBean.markerObjType
            markerNumberView.text = labelBean.markerNumber
            objectNameView.text = labelBean.objectName
            voltageLevelView.text = labelBean.voltageLevel
            transformerModelView.text = labelBean.transformerModel
            wellCoverMaterialView.text = labelBean.wellCoverMaterial
            sizeView.text = labelBean.size
            bottomDepthView.text = labelBean.bottomDepth
            jointCountView.text = labelBean.jointCount
            casingMaterialView.text = labelBean.casingMaterial
            casingSpecView.text = labelBean.casingSpec
            constructTimeView.text = labelBean.constructTime
            inspectionUnitView.text = labelBean.inspectionUnit
            areaView.text = labelBean.area
            roadView.text = labelBean.road
            memo1View.text = labelBean.memo1
            memo2View.text = labelBean.memo2
            memo3View.text = labelBean.memo3
            markerIdView.text = labelBean.markerId
            markerTypeView.text = labelBean.markerType
            ownerView.text = labelBean.owner
            markerDepthView.text = labelBean.markerDepth
            electricTagCountView.text = labelBean.electricTagCount
            installedTimeView.text = labelBean.installedTime
            longitudeView.text = labelBean.longitude
            latitudeView.text = labelBean.latitude
            markerMemo1View.text = labelBean.markerMemo1
            markerMemo2View.text = labelBean.markerMemo2
            markerMemo3View.text = labelBean.markerMemo3
        } catch (e: NumberFormatException) {
            e.printStackTrace()
        }
    }

    override fun initEvent() {
        closeView.setOnClickListener { finish() }

        showImageView.setOnClickListener {
            //TODO 服务器返回的表格里面并没有图片字段，此功能暂时屏蔽
            "此标识器无图片".show(context)
        }
    }

    override fun initLayoutView(): Int = R.layout.activity_object_detail

    override fun observeRequestState() {

    }

    override fun setupTopBarLayout() {

    }
}