/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vostan.banvor;

import static org.vostan.banvor.App.theApp;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
//import android.widget.Button;
//import android.widget.TextView;
//import static org.vostan.banvor.App.theApp;

import org.vostan.banvor.databinding.FragmentWelcomeBinding;
import org.vostan.banvor.game.State;

/**
 *
 */
public class WelcomeFragment extends Fragment
{
	private FragmentWelcomeBinding binding;
	private State gameState;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		gameState = theApp().state();
		binding = FragmentWelcomeBinding.inflate(inflater, container, false);
		return binding.getRoot();
	}

	public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

		binding.btnContinue.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				WelcomeFragmentDirections.ActionWelcomeFragmentToPuzzleBoardFragment action =
						WelcomeFragmentDirections.actionWelcomeFragmentToPuzzleBoardFragment();
				action.setLevel(gameState.getCurrentLevel());
				NavHostFragment.findNavController(WelcomeFragment.this)
						.navigate(action);
			}
		});
		binding.btnPuzzles.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				NavHostFragment.findNavController(WelcomeFragment.this)
						.navigate(R.id.action_WelcomeFragment_to_PuzzleListFragment);
			}
		});
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		binding = null;
	}
}
