package org.keyscience.fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.keyscience.R;
import org.keyscience.app.Constants;
import org.keyscience.app.HomeActivity;

import java.util.HashMap;

import static org.keyscience.fragments.SectionsStatePagerAdapter.getInstanceSectionsStatePagerAdapter;

public class ReefRestorationFragment extends Fragment {
    Context context;
    Button learnMoreButton;
    HashMap<String, Integer> fragmentMap = new HashMap<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
        context = getContext();

        View view = inflater.inflate(R.layout.reefresto_fragment, container, false);

        // Paragraphs that require HTML
        String rrSection1 = getResources().getString(R.string.reef_restoTxt1);
        TextView rr_textView2 = view.findViewById(R.id.rr_textView2);
        rr_textView2.setText(Html.fromHtml(rrSection1));

        String rrSection2 = getResources().getString(R.string.reef_restoTxt2);
        TextView rr_textView3 = view.findViewById(R.id.rr_textView3);
        rr_textView3.setText(Html.fromHtml(rrSection2));

        String rrSection3 = getResources().getString(R.string.reef_restoTxt3);
        TextView rr_textView4 = view.findViewById(R.id.rr_textView4);
        rr_textView4.setText(Html.fromHtml(rrSection3));

        AddChildActivities();

        // Button 'Learn More'
        learnMoreButton = view.findViewById(R.id.rr_learnmore_button);
        learnMoreButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((HomeActivity) context).setViewPager(fragmentMap.get(Constants.REEF_RESTORATION_CHILD));
            }
        });

        return view;
    }

    public void AddChildActivities() {
        SectionsStatePagerAdapter sectionsStatePagerAdapter = getInstanceSectionsStatePagerAdapter();
        for (int i = 0; i < sectionsStatePagerAdapter.getCount(); i++) {
            fragmentMap.put(sectionsStatePagerAdapter.getFragmentName(i), i);
        }
    }
}
