package br.com.diarista.provider;

import android.graphics.Color;
import android.os.Bundle;
import android.webkit.WebView;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Necessário para @capacitor/google-maps: o mapa nativo renderiza atrás do
        // WebView, então o WebView precisa ser transparente onde o mapa é exibido.
        // (O background do body cobre isso nas telas normais — só o LocationMapDialog
        //  torna a cadeia html/body/#q-app transparente para revelar o mapa.)

        createNotificationChannel();

        getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);
    }

    @Override
    public void onStart() {
        super.onStart();
        WebView webview = getBridge().getWebView();
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
    }

    private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        Uri sound = Uri.parse(
                "android.resource://" + getPackageName() + "/" + R.raw.diaria
        );

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .build();

        NotificationChannel channel = new NotificationChannel(
                "diaria",
                "Novas Diárias",
                NotificationManager.IMPORTANCE_HIGH
        );

        channel.setDescription("Canal para novas solicitações de diária");
        channel.setShowBadge(true);
        channel.enableLights(true);
        channel.enableVibration(true);
        channel.setSound(sound, audioAttributes);

        NotificationManager notificationManager =
                getSystemService(NotificationManager.class);

        notificationManager.createNotificationChannel(channel);
    }
}
}
