package com.apps.chillscreen.uiView;

import android.content.Intent;
import android.os.Bundle;

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

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

import com.apps.chillscreen.BaseApplication;
import com.apps.chillscreen.adapter.DiscoverAdapter;
import com.apps.chillscreen.bean.Picture;
import com.apps.chillscreen.databinding.FragmentDiscoverBinding;
import com.apps.chillscreen.listener.CardClickListener;

import java.util.List;

public class DiscoverFragment extends Fragment implements CardClickListener {
    FragmentDiscoverBinding binding;

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

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

    private void init() {
        List<String> categoryList = BaseApplication.getCategoryList();
        DiscoverAdapter discoverAdapter =new DiscoverAdapter();
        discoverAdapter.setPictures(categoryList);
        discoverAdapter.setClickListener(this);
        GridLayoutManager layoutManager=new GridLayoutManager(requireContext(),2);
        binding.rlStart.setLayoutManager(layoutManager);
        binding.rlStart.setAdapter(discoverAdapter);

    }


    @Override
    public void onDetailClick(Picture picture) {

    }

    @Override
    public void onHomeClick(String name) {
        Intent intent=new Intent(requireActivity(), GeneraActivity.class);
        intent.putExtra(GeneraActivity.name,name);
        startActivity(intent);
    }
}