package com.yidianling.medical.archives

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.utils.StatusBarUtils
import com.ydl.ydlcommon.view.dialog.NormalDialog
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R
import com.yidianling.medical.archives.bean.MedicalArchivesListBean
import com.yidianling.uikit.custom.http.ServiceImpl
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.medical_edit_archives_activity.*


/**
 *编辑问诊人
 * */
class MedicalEditArchivesActivity : BaseActivity() {


    companion object {
        private lateinit var archivesBeanExtra: MedicalArchivesListBean

        @JvmStatic
        fun start(context: Context, archivesBean: MedicalArchivesListBean) {
            val starter = Intent(context, MedicalEditArchivesActivity::class.java)
                .putExtra("archivesBean", archivesBean)
            context.startActivity(starter)
        }
    }

    override fun layoutResId(): Int {
        return R.layout.medical_edit_archives_activity
    }

    override fun initDataAndEvent() {
        initStatus()

        archivesBeanExtra = intent.getSerializableExtra("archivesBean") as MedicalArchivesListBean

        iv_back.setOnClickListener { finish() }
        tv_save.setOnClickListener { finish() }
        tv_delete.setOnClickListener {

            val builder = NormalDialog.Builder(this@MedicalEditArchivesActivity, "center", true)
            builder.setTitle("")
            builder.setMessage("\n是否删除该条问诊人信息\n")
            builder.setPositiveButton(
                "是"
            ) { dialog, which ->
                //删除
                toDelete()
                dialog.dismiss()
            }.setNegativeButton(
                "否"
            ) { dialog, which ->
                dialog.dismiss()
            }
            builder.setRight_color("#3464EC")
            builder.setLeft_color("#8595A9")
            builder.setContent_color("#10233A")
            builder.create().show()


        }
        name.text = archivesBeanExtra.name
        idcard.text = archivesBeanExtra.idcardNo


        merried.text = archivesBeanExtra.merriedName
        relation.text = archivesBeanExtra.relationName

    }

    @SuppressLint("CheckResult")
    private fun toDelete() {
        ServiceImpl.instance.deleteArchives(archivesBeanExtra.patientId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ response ->
                if ("200" == response.code) {
                    finish()
                    ToastUtil.toastShort("成功")
                } else {
                    ToastUtil.toastShort(response.msg)
                }
            }, { e ->
                e.printStackTrace()

            })
    }
    private fun initStatus() {
        StatusBarUtils.setTransparentForImageView(this@MedicalEditArchivesActivity, null)
        StatusBarUtils.statusBarLightMode(this@MedicalEditArchivesActivity)
    }
}