package com.ar.drawing.assistant.paint.ui_fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;

import com.ar.drawing.assistant.paint.databinding.FragHomeBinding;
import com.ar.drawing.assistant.paint.tooladapter.AdMain;
import com.ar.drawing.assistant.paint.toollistener.OnClickCallback;
import com.ar.drawing.assistant.paint.ui_activity.ActList;
import com.ar.drawing.assistant.paint.ui_activity.ActPreview;
import com.ar.drawing.assistant.paint.utils.MyApp;

public class FragHome extends Fragment implements OnClickCallback {

    private FragHomeBinding binding;

    public FragHome() {

    }

    public static FragHome newInstance() {
        FragHome fragment = new FragHome();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragHomeBinding.inflate(getLayoutInflater());
        onInitRecycler();


        return binding.getRoot();
    }

    private void onInitRecycler() {
        AdMain adMain = new AdMain(requireContext());
        adMain.setListener(this::onClickItem);
        binding.recyclerview.setAdapter(adMain);
        binding.recyclerview.setLayoutManager(new GridLayoutManager(requireContext(), 1));
    }


    @Override
    public void onClickItem(int type, String dir) {
        switch (type) {
            case 0:
                Intent intent = new Intent(requireContext(), ActList.class);
                intent.putExtra(MyApp.Key_ViewDir, dir);
                startActivity(intent);
                break;
            case 1:
                Intent intent1 = new Intent(requireContext(), ActPreview.class);
                intent1.putExtra(MyApp.Key_Camera, dir);
                startActivity(intent1);
                break;
        }


    }
}