package com.wd.workoffice.util.ddmfilter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.Config;
import com.wd.workoffice.app.WorkApp;
import com.wd.workoffice.bean.listener.WarehouseOrderFilterClickListener;
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 WarehouseOrderFilterData {
    DropDownMenu menu;
    private List<View> viewList;
    private View mainView;
    private RecyclerView rvData;
    private SmartRefreshLayout srlRefresh;
    WarehouseOrderFilterClickListener listener;

    String[] TABLIST = new String[]{"全部类型"};
    Context context;

    public WarehouseOrderFilterData(Context context, DropDownMenu menu, WarehouseOrderFilterClickListener listener) {
        this.context = context;
        this.menu = menu;
        this.listener = listener;
        initView();
    }


    private void initView() {
        mainView = LayoutInflater.from(context).inflate(R.layout.view_pro, null);
        rvData = mainView.findViewById(R.id.rv_data);
        srlRefresh = mainView.findViewById(R.id.srl_refresh);
        rvData.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
        viewList = new ArrayList<>();
        addTabView(Config.WAREHOUSE_STATUS_LIST, 1);
        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) {
                listener.clickType(Config.WAREHOUSE_CODE_LIST.get(position));
            }
            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;
    }
}
