package com.rdiot.yx485.device.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import com.bumptech.glide.Glide;
import com.rdiot.yx485.BaseActivity;
import com.rdiot.yx485.bean.DeviceTreeBean;
import com.rdiot.yx485.databinding.ActivityResetBinding;
import com.rdiot.yx485.http.Url;

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

public class ResetActivity extends BaseActivity {
    private ActivityResetBinding mBiding;

    public static void newIntent(Context context, Bundle bundle, List<DeviceTreeBean.DataBean.ChildrenBean.StepsBean> steps) {
        Intent intent = new Intent(context, ResetActivity.class);
        intent.putParcelableArrayListExtra("data", (ArrayList<? extends Parcelable>) steps);
        intent.putExtra("bundle", bundle);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        WindowManager.LayoutParams attrs = getWindow().getAttributes();
//        attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//        getWindow().setAttributes(attrs);
        mBiding = ActivityResetBinding.inflate(getLayoutInflater());
        setContentView(mBiding.btnNext.getRootView());
        init();
    }

    private void init() {
//        /** 绑定分控标志 */
//        boolean isBindSub = getIntent().getBooleanExtra("isBindSub", false);
//        /** 绑定永续精灵标志 */
//        boolean isBindInfrared = getIntent().getBooleanExtra("isBindInfrared", false);
//        mBiding.viewOne.setVisibility(isBindSub || isBindInfrared ? View.GONE : View.VISIBLE);
//        mBiding.viewTwo.setVisibility(isBindSub ? View.VISIBLE : View.GONE);
//        mBiding.viewThree.setVisibility(isBindSub ? View.VISIBLE : View.GONE);
//        mBiding.viewFour.setVisibility(isBindInfrared ? View.VISIBLE : View.GONE);
//        mBiding.viewFive.setVisibility(isBindInfrared ? View.VISIBLE : View.GONE);
        List<DeviceTreeBean.DataBean.ChildrenBean.StepsBean> stepsBeanList = getIntent().getParcelableArrayListExtra("data");
        if (stepsBeanList != null && stepsBeanList.size() > 0) {
            if (stepsBeanList.get(0) != null) {
                mBiding.resetOneDec.setText(stepsBeanList.get(0).desc);
                if (stepsBeanList.get(0).photo != null) {
                    Glide.with(this)
                            .load(Url.BASE_URL + stepsBeanList.get(0).photo)
                            //   .error(Glide.with(this).load(R.drawable.img_reset_1))
                            .into(mBiding.resetOneImg);
                }
            }
            if (stepsBeanList.size() > 1 && stepsBeanList.get(1) != null) {
                mBiding.resetTwoDec.setText(stepsBeanList.get(1).desc);
                if (stepsBeanList.get(1).photo != null) {
                    Glide.with(this)
                            .load(Url.BASE_URL + stepsBeanList.get(1).photo)
                            //  .error(Glide.with(this).load(R.drawable.img_reset_2))
                            .into(mBiding.resetTwoImg);
                }
            }
        }

        mBiding.btnNext.setOnClickListener(view ->
                EnterRoomInfoActivity.Companion.newIntent(ResetActivity.this,
                        Objects.requireNonNull(getIntent().getBundleExtra("bundle"))));
        mBiding.layoutTitle.btnTitleLeft.setOnClickListener(view -> finish());

    }
}
