package it.integry.integrywmsnative.view.dialogs;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
import it.integry.integrywmsnative.databinding.DialogAskActionEditDeleteBinding;

public class DialogAskActionView extends BaseDialogFragment {

    private final String mTitle;
    private final String mSubtitle;

    private final Runnable mOnEditSelected;
    private final Runnable mOnDeleteSelected;



    public static DialogAskActionView newInstance(String title, String subtitle, Runnable onEdit, Runnable onDelete) {
        return new DialogAskActionView(title, subtitle, onEdit, onDelete);
    }

    private DialogAskActionView(String title, String subTitle, Runnable onEditSelected, Runnable onDeleteSelected) {
        super();

        mTitle = title;
        mSubtitle = subTitle;

        mOnEditSelected = onEditSelected;
        mOnDeleteSelected = onDeleteSelected;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        DialogAskActionEditDeleteBinding mBinding = DialogAskActionEditDeleteBinding.inflate(LayoutInflater.from(requireContext()), null, false);
        mBinding.setLifecycleOwner(this);
        mBinding.setViewmodel(this);

        var alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
                .setView(mBinding.getRoot());

        mBinding.bottomSheetActionsTitle.setText(mTitle);
        mBinding.bottomSheetActionsSubtitle.setText(mSubtitle);

        return alertDialogBuilder.create();
    }

    public void onEdit() {
        dismiss();
        mOnEditSelected.run();
    }

    public void onDelete() {
        dismiss();
        mOnDeleteSelected.run();
    }

}

