package com.cscodetech.movers.ui.findlorry;

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

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.cscodetech.movers.R;
import com.cscodetech.movers.databinding.ActivityMyBookLoadBinding;
import com.cscodetech.movers.ui.BaseActivity;

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

public class MyBookLoadActivity extends BaseActivity {

    private ActivityMyBookLoadBinding binding;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMyBookLoadBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        TabFragmentAdapter adapter = new TabFragmentAdapter(getSupportFragmentManager());
        adapter.addFragment(CurrentBookLoadFragment.newInstance(), getString(R.string.mycurrentloads));
        adapter.addFragment(CompletBookLoadFragment.newInstance(), getString(R.string.completed));
        binding.viewPager.setAdapter(adapter);
        binding.tab.setupWithViewPager(binding.viewPager);
        binding.imgBack.setOnClickListener(this::onBindClick);


    }

    public void onBindClick(View view) {
        if (view.getId() == R.id.img_back) {
            finish();
        }
    }

    public class TabFragmentAdapter extends FragmentPagerAdapter {
        private final List<Fragment> fragmentList = new ArrayList<>();
        private final List<String> fragmentTitleList = new ArrayList<>();

        public TabFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragmentList.get(i);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return fragmentTitleList.get(position);
        }

        public void addFragment(Fragment fragment, String title) {
            fragmentList.add(fragment);
            fragmentTitleList.add(title);
        }
    }
}