package org.keyscience.fragments;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

import org.keyscience.R;
import org.keyscience.adapters.ChartsAccordionAdapter;
import org.keyscience.adapters.NavDrawerAdapter;
import org.keyscience.adapters.WaterWatchListAdapter;
import org.keyscience.models.NavDrawerItem;

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

public class WaterWatchFragment extends Fragment {
    private Context context;

    private List<String> parentItems;
    private Map<String, List<String>> childItems;

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

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

        setUpRecyclerView(view);

        return view;
    }

    private void setUpRecyclerView(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.chartsList);
        WaterWatchListAdapter adapter = new WaterWatchListAdapter(getActivity());
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

    private void htmlParagraphs(View v) {
        // Paragraphs that require HTML
        String wwText1 = getResources().getString(R.string.waterwatch_Text1);
        TextView txtParagraph1 = v.findViewById(R.id.wwTextView1);
        txtParagraph1.setText(Html.fromHtml(wwText1));

        String wwText2 = getResources().getString(R.string.waterwatch_Text2);
        TextView txtParagraph2 = v.findViewById(R.id.wwTextView2);
        txtParagraph2.setText(Html.fromHtml(wwText2));

        String wwText3 = getResources().getString(R.string.waterwatch_Text3);
        TextView txtParagraph3 = v.findViewById(R.id.wwTextView3);
        txtParagraph3.setText(Html.fromHtml(wwText3));

        String wwText4 = getResources().getString(R.string.waterwatch_Text4);
        TextView txtParagraph4 = v.findViewById(R.id.wwTextView4);
        txtParagraph4.setText(Html.fromHtml(wwText4));

        String wwText5 = getResources().getString(R.string.waterwatch_Text5);
        TextView txtParagraph5 = v.findViewById(R.id.wwTextView5);
        txtParagraph5.setText(Html.fromHtml(wwText5));

        String wwText6 = getResources().getString(R.string.waterwatch_Text6);
        TextView txtParagraph6 = v.findViewById(R.id.wwTextView6);
        txtParagraph6.setText(Html.fromHtml(wwText6));

        txtParagraph3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://sfyl.ifas.ufl.edu/miami-dade/natural-resources/biscayne-bay-water-watch-/"));
                startActivity(browserIntent);
            }
        });

        txtParagraph4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://sfyl.ifas.ufl.edu/media/sfylifasufledu/miami-dade/documents/sea-grant/Dissolved-Oxygen.pdf"));
                startActivity(browserIntent);
            }
        });

        txtParagraph5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://sfyl.ifas.ufl.edu/media/sfylifasufledu/miami-dade/documents/sea-grant/Nutrients.pdf"));
                startActivity(browserIntent);
            }
        });

        txtParagraph6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://sfyl.ifas.ufl.edu/media/sfylifasufledu/miami-dade/documents/sea-grant/Chlorophyll-a.pdf"));
                startActivity(browserIntent);
            }
        });
    }
}
