package com.wall.turing.wallpapers.turingfragments;

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.turing.wallpapers.WallpaperApplication;
import com.wall.turing.wallpapers.accctivities.TuringListActivity;
import com.wall.turing.wallpapers.accctivities.TuringWallpaperActivity;
import com.wall.turing.wallpapers.databinding.MainPageBinding;
import com.wall.turing.wallpapers.uutils.AppUtils;
import com.wall.turing.wallpapers.uutils.AdapterHelper;
import com.wall.turing.wallpapers.connect.TuringItemClick;
import com.wall.turing.wallpapers.myselfbean.Wallpaper;
import com.wall.turing.wallpapers.adapteres.MainAdapter;

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


public class MainPage extends Fragment implements TuringItemClick {
    private MainPageBinding vb;
    public MainPage() {
    }
    public static MainPage newInstance(int type) {
        Bundle bundle = new Bundle();
        bundle.putInt(AppUtils.key_index, type);
        MainPage fragment = new MainPage();
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        vb = MainPageBinding.inflate(getLayoutInflater());

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



    private void initTabVp() {

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

    }


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

    }

    @Override
    public void onItemClickAction(Wallpaper info) {
        Intent intent = new Intent(requireContext(), TuringWallpaperActivity.class);
        intent.putExtra(AppUtils.key_info, info);
        startActivity(intent);
    }

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