package com.cartoon.live.wallpaper.ui;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.cartoon.live.wallpaper.R;
import com.cartoon.live.wallpaper.myadapter.AdapterViewPager;
import com.cartoon.live.wallpaper.parent.BaseActivity;
import com.cartoon.live.wallpaper.databinding.ActivityMainBinding;
import com.cartoon.live.wallpaper.databinding.ItemTabBinding;

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

public class HomeActivity extends BaseActivity<ActivityMainBinding> {


    @Override
    protected ActivityMainBinding getViewBinding() {
        return ActivityMainBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreateInit() {
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(HomeFragment.newInstance(0));
        fragmentList.add(HomeFragment.newInstance(3));
        fragmentList.add(HomeFragment.newInstance(2));
        fragmentList.add(FavoriteFragment.newInstance());

        AdapterViewPager adapter = new AdapterViewPager(this, fragmentList);
        vb.vp.setAdapter(adapter);
        new TabLayoutMediator(vb.tab, vb.vp, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                ItemTabBinding inflate = ItemTabBinding.inflate(getLayoutInflater());
                tab.setCustomView(inflate.getRoot());
                switch (position) {
                    case 0:
                        inflate.tabTitle.setText(ContextCompat.getString(HomeActivity.this, R.string.tab_Trending));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(HomeActivity.this, R.drawable.selector_tab_trending));
                        break;
                    case 1:
                        inflate.tabTitle.setText(ContextCompat.getString(HomeActivity.this, R.string.tab_Explore));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(HomeActivity.this, R.drawable.selector_explore));
                        break;
                    case 2:
                        inflate.tabTitle.setText(ContextCompat.getString(HomeActivity.this, R.string.tab_Shift));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(HomeActivity.this, R.drawable.selector_tab_shift));
                        break;
                    case 3:
                        inflate.tabTitle.setText(ContextCompat.getString(HomeActivity.this, R.string.tab_Favorites));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(HomeActivity.this, R.drawable.selector_tab_like));
                        break;
                }
            }
        }).attach();
    }

    @Override
    protected void onInitClick() {

    }

    @Override
    public boolean isFullScreen() {
        return true;
    }

    @Override
    public boolean statusBarLight() {
        return false;
    }

    @Override
    public void onClick(View v) {

    }
}