package com.wd.workoffice.ui.activity.bat.work;

import android.view.Menu;
import android.view.MenuItem;

import com.google.android.material.tabs.TabLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.ui.adapter.VpDataAdapter;
import com.wd.workoffice.ui.fg.WorkWarehouse1Fragment;
import com.wd.workoffice.ui.fg.WorkWarehouse2Fragment;

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

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 工作台 - 仓库
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class WorkWarehouseActivity extends WorkToolBarActivity {

    @BindView(R.id.tl_tab)
    TabLayout tlTab;
    @BindView(R.id.vp_data)
    ViewPager vpData;
    private String tab[] = {"仓库列表", "订单列表"};
    int choosePos = 0;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        tlTab.setupWithViewPager(vpData);
    }

    @Override
    protected void initData() {
        FragmentManager sfm = getSupportFragmentManager();
        List<Fragment> data = new ArrayList<>();
        WorkWarehouse1Fragment workWarehouse1Fragment = new WorkWarehouse1Fragment();
        WorkWarehouse2Fragment workWarehouse2Fragment = new WorkWarehouse2Fragment();
        data.add(workWarehouse1Fragment);
        data.add(workWarehouse2Fragment);
        VpDataAdapter vpFgAdapter = new VpDataAdapter(sfm, data);
        vpData.setAdapter(vpFgAdapter);
        for (int i = 0; i < tab.length; i++) {
            tlTab.getTabAt(i).setText(tab[i]);
        }
    }

    @Override
    protected void initEvent() {
        tlTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                choosePos = tab.getPosition();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_pro;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.search:
                if (choosePos == 0) {
                    startActivity(WorkWarehouseSearchActivity.class);
                } else {
                    startActivity(WorkWarehouseOrderSearchActivity.class);
                }
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}
