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.ThreeMenuClickListener;
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 FinancialTicketFilterData {
    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("全部状态", "待审核", "已通过","已驳回");
    ThreeMenuClickListener listener;

    String[] TABLIST = new String[]{ "销售订单", "全部状态"};
    Context context;
    public FinancialTicketFilterData(Context context, DropDownMenu menu, ThreeMenuClickListener listener) {
        this.menu = menu;
        this.context=context;
        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(statusList , 1);
        addTabView(typeList, 2);
        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;
    }
}
