package com.cygnusa.hyperm.fragments;


import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.cygnusa.hyperm.R;

public class IndroFragment extends Fragment {

    View mainView;
    int POSITION = 0;
    ImageView indroImage;
    TextView indroTitle, indroDesc;

    public IndroFragment() {

    }

    public void setPosition(int pos) {
        this.POSITION = pos;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_indro, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mainView = view;
        indroImage = mainView.findViewById(R.id.indroImage);
        indroTitle = mainView.findViewById(R.id.indroTitle);
        indroDesc = mainView.findViewById(R.id.indroDesc);

        if (POSITION == 0) {
            Glide.with(this).load(R.drawable.dash_intro_one)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(indroImage);
            String header = "<b>An ounce of prevention is worth a pound of cure.</b>";
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                indroTitle.setText(Html.fromHtml(header, Html.FROM_HTML_MODE_LEGACY));
            } else {
                indroTitle.setText(Html.fromHtml(header));
            }
            indroDesc.setText("-Benjamin Franklin");
        } else if (POSITION == 1) {
            Glide.with(this).load(R.drawable.dash_intro_two)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(indroImage);
            String header = "<b>Safety is something that happens between your ears, not something you hold in your hands.</b>";
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                indroTitle.setText(Html.fromHtml(header, Html.FROM_HTML_MODE_LEGACY));
            } else {
                indroTitle.setText(Html.fromHtml(header));
            }
            indroDesc.setText("-Jeff Cooper");
        } else if (POSITION == 2) {
            Glide.with(this).load(R.drawable.dash_intro_three)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(indroImage);
            String header = "<b>Fear is the father of courage and the mother of safety.</b>";
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                indroTitle.setText(Html.fromHtml(header, Html.FROM_HTML_MODE_LEGACY));
            } else {
                indroTitle.setText(Html.fromHtml(header));
            }
            indroDesc.setText("-Henry H Tweedy");
        }
    }

}
