package com.kuckovsky.richard.home;


import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class TabBarController extends AppCompatActivity implements rooms.OnFragmentInteractionListener, room.OnFragmentInteractionListener {

    private JSONArray rooms_array;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Log.i("OK", "klik");

            Fragment selectedFragment = null;

            switch (item.getItemId()) {
                case R.id.navigation_favourite:
                    Log.i("OK", "fav");
                    return true;
                case R.id.navigation_rooms:
                    Log.i("OK", "room");

                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                    selectedFragment = rooms.newInstance(rooms_array.toString());
                    transaction.replace(R.id.content, selectedFragment);
                    transaction.commit();
                    return true;
                case R.id.navigation_settings:
                    Log.i("OK", "set");
                    return true;
            }
            return false;
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_bar_controller);
        try {
            JSONArray obj = new JSONArray(getIntent().getStringExtra("rooms"));
            rooms_array = obj;

        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.i("OK", "nove okno");
        //mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }


    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}
