package rallyedto.epicalyxedto.rodedto.trunkedto

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import rallyedto.talledto.blewedto.Musicaledto
import rallyedto.talledto.blewedto.Pianoedto

class Magnetedto : BroadcastReceiver() {

    private val TAG = "CloseNotificationReceiver"

    companion object {
        var Action = "CANCEL_NOTIFICATION"
        var NotificationId = "NOTIFICATION_ID"
    }

    override fun onReceive(context: Context?, intent: Intent?) {
        Musicaledto.logDebug(TAG, "onReceive")
        val action = intent?.action ?: ""
        Obscureedto.stopNotificationHandler()
        if (action == Action) {
            var notificationId = intent?.extras?.getInt(NotificationId, 0) ?: 0
            Musicaledto.logDebug(TAG, "notificationId=$notificationId")
            val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            val actionS = Pianoedto.getInstance().getString("actionS", "0") ?: "0"
            runCatching {
                if (actionS.toInt() == 0) {
                    notificationId = 0
                }
            }
            notificationManager.cancel(notificationId)
        }
    }
}