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.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.bpa.Model.IMessageLogNotify;
import com.example.bpa.R;
import com.example.bpa.config.ConfigName;
import com.example.bpa.db.QueryDB;
import com.example.bpa.db.mode.BPA_LOG;
import com.example.bpa.helper.MessageLog;
import com.example.bpa.view.fragment.setting.Fragment_lcparameter;

/**
 * 系统设置界面
 */
public class SystemSetFragment extends Fragment implements View.OnClickListener {


    View view;
    private Button btn_system_set;

    private Button btn_lc_set;

    private Fragment lcparameter;
    private Fragment SelectFragment;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_system_set, container,false);
        Init();
        initEvent();
        return view;

    }

    private void Init() {
        lcparameter = new Fragment_lcparameter();
        btn_system_set = view.findViewById(R.id.stparameter);
        btn_lc_set = view.findViewById(R.id.lcparameter);
        MessageLog.MsgNotify = new IMessageLogNotify() {
            @Override
            public void ErrorMsg(String msg) {
                Log.e("Error", msg);

            }

            @Override
            public void InfoMsg(String msg,String datetime) {
                BPA_LOG log = new BPA_LOG();
                log.userID = ConfigName.getInstance().user.userID;
                log.createTime = datetime;
                log.type = 1;
                log.text = msg;
                QueryDB.Addlog(log);
                Log.i("Info", msg);
            }
            @Override
            public void WarnMsg(String msg) {
                Log.w("Warn", msg);
            }
        };


    }

    private void initEvent(){
        btn_system_set.setOnClickListener(this);
        btn_lc_set.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.stparameter://返回按钮
                Log.d("页面", "onClick: ");
                break;
                case R.id.lcparameter://返回按钮
                    ShowFragment(lcparameter);
                    break;


        }
    }


    public void ShowFragment(Fragment fragment)
    {
        FragmentManager manager = getChildFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        if(SelectFragment!=null)
        {
            transaction.remove(SelectFragment);
        }
        transaction.add(R.id.fragment_container, fragment);
        transaction.commit();
        SelectFragment=fragment;
    }
}