package xn.hxp.ui.login.fragment;

import android.graphics.Bitmap;
import android.os.CountDownTimer;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.ThreadUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.OnHttpListener;
import com.king.zxing.util.CodeUtils;

import java.text.SimpleDateFormat;
import java.util.Locale;

import xn.hxp.base.BaseFragment;
import xn.hxp.databinding.FragmentLoginQrBinding;
import xn.hxp.http.HttpData;
import xn.hxp.http.api.GetScanCodeApi;
import xn.hxp.room.bean.DeviceInfo;
import xn.hxp.room.bean.LabInfo;
import xn.hxp.room.bean.UserInfo;
import xn.hxp.room.tool.DeviceInfoTool;
import xn.hxp.room.tool.LabInfoTool;

public class LoginQrFragment extends BaseFragment {
    private FragmentLoginQrBinding binding;
    private DeviceInfo deviceInfo;
    private LabInfo labInfo;


    @Override
    protected ViewBinding setViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
        return binding = FragmentLoginQrBinding.inflate(inflater);
    }

    @Override
    protected void onInit() {
        ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Bitmap>() {
            @Override
            public Bitmap doInBackground() throws Throwable {
                deviceInfo = DeviceInfoTool.INSTANCE.getDeviceInfo();
                labInfo = LabInfoTool.INSTANCE.getLabInfo();
                String text = deviceInfo.getBaseUrl() + "/api/?code=" + TimeUtils.getNowString(new SimpleDateFormat("HHmmssSSS", Locale.getDefault())) + "&subId=" + labInfo.getSubjectId() + "&type=11&macId=" + deviceInfo.getSn();
                return CodeUtils.createQRCode(text, 200);
            }

            @Override
            public void onSuccess(Bitmap result) {
                if (null != result) {
                    binding.qr.setImageBitmap(result);
                }
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();


    }

    @Override
    public void onPause() {
        super.onPause();
    }
}
