package com.cartoon.wallpapers.live.ui;

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

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

import com.cartoon.wallpapers.live.R;
import com.cartoon.wallpapers.live.ada.FragState;
import com.cartoon.wallpapers.live.base.BaseActivity;
import com.cartoon.wallpapers.live.databinding.ItemTabViewBinding;
import com.cartoon.wallpapers.live.databinding.MainActivityBinding;
import com.cartoon.wallpapers.live.upload.Http;
import com.cartoon.wallpapers.live.upload.SaveUtils;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

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

public class MainActivity extends BaseActivity<MainActivityBinding> {
    @Override
    protected MainActivityBinding getViewBinding() {
        return MainActivityBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreateInit() {
        boolean post = SaveUtils.INSTANCE.isPost();
        if (!post) {
            Http.INSTANCE.makeGetRequest(MainActivity.this);
            SaveUtils.INSTANCE.setPost(true);
        }
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(MainFragment.newInstance(0));
        fragmentList.add(MainFragment.newInstance(3));
        fragmentList.add(MainFragment.newInstance(2));

        FragState adapter = new FragState(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(MainActivity.this, R.string.tab_Trending));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.selector_1));
                        break;
                    case 1:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_Explore));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.selector_2));
                        break;
                    case 2:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_Shift));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.selector_3));
                        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 true;
    }

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

    }
}