package com.unis.sxzcl.ui.facility;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentBaseTabPagerBinding;
import com.unis.sxzcl.ui.facility.facility_check.FacilityCheckLastFragment;
import com.unis.sxzcl.widget.TabFragmentPagerAdapter;

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

/**
 * 设施管理
 * 创建人: mQ
 * 创建时间: 2021/3/23 16:07
 */
public class FacilityHomeFragment extends BaseFragment<FragmentBaseTabPagerBinding> {

    private List<String> mTabs;
    private List<Fragment> mFragments;

    @Override
    protected FragmentBaseTabPagerBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentBaseTabPagerBinding.inflate(inflater, container, false);
    }

    @Override
    protected void init() {
        mBinding.bar.setTitle("设施检查记录")
                .setLeftClickListener(v -> onBack());
    }

    @Override
    protected void onFirstShow() {
        // 初始化Fragment
        initFragment();

        // 配置TabLayout和ViewPager
        mBinding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
        TabFragmentPagerAdapter adapter = new TabFragmentPagerAdapter(
                getChildFragmentManager(), mTabs, mFragments);
        mBinding.viewPager.setAdapter(adapter);
        mBinding.viewPager.setOffscreenPageLimit(mFragments.size());

    }

    /**
     * 创建标签和Fragment
     */
    private void initFragment() {
        mTabs = new ArrayList<>();
        mTabs.add("设施检查");
//        mTabs.add("设施维修和改造");

        mFragments = new ArrayList<>();
        mFragments.add(new FacilityCheckLastFragment());
    }


}
