package it.integry.integrywmsnative.gest.lista_bancali;

import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.databinding.ActivityListaBancaliBinding;
import it.integry.integrywmsnative.gest.contenuto_bancale.ContenutoBancaleActivity;
import it.integry.integrywmsnative.gest.lista_bancali.viewmodel.ListaBancaliViewModel;

import static it.integry.integrywmsnative.gest.lista_bancali.ListaBancaliActivity.Key.CanRecoverUL;

public class ListaBancaliActivity extends AppCompatActivity {

    public static class Key {
        public static final String CanRecoverUL = "canRecoverUL";
    }

    public ActivityListaBancaliBinding bindings;

    private ListaBancaliViewModel mViewModel;

    private boolean mCanRecoverUl;

    private static final int PICK_UL_REQUEST = 1;  // The request code


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bindings = DataBindingUtil.setContentView(this, R.layout.activity_lista_bancali);


        mCanRecoverUl = getIntent().getBooleanExtra(CanRecoverUL, false);
        List<MtbColt> mtbColts = (ArrayList<MtbColt>)getIntent().getSerializableExtra("key");
        mViewModel = new ListaBancaliViewModel(this, mtbColts);


        setSupportActionBar(this.bindings.toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    }

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }

    public void startContenutoBancaleActivity(MtbColt item){
        Intent myIntent = new Intent(this, ContenutoBancaleActivity.class);
        myIntent.putExtra("key", item); //Optional parameters
        myIntent.putExtra(ContenutoBancaleActivity.Key.CanRecoverUL, mCanRecoverUl);
        startActivityForResult(myIntent, PICK_UL_REQUEST);
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Check which request we're responding to
        if (requestCode == PICK_UL_REQUEST) {
            // Make sure the request was successful
            if (resultCode == RESULT_OK) {

                // MtbColt recoveredMtbColt = data.getParcelableExtra("key");


                this.setResult(RESULT_OK, data);
                this.finish();
            }
        }
    }
}
