package com.ez.ertc.setting

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import com.ez.baselib.utils.AppSpUtils
import com.ez.ertc.ConstantApp
import com.ez.ertc.R
import kotlinx.android.synthetic.main.dialog_host_select.*

class HostSelectDialog(private val mContext: Context) : Dialog(mContext) {

    public interface OnSaveHostListener {
        fun onSaveHost(hostData: String)
    }

    private var saveHostListener: OnSaveHostListener ? = null

    public fun setSaveHostListener(saveHostListener: OnSaveHostListener) {
        this.saveHostListener = saveHostListener
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_host_select)
        apiUrlTest12.setOnClickListener {
            AppSpUtils.saveHost(mContext, ConstantApp.apiUrlTest12)
            saveHostListener?.onSaveHost(AppSpUtils.getHost(mContext))
            dismiss()
        }
        apiUrlTest12_open.setOnClickListener {
            AppSpUtils.saveHost(mContext, ConstantApp.apiUrlTest12_open)
            saveHostListener?.onSaveHost(AppSpUtils.getHost(mContext))
            dismiss()
        }
        apiUrlTest13.setOnClickListener {
            AppSpUtils.saveHost(mContext, ConstantApp.apiUrlTest13)
            saveHostListener?.onSaveHost(AppSpUtils.getHost(mContext))
            dismiss()
        }
        apiUrlTestapigw.setOnClickListener {
            AppSpUtils.saveHost(mContext, ConstantApp.apiUrlTestapigw)
            saveHostListener?.onSaveHost(AppSpUtils.getHost(mContext))
            dismiss()
        }
        apiUrlOpen.setOnClickListener {
            AppSpUtils.saveHost(mContext, ConstantApp.apiUrlOpen)
            saveHostListener?.onSaveHost(AppSpUtils.getHost(mContext))
            dismiss()
        }
    }
}