package com.tt.honeyDue.ui.screens

import android.content.Intent
import android.provider.Settings
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import com.tt.honeyDue.notifications.NotificationPreferencesStore
import com.tt.honeyDue.viewmodel.NotificationCategoriesController
import com.tt.honeyDue.viewmodel.NotificationCategoryKeys

@Composable
actual fun rememberNotificationCategoriesController(): NotificationCategoriesController? {
    val context = LocalContext.current
    return remember(context) {
        val store = NotificationPreferencesStore(context.applicationContext)
        NotificationCategoriesController(
            loadAll = {
                NotificationCategoryKeys.ALL.associateWith { id ->
                    store.isCategoryEnabled(id)
                }
            },
            setCategory = { id, enabled -> store.setCategoryEnabled(id, enabled) },
            setAll = { enabled -> store.setAllEnabled(enabled) },
        )
    }
}

@Composable
actual fun rememberOpenAppNotificationSettings(): (() -> Unit)? {
    val context = LocalContext.current
    return remember(context) {
        {
            val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
                putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            context.startActivity(intent)
        }
    }
}
