package org.ntlab.acanthus_client.views.paint;

import android.content.Intent;
import android.os.Build;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.R;
import org.ntlab.acanthus_client.views.MainActivity;
import org.ntlab.acanthus_client.views.paint.page.PageActivity;

//-----------------------------------------------------------------
//　描画シーンの下部のツールバー
public class PaintToolBar {
    private BottomNavigationView bottomNavigationView;
    private BottomNavigationView.OnNavigationItemSelectedListener onNavigationItemSelectedListener;

    //-----------------------------------------------------------------
    //-----------------------------------------------------------------
    public PaintToolBar(PaintActivity paintActivity, PaintCanvas paintCanvas) {
        this.bottomNavigationView = (BottomNavigationView) paintActivity.findViewById(R.id.navPaint);
        setNavigationListener(paintActivity, paintCanvas);
    }

    //-----------------------------------------------------------------
    //-----------------------------------------------------------------
    // ナビゲーションバーのタッチ監視
    private void setNavigationListener(AppCompatActivity appCompatActivity, PaintCanvas paintCanvas) {
        this.onNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    //-----------------------------------------------------------------
                    //
                    case R.id.navigation_pen:

                    //-----------------------------------------------------------------
                    //
                    case R.id.navigation_clear:
                        paintCanvas.clearCanvas();
                        return true;
                    //-----------------------------------------------------------------
                    //
                    case R.id.navigation_invite:
                        transitionInviteActivity(appCompatActivity);
                        return true;

                    //-----------------------------------------------------------------
                    case R.id.navigation_page:
                        paintCanvas.canvassc();
                        transitionPageActivity(appCompatActivity);
                        return true;

                }

                return true;
            }
        };

        bottomNavigationView.setOnNavigationItemSelectedListener(this.onNavigationItemSelectedListener);
    }
    //-----------------------------------------------------------------
    //ペンの詳細変更ページへ移動
    private void transitionPenDetailFragment(AppCompatActivity appCompatActivity){
        Acanthus acanthus =(Acanthus) appCompatActivity.getApplication();
        Intent intent = new Intent(acanthus,PenDetailsFragment.class);
        appCompatActivity.startActivity(intent);
    }

    //-----------------------------------------------------------------
    // 招待ページへ移動
    private void transitionInviteActivity(AppCompatActivity appCompatActivity) {
        Acanthus acanthus = (Acanthus) appCompatActivity.getApplication();
        Intent intent = new Intent(acanthus, InviteActivity.class);
        appCompatActivity.startActivity(intent);
    }

    //-----------------------------------------------------------------
    // 編集へ移動
    private void transitionPageActivity(AppCompatActivity appCompatActivity) {
        Acanthus acanthus = (Acanthus) appCompatActivity.getApplication();
        Intent intent = new Intent(acanthus, PageActivity.class);
        appCompatActivity.startActivity(intent);
    }

    //-----------------------------------------------------------------

}
