package com.ydl.ydlcommon.view.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import com.ydl.ydlcommon.R
import kotlinx.android.synthetic.main.platform_ydl_common_dialog_layout.*

class YDLCommonDialog(context: Context, private var listener: OnYDLCommonDialogListener?): Dialog(context, R.style.platform_dialog_default_style) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.platform_ydl_common_dialog_layout)

        val params = window.attributes
        params.width = WindowManager.LayoutParams.MATCH_PARENT
        params.height = WindowManager.LayoutParams.WRAP_CONTENT
        window.setGravity(Gravity.CENTER)
        window.attributes = params

        ydl_common_dialog_cancel.setOnClickListener {
            listener?.onCancel()
        }
        ydl_common_dialog_sure.setOnClickListener {
            listener?.onSure()
        }

    }

    /**
     * 标题
     */
    fun setTitle(title: String): YDLCommonDialog {
        ydl_common_dialog_title.text = title
        return this
    }

    /**
     * 内容
     */
    fun setDesc(desc: String): YDLCommonDialog {
        ydl_common_dialog_desc.text = desc
        return this
    }

    /**
     * 左侧按钮
     */
    fun setCancelText(cancelText: String): YDLCommonDialog {
        ydl_common_dialog_cancel.text = cancelText
        return this
    }

    /**
     * 右侧按钮
     */
    fun setSureText(sureText: String): YDLCommonDialog {
        ydl_common_dialog_sure.text = sureText
        return this
    }

    /**
     * 根据app包设置右侧按钮主题色，*****************必须调用*****************
     */
    fun setTheme(flavor: String): YDLCommonDialog {
        if (flavor == "ydl") {
            ydl_common_dialog_sure.setBackgroundResource(R.drawable.platform_ydl_common_dialog_sure_btn_ydl_bg)
        }else {
            ydl_common_dialog_sure.setBackgroundResource(R.drawable.platform_ydl_common_dialog_sure_btn_xlzx_bg)
        }
        return this
    }

    interface OnYDLCommonDialogListener {
        fun onCancel()
        fun onSure()
    }


}