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

import android.os.Bundle;
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.WorkBaseFg;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.workEnum.OrderDeptPermission;
import com.wd.workoffice.bean.workEnum.PagePermissionType;
import com.wd.workoffice.bean.workEnum.PermissionType;
import com.wd.workoffice.ui.activity.bat.order.CrucibleOrderSearchActivity;
import com.wd.workoffice.ui.activity.bat.store.ChooseInfoActivity;
import com.wd.workoffice.ui.adapter.VpDataAdapter;
import com.wd.workoffice.ui.fg.CrucibleOrderBuyListFragment;
import com.wd.workoffice.util.WorkUtils;

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

import androidx.annotation.Nullable;
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 WorkPlanActivity extends WorkToolBarActivity {

    @BindView(R.id.tl_tab)
    TabLayout tlTab;
    @BindView(R.id.vp_data)
    ViewPager vpData;
    private String tab[] = {
            "全部", "待审核", "待接单", "待生产", "已入库"};
    private String order[] = {
            "", "100", "200", "300", "500"};
    private String identity = "2";

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

    @Override
    protected void initData() {
        FragmentManager sfm = getSupportFragmentManager();
        List<Fragment> data = new ArrayList<>();
        for (int i = 0; i < tab.length; i++) {
            CrucibleOrderBuyListFragment saleFragment = new CrucibleOrderBuyListFragment();
            Bundle bundle = new Bundle();
            bundle.putString("state", order[i]);
            bundle.putString("identity", identity);
            saleFragment.setArguments(bundle);
            data.add(saleFragment);
        }
        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() {
    }

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (WorkUtils.hasOrderDeptPermission(OrderDeptPermission.CRUCIBLE.getCode())
                &&WorkUtils.hasPermission(PagePermissionType.CO_CRUCIBLE_START.getPermission())) {
            getMenuInflater().inflate(R.menu.menu_add_and_search, menu);
        }else {
            getMenuInflater().inflate(R.menu.menu_search, menu);
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.search:
                startActivity(CrucibleOrderSearchActivity.class, "identity", "2"
                        ,"type","2");
                break;
            case R.id.add:
                startActivity(ChooseInfoActivity.class, "code", PermissionType.CRUCIBLE_SELL.getCode(),
                        "type", "5", "deptId",  "-1");
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
