package com.example.quiz;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.quiz.databinding.FragmentLoginBinding;
import com.example.quiz.utils.SharedPrefsHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Login#newInstance} factory method to
 * create an instance of this fragment.
 */
public class Login extends Fragment {

    private SharedPrefsHelper prefsHelper;
    public Login() {
        // Required empty public constructor
    }
    public static Login newInstance() {
        Login fragment = new Login();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    private FragmentLoginBinding binding;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

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

    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        if(activity != null){
            activity.getSupportActionBar().hide();
        }

    }

   public void onStart(){
       super.onStart();
       binding.loginButton.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {

               prefsHelper = SharedPrefsHelper.getInstance(getContext());
               FragmentManager fragmentManager = getParentFragmentManager();
               ListOfReunions reunions = ListOfReunions.newInstance("");
               fragmentManager.beginTransaction()
                       .replace(R.id.nav_host_fragment_content_main, reunions)
                       .addToBackStack(null)
                       .commit();
           }
       });

       binding.caisse.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Caisse caisse = Caisse.newInstance();
               FragmentManager fragmentManager = getParentFragmentManager();
               fragmentManager.beginTransaction()
                       .replace(R.id.nav_host_fragment_content_main, caisse)
                       .addToBackStack(null)
                       .commit();
           }
       });

   }

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