package com.develop.food.base.widgets

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.core.view.marginTop
import com.develop.base.R
import com.develop.base.databinding.DialogCancelConfirmBinding
import com.develop.food.base.ui.FullScreenTransparentDialog
import com.develop.food.base.utils.ResDimension

class CancelConfirmDialog(
) : FullScreenTransparentDialog() {

    lateinit var binding: DialogCancelConfirmBinding

    var title = ""
    var cancelStr = ""
    var confirmStr = ""
    var showConfirm = true
    var showCancel = true
    var onDialogClickListener: OnDialogClickListener? = null
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        binding = DialogCancelConfirmBinding.inflate(
            inflater, container, false
        )
        binding.tvYes.setOnClickListener {
            onDialogClickListener?.onConfirm()
            removeSelf()
        }
        binding.tvCancel.setOnClickListener {
            onDialogClickListener?.onCancel()
            removeSelf()
        }
        binding.tvTitle.text = title
        if (cancelStr.isNotEmpty()) {
            binding.tvCancel.text = cancelStr
        }
        if (confirmStr.isNotEmpty()) {
            binding.tvYes.text = confirmStr
        }

        //只显示确认按钮
        if (showConfirm && !showCancel) {
            binding.tvCancel.visibility = View.GONE;
            binding.tvYes.visibility = View.VISIBLE;
            val layoutParams = binding.tvYes.layoutParams as RelativeLayout.LayoutParams;
            layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
            binding.tvCancel.layoutParams = layoutParams
        }

        if (!showConfirm && showCancel) {
            binding.tvYes.visibility = View.GONE;
            binding.tvCancel.visibility = View.VISIBLE;
            val layoutParams = binding.tvCancel.layoutParams as RelativeLayout.LayoutParams;
            layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
            binding.tvCancel.layoutParams = layoutParams
        }



        return binding.root
    }


    interface OnDialogClickListener {
        fun onConfirm()
        fun onCancel()
    }
}