package com.example.status_saver.fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.cv.status.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.hbb20.CountryCodePicker;


public class ChatFragment extends Fragment {
    TextView msg;
    EditText number;
    CountryCodePicker cpp;
    FloatingActionButton sendmsg;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_chat, container, false);
        number = view.findViewById(R.id.number);
        msg = view.findViewById(R.id.largeTextField);
        sendmsg = view.findViewById(R.id.sendMesaage);
        cpp = view.findViewById(R.id.cpp);
        sendmsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                send();
                msg.setText("");
                number.setText("");
            }
        });
       // MyNotificationListenerService ob =new MyNotificationListenerService();


        return view;
    }

    private void send() {
        String phoneNumber1 = number.getText().toString();
        String message = msg.getText().toString();
        cpp.registerCarrierNumberEditText(number);
        String phoneNumber = cpp.getFullNumber();
        if (phoneNumber1.isEmpty()) {
            Toast.makeText(getContext(), "Please Enter Mobile number", Toast.LENGTH_SHORT).show();
        } else {

            Uri uri = Uri.parse("https://api.whatsapp.com/send?phone=" + phoneNumber + "&text=" + message);
            // val uri = Uri.parse("https://api.whatsapp.com/send?phone=$phoneNumber&text=$message")
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setPackage("com.whatsapp");

            // Start the activity with the intent
            startActivity(intent);

        }

    }
}