package ru.forbion.f7cloud.feature.files

import java.util.Locale

enum class OpenableKind {
    IMAGE,
}

object OpenableFiles {
    private val IMAGE_EXT = setOf("jpg", "jpeg", "png", "gif", "webp", "bmp", "heic", "heif")

    fun kind(name: String): OpenableKind? {
        val ext = name.lowercase(Locale.ROOT).substringAfterLast('.', missingDelimiterValue = "")
        return if (ext in IMAGE_EXT) OpenableKind.IMAGE else null
    }

    fun isOpenable(name: String): Boolean = kind(name) != null || ArchiveFiles.isArchive(name)

    fun isImage(name: String): Boolean = kind(name) == OpenableKind.IMAGE

    fun hint(name: String): String? = when {
        isImage(name) -> "Просмотр"
        ArchiveFiles.isArchive(name) -> "Открыть с помощью…"
        else -> null
    }
}
