/*
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 */

package at.bitfire.davdroid.ui.intro

import android.content.Context
import androidx.compose.runtime.Composable
import at.bitfire.davdroid.ui.PermissionsScreen
import at.bitfire.davdroid.ui.PermissionsViewModel
import at.bitfire.davdroid.util.PermissionUtils
import at.bitfire.davdroid.util.PermissionUtils.CALENDAR_PERMISSIONS
import at.bitfire.davdroid.util.PermissionUtils.CONTACT_PERMISSIONS
import at.bitfire.synctools.storage.TaskProvider
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class PermissionsIntroPage @Inject constructor(
    @ApplicationContext private val context: Context
): IntroPage() {

    var model: PermissionsViewModel? = null

    override fun getShowPolicy(): ShowPolicy {
        // show PermissionsFragment as intro fragment when no permissions are granted
        val permissions = CONTACT_PERMISSIONS + CALENDAR_PERMISSIONS +
                TaskProvider.ProviderName.JtxBoard.permissions +
                TaskProvider.ProviderName.OpenTasks.permissions +
                TaskProvider.ProviderName.TasksOrg.permissions
        return if (PermissionUtils.haveAnyPermission(context, permissions))
            ShowPolicy.DONT_SHOW
        else
            ShowPolicy.SHOW_ALWAYS
    }

    @Composable
    override fun ComposePage() {
        PermissionsScreen()
    }

}