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.WorkApp;
import com.wd.workoffice.bean.listener.FiveMenuClickListener;
import com.wd.workoffice.bean.listener.FourMenuClickListener;
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 MesUserDataListFilterData {
    DropDownMenu menu;
    private List<View> viewList;
    private View mainView;
    private RecyclerView rvData;
    private SmartRefreshLayout srlRefresh;
    private List<String> statusList = Arrays.asList("反馈日期", "产品名称", "制单日期", "任务状态");
    private List<String> typeList = Arrays.asList("全部类型", "厂内库", "场外库");
    FiveMenuClickListener listener;

    String[] TABLIST = new String[]{"反馈日期", "客户信息", "炼钢厂", "连铸机", "状态"};
    Context context;

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


    private void initView() {
        mainView = LayoutInflater.from(context).inflate(R.layout.view_user_data, 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(typeList, 1);
        addTabView(statusList, 2);
        addTabView(typeList, 3);
        addTabView(typeList, 4);
        addTabView(typeList, 5);
        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;
                }
            }
            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;
    }
}
