package com.pixelized.desktop.lwa.utils

import androidx.compose.runtime.Composable
import coil3.ImageLoader
import coil3.compose.setSingletonImageLoaderFactory
import coil3.disk.DiskCache
import coil3.request.crossfade
import com.pixelized.shared.lwa.utils.PathProvider
import okio.Path.Companion.toPath
import org.koin.compose.koinInject

@Composable
fun InstallCoil(
    pathProvider: PathProvider = koinInject(),
    crossfade: Boolean,
    diskCachePath: (PathProvider) -> String,
) {
    setSingletonImageLoaderFactory { context ->
        ImageLoader.Builder(context)
            .crossfade(enable = crossfade)
            .diskCache {
                DiskCache.Builder()
                    .directory(directory = diskCachePath(pathProvider).toPath())
                    .build()
            }
            .build()
    }
}