package com.bonait.bnframework.modules.home.fragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.bonait.bnframework.HBL.Dialog.AlertDialogButton;
import com.bonait.bnframework.HBL.Dialog.DialogManager;
import com.bonait.bnframework.HttpModel.APIService;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.MessageName;
import com.bonait.bnframework.common.message.MessageManager;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.modules.home.fragment.from.GoodPeiFangActivity;
import com.bonait.bnframework.modules.home.fragment.from.JcsjglActivity;
import com.bonait.bnframework.modules.home.fragment.from.LogActivity;
import com.bonait.bnframework.modules.home.fragment.from.RealTimeActivity;
import com.bonait.bnframework.modules.home.fragment.from.SilosNewActivity;
import com.bonait.bnframework.modules.home.fragment.mode.caidan_control;
import com.orhanobut.logger.Logger;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GongnengFragment extends BaseFragment {

    @BindView(R.id.topbar)
    QMUITopBarLayout mTopBar;//顶部标题

    @BindView(R.id.btn_sync)
    Button btn_Sync;

    private Context context;

    public GongnengFragment() {
    }

    @Override
    protected View onCreateView() {
        View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_gongneng, null);
        ButterKnife.bind(this, root);
        return root;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        context = getContext();
        initTopBar();
    }

    /**
     * 初始化TopBar
     */
    private void initTopBar() {
        mTopBar.setTitle("功能菜单");
        btn_Sync.setOnClickListener(v->{
            DialogManager.showWarn(context,"同步云端商品会参数本地所有配方数据，\r\n请问是否继续？", AlertDialogButton.YesNo,(s)->{
                if(s){
                    APIService.MainInit();
                    ToastUtils.info("同步成功");
                }
            });
        });
    }
    @OnClick({R.id.jcsjgl,R.id.lcgl,R.id.yfpf,R.id.log,R.id.ssjk})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.jcsjgl://
                skipToActivity(JcsjglActivity.class);
                //ConfigName.getInstance().fragmentAdapter.replaceFragment(0,new JcsjglActivity());
                break;
            case R.id.lcgl://
                skipToActivity(SilosNewActivity.class);
                //ConfigName.getInstance().fragmentAdapter.replaceFragment(0,new SilosActivity());
                break;
            case R.id.yfpf://
                skipToActivity(GoodPeiFangActivity.class);
                //ConfigName.getInstance().fragmentAdapter.replaceFragment(0,new GoodPeiFangActivity());
                break;
            case R.id.log://
                skipToActivity(LogActivity.class);
                //ConfigName.getInstance().fragmentAdapter.replaceFragment(0,new GoodPeiFangActivity());
                break;
            case R.id.ssjk://
                skipToActivity(RealTimeActivity.class);
                //ConfigName.getInstance().fragmentAdapter.replaceFragment(0,new GoodPeiFangActivity());
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Logger.d("第一页销毁");
    }

    /**
     * 当在activity设置viewPager + BottomNavigation + fragment时，
     * 为防止viewPager左滑动切换界面，与fragment左滑返回上一界面冲突引起闪退问题，
     * 必须加上此方法，禁止fragment左滑返回上一界面。
     * <p>
     * 切记！切记！切记！否则会闪退！
     * <p>
     * 当在fragment设置viewPager + BottomNavigation + fragment时，则不会出现这个问题。
     */
    @Override
    protected boolean canDragBack() {
        return false;
    }
}