package com.dbs.mplus.fatima.framework.view.dialog;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.PixelFormat;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.view.ContextThemeWrapper;
import android.view.WindowManager;
import android.widget.EditText;

import com.dbs.mplus.fatima.framework.util.MPlusResourceUtil;

/**
 * 메시지 출력을 위한 Dialog 표시용
 *
 * Created by aple on 2015. 7. 19..
 */
public class MPlusDialog {

    /**
     * OK 버튼만 있는 대화상자
     * @param context
     * @param title
     * @param msg
     * @param okListener
     * @return
     */
    public static AlertDialog getOKDialog(Context context, String title, String msg, DialogInterface.OnClickListener okListener) {
        int okId = MPlusResourceUtil.getStringIdByName(context, "mf_ok_button_str");
        AlertDialog dlg = createDialog(context, title, msg, okId, okListener, -1, null);
        dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        return dlg;
    }

    /**
     * Yes, NO 버튼이 있는 대화상자
     *
     * @param context
     * @param title
     * @param msg
     * @param yesListener
     * @param noListener
     * @return
     */
    public static AlertDialog getYesNoDialog(Context context, String title, String msg, DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener) {
        int yesId = MPlusResourceUtil.getStringIdByName(context, "mf_yes_button_str");
        int noId = MPlusResourceUtil.getStringIdByName(context, "mf_no_button_str");

        AlertDialog dlg = createDialog(context, title, msg, yesId, yesListener, noId, noListener);
        dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        return dlg;
    }

    /**
     * 비밀번호 입력 다이얼로그
     * @param context
     * @param title
     * @param msg
     * @param okListener
     * @param cancelListener
     * @return
     */
    public static AlertDialog getPasswordInputDialog(Context context, String title, String msg, DialogInterface.OnClickListener okListener, DialogInterface.OnClickListener cancelListener) {
        int okId = MPlusResourceUtil.getStringIdByName(context, "mf_ok_button_str");
        int cancelId = MPlusResourceUtil.getStringIdByName(context, "mf_cancel_button_str");

        AlertDialog dlg = createDialog(context, title, msg, okId, okListener, cancelId, cancelListener);
        dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        return dlg;
    }

    /**
     * Diakog 만들기
     *
     * @param context
     * @param title
     * @param msg
     * @param button1
     * @param button1Listener
     * @param button2
     * @param button2Listener
     * @return
     */
    private static AlertDialog createDialog(Context context, String title, String msg, int button1, DialogInterface.OnClickListener button1Listener, int button2, DialogInterface.OnClickListener button2Listener) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Light_Dialog));

        builder.setTitle(title);
        builder.setMessage(msg);
        builder.setPositiveButton(button1, button1Listener);
        if(button2Listener != null) {
            builder.setNegativeButton(button2, button2Listener);
        }
        builder.setCancelable(false);

        return builder.create();
    }


}
