package com.example.myapplication.ui.home;

import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.example.myapplication.R;
import com.example.myapplication.databinding.FragmentHomeBinding;
import com.example.myapplication.ui.Buttonfragments.HazardGarbageFragment;
import com.example.myapplication.ui.Buttonfragments.KitchenGarbageFragment;
import com.example.myapplication.ui.Buttonfragments.OtherGarbageFragment;
import com.example.myapplication.ui.Buttonfragments.RecycleGarbageFragment;

public class HomeFragment extends Fragment {
    private Fragment recycleGarbageFragment;
    private ImageButton recycleButton;

    private ImageButton kitchenButton;

    private ImageButton otherButton;

    private ImageButton hazardButton;
    private FragmentHomeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        recycleButton = root.findViewById(R.id.recycle);
        kitchenButton = root.findViewById(R.id.kitchen_garbage);
        otherButton = root.findViewById(R.id.other_garbage);
        hazardButton = root.findViewById(R.id.hazardous_waste);
        recycleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getParentFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_container, new RecycleGarbageFragment()).commit();
            }
        });
        recycleButton.performClick();
        kitchenButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getParentFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_container, new KitchenGarbageFragment()).commit();
            }
        });
        otherButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getParentFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_container, new OtherGarbageFragment()).commit();
            }
        });
        hazardButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getParentFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_container, new HazardGarbageFragment()).commit();
            }
        });
        return root;
    }

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