package com.wd.workoffice.util.ddmfilter;

import android.view.LayoutInflater;
import android.view.View;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkApp;
import com.wd.workoffice.bean.listener.ThreeMenuClickListener;
import com.wd.workoffice.bean.listener.WarehouseFilterClickListener;
import com.wd.workoffice.ui.adapter.FilterAdapter;
import com.wd.workoffice.widget.DropDownMenu;

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

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class InSotckFilterData {
    DropDownMenu menu;
    private List<View> viewList;
    private View mainView;
    private RecyclerView rvData;
    private SmartRefreshLayout srlRefresh;
    private List<String> levelList = Arrays.asList("全部类型", "一级库", "二级库");
    private List<String> statusList = Arrays.asList("全部状态", "未启用", "已启用");
    private List<String> typeList = Arrays.asList("全部类型", "厂内库", "场外库");
    ThreeMenuClickListener listener;

    String[] TABLIST = new String[]{"层级", "区分", "状态"};

    public InSotckFilterData(DropDownMenu menu, ThreeMenuClickListener listener) {
        this.menu = menu;
        this.listener = listener;
        initView();
    }


    private void initView() {
        mainView = LayoutInflater.from(WorkApp.getApp()).inflate(R.layout.view_pro, null);
        rvData = mainView.findViewById(R.id.rv_data);
        srlRefresh = mainView.findViewById(R.id.srl_refresh);
        rvData.setLayoutManager(new LinearLayoutManager(WorkApp.getApp(), RecyclerView.VERTICAL, false));
        viewList = new ArrayList<>();
        addTabView(levelList, 1);
        addTabView(typeList, 2);
        addTabView(statusList, 3);
        menu.setDropDownMenu(Arrays.asList(TABLIST), viewList, mainView);
    }

    private void addTabView(List<String> dataList, int type) {
        View view = LayoutInflater.from(WorkApp.getApp()).inflate(R.layout.view_filter_pro, null);
        RecyclerView rvData = view.findViewById(R.id.rv_filter);
        rvData.setLayoutManager(new LinearLayoutManager(WorkApp.getApp(), RecyclerView.VERTICAL, false));
        FilterAdapter filterAdapter = new FilterAdapter(R.layout.item_filter, dataList);
        filterAdapter.bindToRecyclerView(rvData);
        viewList.add(view);
        filterAdapter.setOnItemClickListener((adapter, v, position) -> {
            filterAdapter.setChoosePos(position);
            menu.setTabText(dataList.get(position));
            if (listener != null) {
                switch (type) {
                    case 1:
                        listener.clickOne(dataList.get(position));
                        break;
                    case 2:
                        listener.clickTwo(dataList.get(position));
                        break;
                    case 3:
                        listener.clickThree(dataList.get(position));
                        break;
                }
            }
            menu.closeMenu();
            filterAdapter.notifyDataSetChanged();
        });
    }


    public SmartRefreshLayout getSrlRefresh() {
        return srlRefresh;
    }

    public void setSrlRefresh(SmartRefreshLayout srlRefresh) {
        this.srlRefresh = srlRefresh;
    }

    public RecyclerView getRvData() {

        return rvData;
    }


    public void setRvData(RecyclerView rvData) {
        this.rvData = rvData;
    }
}
