package com.casic.common.detector.gd.widgets

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import com.casic.common.detector.gd.R
import com.casic.common.detector.gd.bean.MarkerLocalBean
import com.casic.common.detector.gd.databinding.DialogMarkerDetailBinding
import com.casic.common.detector.gd.utils.LocaleConstant
import com.pengxh.kt.lite.extensions.binding
import com.pengxh.kt.lite.extensions.getScreenHeight
import com.pengxh.kt.lite.extensions.getScreenWidth

class MarkerDetailDialog constructor(context: Context) :
    Dialog(context, R.style.UserDefinedDialogStyle) {

    private lateinit var marker: MarkerLocalBean

    fun setMarker(marker: MarkerLocalBean) {
        this.marker = marker
    }

    private val binding: DialogMarkerDetailBinding by binding()

    private fun Dialog.initDialogLayoutParams() {
        val window = this.window ?: return
        window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window.decorView.setBackgroundColor(Color.TRANSPARENT)
        val params = window.attributes
        params.width = ((context.getScreenWidth() * 0.8).toInt())
        params.height = ((context.getScreenHeight() * 0.7).toInt())
        window.attributes = params
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.initDialogLayoutParams()
        setCanceledOnTouchOutside(true)

        binding.objectTypeView.text = LocaleConstant.POINT_TYPE_ARRAY[marker.objectType.toInt() - 1]
        binding.pipelineTypeView.text = marker.pipelineType
        binding.pipelineDiameterView.text = marker.pipelineDiameter
        binding.pipelineMaterialView.text = marker.pipelineMaterial
        binding.buryMethodView.text = marker.buryMethod
        binding.buryDeepView.text = marker.buryDepth
        binding.areaView.text = marker.area
        binding.lineView.text = marker.line
        binding.roadView.text = marker.road
        binding.constructTimeView.text = marker.constructTime
        binding.ownerView.text = marker.owner
        binding.identifierIdView.text = marker.markerId
        binding.identifierTypeView.text = marker.markerType
        binding.identifierDeepView.text = marker.markerDepth
        binding.personView.text = marker.installationDept
        binding.installTimeView.text = marker.updateTime
        binding.remarkView.text = marker.remark
    }
}