package com.app.simplitend.welcome.welcomepatient.fragments.register;

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

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

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.app.simplitend.R;
import com.app.simplitend.databinding.ThankYouFragmentBinding;

public class ThankYouFragment extends Fragment {

    // view binding
    protected ThankYouFragmentBinding binding;

    public ThankYouFragment(){
        // required empty const.
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = ThankYouFragmentBinding.inflate(inflater, container, false);

        initializeViews(savedInstanceState);

        clickEvents();

        return binding.getRoot();
    }

    private void initializeViews(Bundle savedInstanceState) {
        // showing anim
        Glide.with(requireContext())
                .asGif()
                .load(R.raw.done_anim)
                .listener(new RequestListener<GifDrawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
                        resource.setLoopCount(1);
                        return false;
                    }
                })
                .into(binding.animIv);
    }

    private void clickEvents() {
        binding.proceed.setOnClickListener(v ->
                Navigation.findNavController(v).navigate(R.id.action_thankYouFragment_to_createContactFragment)
        );
    }
}

