package com.ccwangluo.accelerator.ui.dialog

import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.R
import com.xuexiang.xui.widget.dialog.materialdialog.CustomMaterialDialog
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog

class CommonDialog(
    var context: Context
) : CustomMaterialDialog(context) {


    override fun getDialogBuilder(context: Context?): MaterialDialog.Builder {
        return MaterialDialog.Builder(context!!)
            .customView(R.layout.dialog_common, false);
    }


    override fun initViews(context: Context?) {

    }

    fun setTitle(title: String): CommonDialog {
        val tx = findViewById<TextView>(R.id.title)
        tx.setText(title)
        tx.visibility = View.VISIBLE
        return this
    }

    fun setContent(content: String): CommonDialog {
        val dia_text = findViewById<TextView>(R.id.dia_text)
        dia_text.text = content
        return this
    }

    fun setBtnLeft(btnText: String, callback: () -> Unit): CommonDialog {
        val btn_left = findViewById<TextView>(R.id.btn_left)
        btn_left.text = btnText
        btn_left.setOnClickListener {
            dismiss<CommonDialog>()
            callback()
        }
        return this
    }

    fun setBtnRight(btnText: String, callback: () -> Unit): CommonDialog {
        val btn_right = findViewById<TextView>(R.id.btn_right)
        btn_right.text = btnText
        btn_right.setOnClickListener {
            dismiss<CommonDialog>()
            callback()
        }
        return this
    }

    init {
        mDialog.setCancelable(false)
    }

}