package in.techware.carrefour.dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Typeface;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import in.techware.carrefour.R;
import in.techware.carrefour.app.App;
import in.techware.carrefour.config.TypefaceCache;
import in.techware.carrefour.util.AppConstants;

/**
 * Created by Jemsheer K D on 02 August, 2018.
 * Package in.techware.carrefour.dialogs
 * Project Carrefour
 */
public class SelectPrintLabelTypeDialog {

    private final Activity mContext;
    private Typeface typeface;
    private SelectPrintLabelTypeDialogDialogActionListener selectPrintLabelTypeDialogDialogActionListener;
    private Dialog dialogSelectPrintLabelTypeDialog;

    public SelectPrintLabelTypeDialog(Activity mContext) {
        this.mContext = mContext;

        try {
            typeface = TypefaceCache.getInstance().getTypeface(App.getInstance(), "Roboto-Regular.ttf");
        } catch (Exception e) {
            e.printStackTrace();
        }
        setSelectPrintLabelTypeDialogDialog();
    }

    public void show() {
        dialogSelectPrintLabelTypeDialog.show();
    }

    private void setSelectPrintLabelTypeDialogDialog() {

        dialogSelectPrintLabelTypeDialog = new Dialog(mContext, R.style.ThemeDialogCustom_NoBackground);
        dialogSelectPrintLabelTypeDialog.setContentView(R.layout.dialog_select_print_label_type);
        dialogSelectPrintLabelTypeDialog.setTitle("Select Print Label Type : ");

        final Button btnSubmit = (Button) dialogSelectPrintLabelTypeDialog.findViewById(R.id.btn_dialog_select_print_label_type_submit);
        final RadioGroup rbgSelect = (RadioGroup) dialogSelectPrintLabelTypeDialog.
                findViewById(R.id.rbg_dialog_select_print_label_type);

        btnSubmit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
//                mVibrator.vibrate(25);

                switch (rbgSelect.getCheckedRadioButtonId()) {
                    case R.id.rb_dialog_select_print_label_type_inventory_label:
                        selectPrintLabelTypeDialogDialogActionListener.onLabelTypeSelected(AppConstants.LABEL_TYPE_INVENTORY_LABEL);
                        dialogSelectPrintLabelTypeDialog.dismiss();
                        break;
                    case R.id.rb_dialog_select_print_label_type_it_label:
                        selectPrintLabelTypeDialogDialogActionListener.onLabelTypeSelected(AppConstants.LABEL_TYPE_IT_LABEL);
                        dialogSelectPrintLabelTypeDialog.dismiss();
                        break;
                    case R.id.rb_dialog_select_print_label_type_shelf_label:
                        selectPrintLabelTypeDialogDialogActionListener.onLabelTypeSelected(AppConstants.LABEL_TYPE_SHELF_LABEL);
                        dialogSelectPrintLabelTypeDialog.dismiss();
                        break;
                    default:
                        selectPrintLabelTypeDialogDialogActionListener.onSnackBarShow(
                                App.getInstance().getString(R.string.message_please_select_a_label_type));
                        break;
                }
            }
        });
    }

    public interface SelectPrintLabelTypeDialogDialogActionListener {
        void onLabelTypeSelected(int labelType);

        void actionFailed(String errorMsg);

        void onSnackBarShow(String message);
    }

    public SelectPrintLabelTypeDialogDialogActionListener getSelectPrintLabelTypeDialogDialogActionListener() {
        return selectPrintLabelTypeDialogDialogActionListener;
    }


    public void setSelectPrintLabelTypeDialogDialogActionListener(
            SelectPrintLabelTypeDialogDialogActionListener selectPrintLabelTypeDialogDialogActionListener) {
        this.selectPrintLabelTypeDialogDialogActionListener = selectPrintLabelTypeDialogDialogActionListener;
    }
}
