package com.unis.sxzcl.ui.house;

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

import androidx.fragment.app.Fragment;

import com.unis.model.HouseModel;
import com.unis.model.bean.HouseListBean;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentBaseTabPagerBinding;
import com.unis.sxzcl.ui.basic.PersonDetailFragment;
import com.unis.sxzcl.widget.TabFragmentPagerAdapter;
import com.xyxsbj.mylibrary.tool.ToastTool;

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

/**
 * 包名: com.unis.sxzcl.ui.house
 * 类名: HouseHomeFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/10 10:55
 * 更新人:
 * 更新时间: 2020/12/10 10:55
 * 更新说明:
 * 版本号: 1.0
 */
public class HouseHomeFragment extends BaseFragment<FragmentBaseTabPagerBinding> {

    private List<String> mTabs = Arrays.asList("仓房信息", "保管员信息");
    private List<Fragment> mFragments;
    private HouseListBean mHouse;

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

    @Override
    protected void init() {
        mHouse = HouseModel.get().getSelectHouse();
        if (mHouse == null) {
            ToastTool.showLong("没有选择仓房");
            onBack();
            return;
        }
        mBinding.bar.setTitle("仓房信息(" + mHouse.houseName + ")")
                .setLeftClickListener(v -> onBack());

        initFragment();
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
        TabFragmentPagerAdapter adapter = new TabFragmentPagerAdapter(
                getChildFragmentManager(), mTabs, mFragments);
        mBinding.viewPager.setAdapter(adapter);
        mBinding.viewPager.setOffscreenPageLimit(mFragments.size());
    }

    private void initFragment() {
        mFragments = new ArrayList<>();
        mFragments.add(new HouseDetailFragment());

        mFragments.add(PersonDetailFragment.newFragment(false, null, mHouse.houseCode));
    }

    @Override
    protected void onFirstShow() {

    }
}