package com.key.coolkeyboard.fragment;

import android.os.Bundle;

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

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

import com.key.coolkeyboard.CoolKeyboardSkin;
import com.key.coolkeyboard.R;
import com.key.coolkeyboard.adapter.ThumAdapter;
import com.key.coolkeyboard.databinding.FragmentAllBinding;
import com.key.coolkeyboard.tool.SpaceItem;

public class AllFragment extends Fragment {
    FragmentAllBinding binding;
    private String tabargs;
    private ThumAdapter thumAdapter;
    private SpaceItem spaceItem = new SpaceItem(12, 12, 12);

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


        initData();


        return binding.getRoot();


    }

    private void initData() {
        tabargs = getArguments().getString("tab");
        if (tabargs.equals("ALL")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getAlllist());
        } else if (tabargs.equals("Love")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getLovelist());
        } else if (tabargs.equals("Cool")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getCoollist());
        } else if (tabargs.equals("Cute")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getCutelist());
        } else if (tabargs.equals("Neon")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getNeonlist());
        } else if (tabargs.equals("Festival")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getFestivallist());
        } else if (tabargs.equals("Shining")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getGravitylist());
        } else if (tabargs.equals("Aesthetic")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getAestheticlist());
        } else if (tabargs.equals("Super Theme")) {
            thumAdapter = new ThumAdapter(requireContext(), CoolKeyboardSkin.getSuperlist());
        }
        binding.allRv.setLayoutManager(new GridLayoutManager(requireContext(), 2));
        binding.allRv.setAdapter(thumAdapter);
        binding.allRv.addItemDecoration(spaceItem);
    }

    public static AllFragment newInstance(String pos) {

        Bundle args = new Bundle();
        AllFragment fragment = new AllFragment();
        args.putString("tab", pos);
        fragment.setArguments(args);
        return fragment;
    }
}