package com.wd.workoffice.util.ddmfilter;

import android.content.Context;
import android.text.TextUtils;
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.workEnum.PagePermissionType;
import com.wd.workoffice.ui.adapter.FilterAdapter;
import com.wd.workoffice.util.WorkUtils;
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 FinancialReceiveTicketFilterData {
    DropDownMenu menu;
    private List<View> viewList;
    private View mainView;
    private RecyclerView rvData;
    private SmartRefreshLayout srlRefresh;
    //    private List<String> statusList = Arrays.asList("供应订单", "外采购订单");
    List<String> statusList = new ArrayList<>();
    private List<String> typeList = Arrays.asList("全部状态", "待审核", "已通过", "已驳回");
    ThreeMenuClickListener listener;

    String[] TABLIST = new String[]{"", "全部状态"};
    Context context;

    public FinancialReceiveTicketFilterData(Context context, DropDownMenu menu, ThreeMenuClickListener listener) {
        this.menu = menu;
        this.context = context;
        this.listener = listener;
        if (WorkUtils.hasPermission(PagePermissionType.FO_RECEIPT_LIST.getPermission())) {
            statusList.add("供应订单");
        }
        if (WorkUtils.hasPermission(PagePermissionType.PO_RECEIPT_LIST.getPermission())) {
            statusList.add("外采购订单");
        }
        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);
        if (statusList.size() != 0) {
            TABLIST[0] = statusList.get(0);
        }
        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;
    }

    public List<String> getStatusList() {
        return statusList;
    }

    public void setStatusList(List<String> statusList) {
        this.statusList = statusList;
    }
}
