package com.free.video.wallpaper.uipage;

import android.content.Intent;
import android.view.View;

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

import com.free.video.wallpaper.R;
import com.free.video.wallpaper.baseapp.MyBaseActivity;
import com.free.video.wallpaper.databinding.ItemTabViewBinding;
import com.free.video.wallpaper.databinding.PageMainBinding;
import com.free.video.wallpaper.mylist.ViewPagerAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

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

public class PageMain extends MyBaseActivity<PageMainBinding> {


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

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

        ViewPagerAdapter adapter = new ViewPagerAdapter(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) {
                ItemTabViewBinding inflate = ItemTabViewBinding.inflate(getLayoutInflater());
                tab.setCustomView(inflate.getRoot());
                switch (position) {
                    case 0:
                        inflate.tabTitle.setText(ContextCompat.getString(PageMain.this, R.string.tab_Trending));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(PageMain.this, R.drawable.selector_tren));
                        break;
                    case 1:
                        inflate.tabTitle.setText(ContextCompat.getString(PageMain.this, R.string.tab_Explore));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(PageMain.this, R.drawable.selector_ex));
                        break;
                    case 2:
                        inflate.tabTitle.setText(ContextCompat.getString(PageMain.this, R.string.tab_Shift));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(PageMain.this, R.drawable.selector_shi));
                        break;
//                    case 3:
//                        inflate.tabTitle.setText(ContextCompat.getString(ActMain.this, R.string.tab_Favorites));
//                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(ActMain.this, R.drawable.selector_tab_like));
//                        break;
                }
            }
        }).attach();
    }

    @Override
    protected void onInitClick() {
     vb.ivFavorite.setOnClickListener(this);
    }

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

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

    @Override
    public void onClick(View v) {
        if(v.equals(vb.ivFavorite)){
            Intent intent = new Intent(this, PageFavorite.class);
            startActivity(intent);
        }

    }
}