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 android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

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

public class FragmentLinka extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_linka, container, false);
        setHasOptionsMenu(true);
        // Add function to call phone number
        Button buttonCall = view.findViewById(R.id.button_lin_volat);
        buttonCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:116111"));
                startActivity(intent);
            }
        });

        // Add function to open url for button 1
        Button buttonUrl1 = view.findViewById(R.id.button_lin_email);
        buttonUrl1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = "https://www.linkabezpeci.cz/napis-nam";
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });

        // Add function to open url for button 2
        Button buttonUrl2 = view.findViewById(R.id.button_lin_chat);
        buttonUrl2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = "https://chat.linkabezpeci.cz/LBCS/PUBLIC/clientlogin.jsp";
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });

        // Set background with blur effect
        /*LinearLayout frameLayout = view.findViewById(R.id.orange_frame);
        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);
        frameLayout.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        frameLayout.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        frameLayout.getBackground().setAlpha(128);*/

        return view;
    }
    @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);
    }
}
