package com.yutou.jianr_mg.views;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.yutou.jianr_mg.Adapters.ViewPagerAdapter;
import com.yutou.jianr_mg.Data.ShipEquipmnt;
import com.yutou.jianr_mg.Data.TeamData;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.DaytimeFragment;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.NightFragment;
import com.yutou.jianr_mg.R;
import com.yutou.jianr_mg.Tools.JianRUtils;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.PageNavigationView;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;

public class WarLogActivity extends AppCompatActivity {
    JSONArray array;
    private PageNavigationView tab;
    private ViewPager pager;
    private NavigationController navigationController;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mod_list);
        initView();
        try {
            array = new JSONArray(getIntent().getStringExtra("data"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (array == null) {
            array = new JSONArray();
        }
        try {
            JSONObject json = array.getJSONObject(0);
            JSONObject data = json.getJSONObject("DealNode");
            JSONObject msg = new JSONObject(data.getString("message"));
            List<TeamData> list = JianRUtils.getUserTeam(msg);
            List<TeamData> hm=new ArrayList<>();
            for (TeamData teamData : list) {
            //    if(teamData.getType()>)
                String name = teamData.getTitle();
                List<String> equipment = teamData.getEquipments();
                for (String s : equipment) {
                    ShipEquipmnt equipmnt = JianRUtils.getEquipmnt(Integer.parseInt(s), -1);
                    System.out.println("舰娘:"+name+"装备名字:"+equipmnt.getTitle()+" 类型："+equipmnt.getType());
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void initView() {
        tab = (PageNavigationView) findViewById(R.id.tab);
        pager = (ViewPager) findViewById(R.id.pager);
        List<Fragment> list = new ArrayList<>();
        list.add(new DaytimeFragment());
        list.add(new NightFragment());
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), list);
        pager.setAdapter(adapter);
        pager.setCurrentItem(0);
        navigationController = tab.material()
                .addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "昼战")
                .addItem(R.drawable.icon_night, R.drawable.icon_night_select, "夜战")
                .build();
        navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
            @Override
            public void onSelected(int index, int old) {
                pager.setCurrentItem(index);

            }

            @Override
            public void onRepeat(int index) {

            }
        });
        navigationController.setupWithViewPager(pager);
        navigationController.setSelect(0);

    }
}
