package com.tsi.navi.activity.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import com.tsi.navi.R;

public class BaseDialog extends Dialog {

    protected Context context;
    protected IDialogClickListener clickListener;

    public BaseDialog(@NonNull Context context, @NonNull IDialogClickListener clickListener) {
        super(context);
        this.context = context;
        this.clickListener = clickListener;
    }

    protected void setupButton(@StringRes int titleId, boolean hideCancel) {
        TextView tvTitle = findViewById(R.id.tv_title);
        if (tvTitle != null) {
            tvTitle.setText(titleId);
        }

        Button ok = findViewById(R.id.btn_ok);
        if (ok != null) {
            ok.setOnClickListener(v -> {
                if (this.clickListener != null) this.clickListener.onPositiveClick();
                dismiss();
            });
        }

        Button cancel = findViewById(R.id.btn_cancel);
        if (cancel != null) {
            if (hideCancel) {
                cancel.setVisibility(View.GONE);
            }
            cancel.setOnClickListener(v -> {
                if (this.clickListener != null) this.clickListener.onNegativeClick();
                dismiss();
            });
        }

    }
}
