package com.example.maposv2;

import android.content.Intent;
import android.graphics.BlurMaskFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;

import com.example.maposv2.databinding.FragmentPolicie1Binding;

public class FragmentPolicieFirst extends Fragment {

    private FragmentPolicie1Binding binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentPolicie1Binding.inflate(inflater, container, false);
        View view = binding.getRoot();
        setHasOptionsMenu(true);
        // Add function to call phone number
        binding.buttonPolVolat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:158"));
                startActivity(intent);
            }
        });

        // Add function to open url for button 1
        binding.buttonPolVolat112.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:112"));
                startActivity(intent);
            }
        });

        // Add function to open url for button 2
        binding.buttonPolDalsi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavHostFragment.findNavController(FragmentPolicieFirst.this)
                        .navigate(R.id.action_FragmentPolicieFirst_to_FragmentPolicieSecond);
            }
        });

        // Set background with blur effect
        /*Paint paint = new Paint();
        paint.setMaskFilter(new BlurMaskFilter(16, BlurMaskFilter.Blur.NORMAL));
        int color = ContextCompat.getColor(requireContext(), android.R.color.white);
        paint.setColor(color);
        paint.setStyle(Paint.Style.FILL);
        binding.redFrame.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        binding.redFrame.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        binding.redFrame.getBackground().setAlpha(128);*/

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        // hide the options menu in this fragment
        menu.findItem(R.id.action_settings).setVisible(false);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public void onPrepareOptionsMenu(@NonNull Menu menu) {
        super.onPrepareOptionsMenu(menu);
        menu.findItem(R.id.action_settings).setVisible(false);
    }
}
