package com.wall.snap.wallpaper.fragmentsnap;

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.LinearLayoutManager;

import com.wall.snap.wallpaper.MysnapApp;
import com.wall.snap.wallpaper.acctivitysnap.ListsnapActivity;
import com.wall.snap.wallpaper.acctivitysnap.WallpapersnapActivity;
import com.wall.snap.wallpaper.databinding.FragmentMainsnapBinding;
import com.wall.snap.wallpaper.toolsnap.ComUtilssnap;
import com.wall.snap.wallpaper.toolsnap.ItemHelpersnap;
import com.wall.snap.wallpaper.mysnapbean.MysnapData;
import com.wall.snap.wallpaper.itemsnap.ItemsnapMain;

import java.util.ArrayList;
import java.util.List;


public class FragmentMainsnap extends Fragment implements com.wall.snap.wallpaper.connectorsnap.OnItemsnapClick {
    private FragmentMainsnapBinding vb;
    public FragmentMainsnap() {
    }
    public static com.wall.snap.wallpaper.fragmentsnap.FragmentMainsnap newInstance(int type) {
        Bundle bundle = new Bundle();
        bundle.putInt(ComUtilssnap.key_index, type);
        com.wall.snap.wallpaper.fragmentsnap.FragmentMainsnap fragment = new com.wall.snap.wallpaper.fragmentsnap.FragmentMainsnap();
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        vb = FragmentMainsnapBinding.inflate(getLayoutInflater());

        initTabVp();
        return vb.getRoot();
    }



    private void initTabVp() {

        List<String> data = new ArrayList<>();
        while (data.size() < 8) {
            data = MysnapApp.getCategoryNames();
        }
        vb.loadingPb.setVisibility(View.GONE);
        initList(data);

    }


    private void initList(List<String> data) {
        ItemsnapMain adHomeParent = new ItemsnapMain();
        adHomeParent.setData(data);
        adHomeParent.setInfoWallpaperListener(this);
        ItemHelpersnap itemHelpertwo = new ItemHelpersnap(10, 10, 0);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(requireContext());
//        vb.classRecycler.addItemDecoration(itemSpace);
        vb.classRecycler.setLayoutManager(linearLayoutManager);
        vb.classRecycler.setAdapter(adHomeParent);

    }

    @Override
    public void onItemClickAction(MysnapData info) {
        Intent intent = new Intent(requireContext(), WallpapersnapActivity.class);
        intent.putExtra(ComUtilssnap.key_info, info);
        startActivity(intent);
    }

    @Override
    public void onClickMore(String name) {
        Intent intent = new Intent(requireContext(), ListsnapActivity.class);
        intent.putExtra(ListsnapActivity.key_index, name);
        startActivity(intent);
    }
}