package it.integry.integrywmsnative.gest.inventario.bottom_sheet__inventario_actions;

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.data_store.db.entity.InventarioRoomDTO;
import it.integry.integrywmsnative.databinding.BottomSheetInventarioActionsViewBinding;

public class BottomSheetInventarioActionsView extends BottomSheetDialogFragment {

    @Inject
    BottomSheetInventarioActionsViewModel mViewModel;

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

    private BottomSheetInventarioActionsViewBinding mBinding;
    private Listener mListener;

    private final InventarioRoomDTO inputItem;

    public BottomSheetInventarioActionsView(InventarioRoomDTO inputItem) {
        this.inputItem = inputItem;
    }


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

        MainApplication.appComponent
                .bottomSheetInventarioActionsComponent()
                .create()
                .inject(this);

        mViewModel.init(inputItem);
    }

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

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

        mBinding.executePendingBindings();

        return mBinding.getRoot();
    }




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

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

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

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



    public void editItem() {
        if(this.mListener != null) this.mListener.onItemEdit();
        this.dismiss();
    }

    public void deleteItem() {
        if(this.mListener != null) this.mListener.onItemDelete();
        this.dismiss();
    }



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

    public interface Listener {
        void onItemEdit();

        void onItemDelete();
    }
}
