package com.example.bpa.view.fragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.bpa.LoginActivity;
import com.example.bpa.MainActivity;
import com.example.bpa.R;
import com.example.bpa.config.ConfigName;
import com.example.bpa.helper.T;
import com.example.bpa.view.control.ItemClickListener;
import com.example.bpa.view.control.MainMeunAdapter;
import com.example.bpa.view.control.MyLayoutManager;
import com.example.bpa.view.from.ddyjrz_activity;
import com.example.bpa.view.from.dzcjy_activity;
import com.example.bpa.view.from.lcsz_activity;
import com.example.bpa.view.from.lsjy_activity;
import com.example.bpa.view.from.wlgl_activity;
import com.example.bpa.view.from.yfcl_activity;
import com.example.bpa.view.from.yfpf_activity;
import com.example.bpa.view.from.ygczrz_activity;
import com.example.bpa.view.from.zdqx_activity;
import com.example.bpa.view.mode.MenuMode;

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

/**
 * 系统功能界面
 */
public class SystemCapabilitiesFragment extends Fragment {

    //region 变量
    RecyclerView recyclerView;
    RelativeLayout recycler_view_container;
    View view;
    MainMeunAdapter adapter;
    List<MenuMode> menuModes = new ArrayList<>();
    //endregion

    //region 私有函数
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_system_capabilities, container,false);
        Init();
        initEvents();
        return view;
    }
    //endregion
    //region 公有函数
    /**
     * 初始化
     */
    private void Init() {
        recyclerView = view.findViewById(R.id.recycler_view);
        recycler_view_container=(RelativeLayout) view.findViewById(R.id.recycler_view_container);

        menuModes.clear();
        menuModes.add(new MenuMode("物料管理",R.mipmap.wlgl));
        menuModes.add(new MenuMode("料仓设置",R.mipmap.lcsz));
        menuModes.add(new MenuMode("电子秤校验",R.mipmap.dzcjy));
        menuModes.add(new MenuMode("流速校验",R.mipmap.lsjy));
        menuModes.add(new MenuMode("自动清洗",R.mipmap.zdqx));
        menuModes.add(new MenuMode("研发出料",R.mipmap.yfcl));
        menuModes.add(new MenuMode("订单预警日志",R.mipmap.gjrz));
        menuModes.add(new MenuMode("员工操作日志",R.mipmap.czrz));
        menuModes.add(new MenuMode("配方研发",R.mipmap.yfpf));

        MyLayoutManager layout = new MyLayoutManager();
        //必须，防止recyclerview高度为wrap时测量item高度0
        layout.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layout);
        adapter = new MainMeunAdapter(view.getContext(), menuModes);
        recyclerView.setAdapter(adapter);
        recyclerView.addOnItemTouchListener(new ItemClickListener(recyclerView, new ItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
//             list.remove(position);
//            adapter.notifyItemRemoved(position);
                TextView textView = (TextView) view.findViewById(R.id.meun_textview);
                T.show(view.getContext(),"打开窗体："+ textView.getText().toString());
                Intent intent;
                switch (textView.getText().toString())
                {
                    case "物料管理":
                        intent = new Intent(view.getContext(), wlgl_activity.class);
                        break;
                    case "料仓设置":
                        intent = new Intent(view.getContext(), lcsz_activity.class);
                        break;
                    case "电子秤校验":
                        intent = new Intent(view.getContext(), dzcjy_activity.class);
                        break;
                    case "流速校验":
                        intent = new Intent(view.getContext(), lsjy_activity.class);
                        break;
                    case "自动清洗":
                        intent = new Intent(view.getContext(), zdqx_activity.class);
                        break;
                    case "研发出料":
                        intent = new Intent(view.getContext(), yfcl_activity.class);
                        break;
                    case "订单预警日志":
                        intent = new Intent(view.getContext(), ddyjrz_activity.class);
                        break;
                    case "员工操作日志":
                        intent = new Intent(view.getContext(), ygczrz_activity.class);
                        break;
                    case "配方研发":
                    default:
                        intent = new Intent(view.getContext(), yfpf_activity.class);
                        break;
                }
                intent.putExtra("data", textView.getText().toString());
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        }));
    }
    /**
     * 初始化按钮事件
     */
    private void initEvents() {
        //设置四个Tab的点击事件

    }
    //endregion
}