package com.abbidot.tracker.dialog

import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.annotation.StyleRes
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseDialog
import com.abbidot.tracker.databinding.DialogMyLayoutBinding
import com.abbidot.tracker.widget.TypefaceRoundButton
import com.abbidot.tracker.widget.TypefaceTextView

/**
 *Created  by .yzq on 2021/12/24/024.
 * @link
 * @description: 自定义对话框，背景阴影
 */
class MyAlertDialog(
    context: Context, @StyleRes themeResId: Int = R.style.my_Dialog_style
) : BaseDialog<DialogMyLayoutBinding>(
    DialogMyLayoutBinding::inflate, context, dialogHeightDp = 260, themeResId = themeResId
) {

    private lateinit var mTitleTextView: TypefaceTextView
    private lateinit var mContentTextView: TypefaceTextView
    private lateinit var mCancelRoundButton: TypefaceRoundButton
    private lateinit var mOkRoundButton: TypefaceRoundButton

    override fun initView() {
        setCancelable(false)

        mTitleTextView = mViewBinding.myDialogTitle
        mContentTextView = mViewBinding.myDialogContent
        mCancelRoundButton = mViewBinding.myDialogCancel
        mOkRoundButton = mViewBinding.myDialogOk

        //设置按下点击透明效果
        mCancelRoundButton.setChangeAlphaWhenPress(true)
        mOkRoundButton.setChangeAlphaWhenPress(true)
    }

    fun setOnDialogCancelListener(cancelListener: OnDialogCancelListener) {
        mCancelRoundButton.setOnClickListener {
            cancelListener.onCancelClick(this)
        }
    }

    fun setOnDialogOkListener(okListener: OnDialogOkListener) {
        mOkRoundButton.setOnClickListener {
            okListener.onOkClick(this)
        }
    }

    fun setTipTitle(title: String) {
        if (!TextUtils.isEmpty(title)) {
            mTitleTextView.visibility = View.VISIBLE
            mTitleTextView.text = title
        }
    }

    fun setTipTitle(resId: Int) {
        setTipTitle(context.getString(resId))
    }

    fun setContent(title: String) {
        mContentTextView.text = title
    }

    fun setContent(resId: Int) {
        setContent(context.getString(resId))
    }

    fun setOkText(text: String) {
        mOkRoundButton.text = text
    }

    fun setOkText(resId: Int) {
        setOkText(context.getString(resId))
    }

    fun setCancelText(text: String) {
        mCancelRoundButton.text = text
    }

    fun setCancelText(resId: Int) {
        setCancelText(context.getString(resId))
    }
}