package com.wd.workoffice.ui.fg;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkBaseFg;
import com.wd.workoffice.bean.workEnum.PagePermissionType;
import com.wd.workoffice.ui.adapter.VpDataAdapter;
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 ProductOrderApplyFragment extends WorkBaseFg {

    @BindView(R.id.tl_tab)
    TabLayout tlTab;
    @BindView(R.id.vp_data)
    ViewPager vpData;
    private String tab[] = {
            "未审核", "已通过", "已驳回"};
    private String order[] = {
            "0", "1", "2"};
    private String identity;

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

    @Override
    protected void initData() {
        if (!WorkUtils.hasPermission(PagePermissionType.AO_PACKAGE_APPLY_LIST.getPermission())) {
            toast(R.string.permission);
            return;
        }
        FragmentManager sfm = getChildFragmentManager();
        List<Fragment> data = new ArrayList<>();
        for (int i = 0; i < tab.length; i++) {
            ProductOrderApplyListFragment saleFragment = new ProductOrderApplyListFragment();
            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
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments != null) {
            identity = arguments.getString("identity");
        }
    }

    @Override
    protected void initEvent() {
    }

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