package com.example.chemical.ui.plan.change;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.chemical.databinding.FragmentChangeCabinetBinding;
import com.example.chemical.databinding.IncludeCabinetBinding;
import com.example.chemical.ui.plan.FragmentCallBack;
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetVo;

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

public class ChangeCabinetFragment extends Fragment {
    private List<HxpCabinetVo> hxpCabinetVoList;
    private FragmentCallBack fragmentCallBack;
    private FragmentChangeCabinetBinding binding;
    private List<ChangeCabinetHelp> changeCabinetHelpList = new ArrayList<>();

    public ChangeCabinetFragment(List<HxpCabinetVo> hxpCabinetVos, FragmentCallBack fragmentCallBack) {
        this.hxpCabinetVoList = hxpCabinetVos;
        this.fragmentCallBack = fragmentCallBack;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentChangeCabinetBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
//        if (null != savedInstanceState) {
//            for (int i = 0; i < changeCabinetHelpList.size(); i++) {
//                changeCabinetHelpList.get(i).recycle();
//            }
//            binding.main.removeAllViewsInLayout();
//        }
        for (int i = 0; i < hxpCabinetVoList.size(); i++) {
            HxpCabinetVo hxpCabinetVo = hxpCabinetVoList.get(i);
            IncludeCabinetBinding includeCabinetBinding = IncludeCabinetBinding.inflate(getLayoutInflater());
            changeCabinetHelpList.add(new ChangeCabinetHelp(includeCabinetBinding, hxpCabinetVo, fragmentCallBack));
            binding.main.addView(includeCabinetBinding.getRoot());
        }
    }
}
