package mg.dot.feufaro.ui

import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember

@Composable
actual fun rememberFileSaveLauncher(
    onResult: (String?) -> Unit
): FileSaveLauncher {
    val launcher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.CreateDocument("text/plain")
    ) { uri ->
        onResult(uri?.toString())
    }

    return remember {
        object : FileSaveLauncher {
            override fun launch(defaultName: String, initialDir: String?) {
                launcher.launch(defaultName)
            }
        }
    }
}