package com.wd.workoffice.ui.activity;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.vo.BatLayoutVo;
import com.wd.workoffice.ui.activity.bat.order.product.ProductInsideOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.product.ProductOutOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.product.ProductSaleOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.product.ProductSupplierOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleCrucibleOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleInsideOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleOutOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleProductOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleSaleOrderActivity;
import com.wd.workoffice.ui.activity.bat.order.sale.SaleSupplierOrderActivity;
import com.wd.workoffice.ui.adapter.BatLayoutAdapter;

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

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class WorkOrderActivity extends WorkToolBarActivity {
    @BindView(R.id.rv_sale)
    RecyclerView rvSale;
    @BindView(R.id.rv_product)
    RecyclerView rvProduct;
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;
    List<BatLayoutVo> saleList = new ArrayList<>();
    List<BatLayoutVo> productList = new ArrayList<>();
    int[] saleImg = new int[]{R.mipmap.order_sale1, R.mipmap.order_sale2, R.mipmap.order_sale3, R.mipmap.order_sale4, R.mipmap.order_sale5, R.mipmap.order_sale6};
    String[] saleName = new String[]{"销售订单", "外采购订单", "供应订单", "内部订单", "组装订单", "坩埚订单"};
    int[] productImg = new int[]{R.mipmap.order_product1, R.mipmap.order_product2, R.mipmap.order_product3, R.mipmap.order_product4, R.mipmap.order_product5, R.mipmap.order_product6};
    String[] productName = new String[]{"销售订单", "外采购订单", "供应订单", "内部订单", "组装订单", "坩埚订单"};

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        addDate(saleList, saleImg, saleName);
        addDate(productList, productImg, productName);
        initRvLayout(rvSale, saleList);
        initRvLayout(rvProduct, productList);

    }
    private void addDate(List<BatLayoutVo> saleList, int[] saleImg, String[] saleName) {
        for (int i = 0; i < saleImg.length; i++) {
            BatLayoutVo batLayoutVo = new BatLayoutVo();
            batLayoutVo.setImg(saleImg[i]);
            batLayoutVo.setName(saleName[i]);
            saleList.add(batLayoutVo);
        }

    }
    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        srlRefresh.setOnRefreshListener(refreshLayout -> {
            srlRefresh.finishRefresh();
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_work_order;
    }
    /**
     * 初始化布局
     *
     * @param rvSale
     * @param saleList
     */
    private void initRvLayout(RecyclerView rvSale, List<BatLayoutVo> saleList) {
        rvSale.setLayoutManager(new GridLayoutManager(this, 4, RecyclerView.VERTICAL,
                false));
        BatLayoutAdapter batLayoutAdapter = new BatLayoutAdapter(R.layout.item_bat_layout, saleList);
        batLayoutAdapter.bindToRecyclerView(rvSale);
        switch (rvSale.getId()) {
            case R.id.rv_sale:
                batLayoutAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                        switch (position) {
                            case 0:
                                startActivity(SaleSaleOrderActivity.class, "identity", "1");
                                break;
                            case 1:
                                startActivity(SaleOutOrderActivity.class, "identity", "1");
                                break;
                            case 2:
                                startActivity(SaleSupplierOrderActivity.class, "identity", "1");
                                break;
                            case 3:
                                startActivity(SaleInsideOrderActivity.class, "identity", "1");
                                break;
                            case 4:
                                startActivity(SaleProductOrderActivity.class, "identity", "1");
                                break;
                            case 5:
                                startActivity(SaleCrucibleOrderActivity.class, "identity", "1");
                                break;
                        }
                    }
                });
                break;
            case R.id.rv_product:
                batLayoutAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                        switch (position) {
                            case 0:
                                startActivity(ProductSaleOrderActivity.class);
                                break;
                            case 1:
                                startActivity(ProductOutOrderActivity.class);
                                break;
                            case 2:
                                startActivity(ProductSupplierOrderActivity.class);
                                break;
                            case 3:
                                startActivity(ProductInsideOrderActivity.class);
                                break;
                            case 4:
                                startActivity(SaleProductOrderActivity.class, "identity", "2");
                                break;
                            case 5:
                                startActivity(SaleCrucibleOrderActivity.class, "identity", "2");
                                break;
                        }
                    }
                });
                break;
        }
    }

}
