package lc.ris.android;

import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import lc.ris.client.RapidInventoryClient;

/**
 * The main activity for the Rapid Inventory System Android application.
 *
 * @author Alex Leigh
 * @since mk1
 */
public class MainActivity extends AppCompatActivity {
    // TODO: Replace this constant w/ a settings available on the settings panel
    private final String UNIVERSE = "lc";
    private final BarcodeBroker barcodeBroker = new BarcodeBroker();
    private final RapidInventoryClient risClient = new RapidInventoryClient(UNIVERSE);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);

        bottomNavigationView.setOnItemSelectedListener(new BottomNavigationView.OnItemSelectedListener() {
            final FragmentManager fragmentManager = getSupportFragmentManager();

            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment fragment = null;

                switch (item.getItemId()) {
                    case R.id.stockPickFragment:
                        fragment = StockPickFragment.newInstance();
                        break;
                    case R.id.stockTakeFragment:
                        fragment = StockTakeFragment.newInstance();
                        break;
                    case R.id.transferFragment:
                        fragment = TransferFragment.newInstance();
                        break;
                    case R.id.itemFragment:
                        fragment = ItemFragment.newInstance();
                        break;
                    case R.id.settingsFragment:
                        fragment = SettingsFragment.newInstance();
                        break;
                }

                fragmentManager.beginTransaction().replace(R.id.nav_host_fragment, fragment).commit();
                return true;
            }
        });
    }

    /**
     * Return the {@link BarcodeBroker} associated with this activity. This method always returns the broker.
     */

    public BarcodeBroker getBarcodeBroker() {
        return barcodeBroker;
    }

    public RapidInventoryClient getRisClient() {
        return risClient;
    }
}