package kr.co.hanwha.hifive.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;

/**
 * Created by sanghoonkwon on 2018. 1. 10..
 */

public class HFDefaultDialog extends Dialog {
    private String mTitle;
    private String mMessage;
    private String mNegative;
    private String mPositive;

    private OnDialogCallback mCallback;

    public HFDefaultDialog(@NonNull Context context) {
        super(context);
    }

    public HFDefaultDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    protected HFDefaultDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public HFDefaultDialog(@NonNull Context context, @NonNull String title, @NonNull String message,
                           String negative, String positive, @Nullable OnDialogCallback callback) {
        super(context, R.style.DialogFadeAnim);
        setCancelable(false);
        this.mTitle = title;
        this.mMessage = message;
        this.mNegative = negative;
        this.mPositive = positive;
        this.mCallback = callback;
    }

    public HFDefaultDialog(@NonNull Context context, @NonNull int titleRes, @NonNull int messageRes,
                           int negativeRes, int positiveRes, @Nullable OnDialogCallback callback) {
        super(context, R.style.DialogFadeAnim);
        setCancelable(false);
        this.mTitle = context.getString(titleRes);
        this.mMessage = context.getString(messageRes);
        this.mNegative = context.getString(negativeRes);
        this.mPositive = context.getString(positiveRes);
        this.mCallback = callback;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_hf_default);

        TextView textViewTitle = (TextView) findViewById(R.id.title_textView);
        TextView textViewMessage = (TextView) findViewById(R.id.message_textView);
        TextView textViewNegative = (TextView) findViewById(R.id.negative_textView);
        TextView textViewPositive = (TextView) findViewById(R.id.positive_textView);

        textViewTitle.setText(mTitle);
        textViewMessage.setText(mMessage);
        textViewNegative.setText(mNegative);
        textViewPositive.setText(mPositive);

        textViewNegative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mCallback != null) mCallback.onNegative();
                HFDefaultDialog.this.dismiss();
            }
        });

        textViewPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mCallback != null) mCallback.onPositive();
                HFDefaultDialog.this.dismiss();
            }
        });
    }

    /**************************************************
     * Callback
     **************************************************/
    public interface OnDialogCallback {
        void onNegative();

        void onPositive();
    }
}
