package de.jg_cody.Teraplex;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.fragment.app.DialogFragment;

import de.jg_cody.Teraplex.ui.Flur.FlurFragment;


public class AddButtonsDialogDouble extends DialogFragment {
    private AddButtonsDialogListenerDouble listener;

    private EditText editText_name, editText_command1, editText_button1, editText_command2, editText_button2;
    private FlurFragment frag;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.addbuttonsdialog_double, null);

        builder.setView(view)
                .setTitle("ON/OFF BUTTON")
                .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                })
                .setPositiveButton("ADD", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String command1 = editText_command1.getText().toString();
                        String command2 = editText_command2.getText().toString();
                        String name = editText_name.getText().toString();
                        String button1 = editText_button1.getText().toString();
                        String button2 = editText_button2.getText().toString();
                        listener.applyTextsDouble(name,command1,button1,command2,button2);
                    }
                });

        editText_name = view.findViewById(R.id.dialogDouble_editText_name);
        editText_command1 = view.findViewById(R.id.dialogDouble_editText_command1);
        editText_command2 = view.findViewById(R.id.dialogDouble_editText_command2);
        editText_button1 = view.findViewById(R.id.dialogDouble_editText_button1);
        editText_button2 = view.findViewById(R.id.dialogDouble_editText_button2);

        AlertDialog mDialog = builder.create();
        mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round);
        return mDialog;
    }

    public void setFragment(FlurFragment frag) {
        this.frag = frag;
    }

    public FlurFragment getFragment() {
        return frag;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        try {
            listener = (AddButtonsDialogListenerDouble) frag;
        } catch (ClassCastException e) {

        }
    }

    public interface AddButtonsDialogListenerDouble {
        void applyTextsDouble(String name, String command1, String command2, String button1, String button2);
    }
}

