package com.cygnusa.hyperm;

import android.annotation.SuppressLint;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.cygnusa.hyperm.fragments.ClassRoomTainingActivity;
import com.cygnusa.hyperm.fragments.TrainerFeedBackFragment;
import com.cygnusa.hyperm.util.DepthPageTransformerNew;
import com.cygnusa.hyperm.util.NonSwipeableViewPager;
import com.cygnusa.hyperm.util.TransparentProgressDialog;
import com.cygnusa.hyperm.wrappers.FragmentItem;

import java.util.ArrayList;
import java.util.Objects;

public class ClassRoomTrainerTainingActivity extends AppCompatActivity {
    TransparentProgressDialog progressDialog;
    NonSwipeableViewPager dseClassRoomPager;
    SmartTabLayout dseClassRoomTab;
    ArrayList<String> arrEarnedPoints = new ArrayList<>();
    DSEClassRoomAdapter adapter;
    ArrayList<FragmentItem> fragments = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_dse_training);
        initView();
    }

    private void initView() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setContentInsetStartWithNavigation(0);
        toolbar.setTitle("");
        Objects.requireNonNull(getSupportActionBar()).setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        @SuppressLint("PrivateResource")
        Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        backArrow.setColorFilter(getResources().getColor(R.color.btn_bg_color), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(backArrow);


        dseClassRoomPager = findViewById(R.id.myDsePager);
        dseClassRoomTab = findViewById(R.id.myDsePagerTab);

        arrEarnedPoints.clear();
        arrEarnedPoints.add("Calender");
        arrEarnedPoints.add("Feedback");

        dseClassRoomPager.setPageTransformer(true, new DepthPageTransformerNew());
        adapter = new DSEClassRoomAdapter(getSupportFragmentManager(),
                arrEarnedPoints);
        dseClassRoomPager.setAdapter(adapter);
        dseClassRoomTab.setViewPager(dseClassRoomPager);

        if (getIntent().getExtras() != null) {
            Bundle bundle = getIntent().getExtras();
            if (bundle != null) {
                String message = bundle.getString("type");
                if (message != null) {
                    if (message.equalsIgnoreCase("11")) {
                        dseClassRoomPager.setCurrentItem(2);
                    }
                }
            }
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            ClassRoomTrainerTainingActivity.this.overridePendingTransition(R.anim.animation_f_enter,
                    R.anim.animation_f_leave);
        }
        return super.onOptionsItemSelected(item);
    }

    private class DSEClassRoomAdapter extends FragmentPagerAdapter {
        ArrayList<String> categories;

        public DSEClassRoomAdapter(androidx.fragment.app.FragmentManager supportFragmentManager, ArrayList<String> list) {
            super(supportFragmentManager);
            categories = list;
            fragments = new ArrayList<>();
        }

        @Override
        public int getCount() {
            return 2;
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new ClassRoomTainingActivity(); //ChildFragment1 at position 0
                case 1:
                    return new TrainerFeedBackFragment();
            }
            return null;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return categories.get(position);
        }
    }
}