package rowedto.jockeyedto.sheetedto.interactiveedto.twistedto

import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Dishedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Stewardedto

class Easilyedto : BroadcastReceiver() {

    private val TAG = "CloseNotificationReceiver"

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

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