package com.example.patrice.rerservation01;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class action_bar extends AppCompatActivity {

    Menu mMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar = getSupportActionBar();
        getSupportActionBar().setTitle("   Ludo ONsemi");
        String title = actionBar.getTitle().toString();
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setLogo(R.drawable.appli_icon);
        getSupportActionBar().setDisplayUseLogoEnabled(true);


       // MenuItem item = (MenuItem) findViewById(R.id.action_panier);
       // item.setVisible(false);

       // this.invalidateOptionsMenu();

    }

    private void save(){
        Toast.makeText(this, "action_save",Toast.LENGTH_LONG).show();

        //mMenu.findItem(R.id.action_panier).setVisible(false);
        Intent i = new Intent(getApplicationContext(), historique_retrait_jeu.class);
        startActivity(i);

    }

    private void delete(){
        Toast.makeText(this,"action_delete",Toast.LENGTH_LONG).show();

        mMenu.findItem(R.id.action_panier).setVisible(true);

        mMenu.findItem(R.id.action_panier).setIcon(getResources().getDrawable(R.drawable.shopping_cart));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //ajoute les entrées de menu_test à l'ActionBar
        getMenuInflater().inflate(R.menu.test_menu, menu);

        mMenu = menu;
        mMenu.findItem(R.id.action_panier).setVisible(false);

/*
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.test_menu, menu);
        MenuItem shareItem = menu.findItem(R.id.menu_action_share);

        // show the button when some condition is true
        if (someCondition) {
            shareItem.setVisible(true);
        }
 */
        return true;
    }

    //gère le click sur une action de l'ActionBar
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId()){
            case R.id.action_panier:
                save();
                return true;
            //case R.id.action_aide:
            //    delete();
            //    return true;
            case R.id.action_a_propos:
                return true;
        }

        return super.onOptionsItemSelected(item);
    }
}