package com.app.input.breeze.board.uiactivity;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.GridLayoutManager;

import com.ad.tradpluslibrary.TPAdManager;
import com.app.input.breeze.board.App;
import com.app.input.breeze.board.R;
import com.app.input.breeze.board.bean.KeyboardTheme;
import com.app.input.breeze.board.bean.CategoryWrapper;
import com.app.input.breeze.board.databinding.ThemeListScreenBinding;
import com.app.input.breeze.board.listutils.ThemeGridAdapter;
import com.app.input.breeze.board.utils.AppUtils;
import com.app.input.breeze.board.utils.GridItemDecoration;

import java.util.List;

public class ThemeListActivity extends AppCompatActivity {
    private ThemeListScreenBinding vb;
    public static final String KEY_NAME ="class_name";
    private String name;
    private List<KeyboardTheme> data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ThemeListScreenBinding.inflate(getLayoutInflater());
        EdgeToEdge.enable(this);
        setContentView(vb.getRoot());
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        name = getIntent().getStringExtra(KEY_NAME);
        TPAdManager.INSTANCE.loadAllAd(this);
        TPAdManager.INSTANCE.showTPAD(this,()-> null);
        initData();
        initClick();
    }

    private void initData(){
        vb.className.setText(name);
        for (CategoryWrapper CategoryWrapper : App.list) {
            if(CategoryWrapper.getParentName().equals(name)){
                data = CategoryWrapper.getKeyboardList();
            }
        }
        // 两列布局，增大上下间距
        GridItemDecoration GridItemDecoration = new GridItemDecoration(16, 12, 0);
        ThemeGridAdapter adapterMain = new ThemeGridAdapter(this,data);
        vb.recycler.setLayoutManager(new GridLayoutManager(ThemeListActivity.this,2));
        vb.recycler.setAdapter(adapterMain);
        vb.recycler.addItemDecoration(GridItemDecoration);

    }
    private void initClick(){
        vb.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TPAdManager.INSTANCE.showTPAD(ThemeListActivity.this,()-> {
                    finish();
                    return null;
                } );
            }
        });
    }

}