package it.integry.integrywmsnative.view.bottom_sheet__mtb_colr_edit;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.ObservableField;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import javax.inject.Inject;

import it.integry.integrywmsnative.MainApplication;
import it.integry.integrywmsnative.core.model.MtbColr;
import it.integry.integrywmsnative.databinding.BottomSheetMtbColrEditBinding;

public class BottomSheetMtbColrEditModalView extends BottomSheetDialogFragment {

    @Inject
    BottomSheetMtbColrEditViewModel mViewModel;

    public ObservableField<Boolean> enabledEditButton = new ObservableField<>(true);
    public ObservableField<Boolean> enabledDeleteButton = new ObservableField<>(true);

    private BottomSheetMtbColrEditBinding mBinding;
    private Listener mListener;

    public final ObservableField<MtbColr> inputMtbColr = new ObservableField<>();

    public BottomSheetMtbColrEditModalView(MtbColr inputMtbColr) {
        this.inputMtbColr.set(inputMtbColr);
    }


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

        MainApplication.appComponent
                .bottomSheetMtbColrEditModalComponent()
                .create()
                .inject(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = BottomSheetMtbColrEditBinding.inflate(inflater, container, true);

        mBinding.setLifecycleOwner(this);
        mBinding.setView(this);

        mBinding.executePendingBindings();

        return mBinding.getRoot();
    }


    public BottomSheetMtbColrEditModalView enableEditButton() {
        this.enabledEditButton.set(true);
        return this;
    }

    public BottomSheetMtbColrEditModalView disableEditButton() {
        this.enabledEditButton.set(false);
        return this;
    }

    public BottomSheetMtbColrEditModalView enableDeleteButton() {
        this.enabledDeleteButton.set(true);
        return this;
    }

    public BottomSheetMtbColrEditModalView disableDeleteButton() {
        this.enabledDeleteButton.set(false);
        return this;
    }


    public void editMtbColr() {
        if (this.mListener != null) this.mListener.onMtbColrEdit(this.inputMtbColr.get());
        this.dismiss();
    }

    public void deleteMtbColr() {
        if (this.mListener != null) this.mListener.onMtbColrDelete(this.inputMtbColr.get());
        this.dismiss();
    }


    public BottomSheetMtbColrEditModalView setListener(Listener listener) {
        this.mListener = listener;
        return this;
    }

    public interface Listener {

        void onMtbColrEdit(MtbColr mtbColr);

        void onMtbColrDelete(MtbColr mtbColr);

    }
}
